_deprecated_hook

Marks a deprecated action or filter hook as deprecated and throws a notice.

Description

_deprecated_hook( (string) $hook, (string) $version, (constant) $replacement = null, (null) $message = null ); 

Use the action to get the backtrace describing where the deprecated hook was called.

Default behavior is to trigger a user error if WP_DEBUG is true.

This function is called by the do_action_deprecated() and apply_filters_deprecated() functions, and so generally does not need to be called directly.

Parameters (4)

0. $hook (string)
The hook that was used.
1. $version (string)
The version of WordPress that deprecated the hook.
2. $replacement — Optional. (constant) => null
The hook that should have been used.
3. $message — Optional. (null) => null
A message regarding the change.

Usage

  1. if ( !function_exists( '_deprecated_hook' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // The hook that was used. 
  5. $hook = ''; 
  6.  
  7. // The version of WordPress that deprecated the hook. 
  8. $version = ''; 
  9.  
  10. // Optional. The hook that should have been used. 
  11. $replacement = null; 
  12.  
  13. // Optional. A message regarding the change. 
  14. $message = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = _deprecated_hook($hook, $version, $replacement, $message); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) { 
  2. /** 
  3. * Fires when a deprecated hook is called. 
  4. * @since 4.6.0 
  5. * @param string $hook The hook that was called. 
  6. * @param string $replacement The hook that should be used as a replacement. 
  7. * @param string $version The version of WordPress that deprecated the argument used. 
  8. * @param string $message A message regarding the change. 
  9. */ 
  10. do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message ); 
  11.  
  12. /** 
  13. * Filters whether to trigger deprecated hook errors. 
  14. * @since 4.6.0 
  15. * @param bool $trigger Whether to trigger deprecated hook errors. Requires 
  16. * `WP_DEBUG` to be defined true. 
  17. */ 
  18. $message = empty( $message ) ? '' : ' ' . $message; 
  19. if ( ! is_null( $replacement ) ) { 
  20. /** translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */ 
  21. trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message ); 
  22. } else { 
  23. /** translators: 1: WordPress hook name, 2: version number */ 
  24. trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );