_deprecated_function

Mark a function as deprecated and inform when it has been used.

Description

_deprecated_function( (string) $function, (string) $version, (null) $replacement = null ); 

There is a that will be called that can be used to get the backtrace up to what file and function called the deprecated function.

The current behavior is to trigger a user error if WP_DEBUG is true.

This function is to be used in every function that is deprecated.

Parameters (3)

0. $function (string)
The function that was called.
1. $version (string)
The version of WordPress that deprecated the function.
2. $replacement — Optional. (null) => null
The function that should have been called. Default null.

Usage

  1. if ( !function_exists( '_deprecated_function' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // The function that was called. 
  5. $function = ''; 
  6.  
  7. // The version of WordPress that deprecated the function. 
  8. $version = ''; 
  9.  
  10. // Optional. The function that should have been called. Default null. 
  11. $replacement = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _deprecated_function($function, $version, $replacement); 
  15.  

Defined (1)

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

/wp-includes/functions.php  
  1. function _deprecated_function( $function, $version, $replacement = null ) { 
  2.  
  3. /** 
  4. * Fires when a deprecated function is called. 
  5. * @since 2.5.0 
  6. * @param string $function The function that was called. 
  7. * @param string $replacement The function that should have been called. 
  8. * @param string $version The version of WordPress that deprecated the function. 
  9. */ 
  10. do_action( 'deprecated_function_run', $function, $replacement, $version ); 
  11.  
  12. /** 
  13. * Filters whether to trigger anerrorfor deprecated functions. 
  14. * @since 2.5.0 
  15. * @param bool $trigger Whether to trigger theerrorfor deprecated functions. Default true. 
  16. */ 
  17. if ( function_exists( '__' ) ) { 
  18. if ( ! is_null( $replacement ) ) { 
  19. /** translators: 1: PHP function name, 2: version number, 3: alternative function name */ 
  20. trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); 
  21. } else { 
  22. /** translators: 1: PHP function name, 2: version number */ 
  23. trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) ); 
  24. } else { 
  25. if ( ! is_null( $replacement ) ) { 
  26. trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) ); 
  27. } else { 
  28. trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );