_deprecated_function
Mark a function as deprecated and inform when it has been used.
Description
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
if ( !function_exists( '_deprecated_function' ) ) { require_once ABSPATH . WPINC . '/functions.php'; } // The function that was called. $function = ''; // The version of WordPress that deprecated the function. $version = ''; // Optional. The function that should have been called. Default null. $replacement = null; // NOTICE! Understand what this does before running. $result = _deprecated_function($function, $version, $replacement);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/functions.php
- function _deprecated_function( $function, $version, $replacement = null ) {
- /**
- * Fires when a deprecated function is called.
- *
- * @since 2.5.0
- *
- * @param string $function The function that was called.
- * @param string $replacement The function that should have been called.
- * @param string $version The version of WordPress that deprecated the function.
- */
- do_action( 'deprecated_function_run', $function, $replacement, $version );
- /**
- * Filters whether to trigger anerrorfor deprecated functions.
- *
- * @since 2.5.0
- *
- * @param bool $trigger Whether to trigger theerrorfor deprecated functions. Default true.
- */
- if ( function_exists( '__' ) ) {
- if ( ! is_null( $replacement ) ) {
- /** translators: 1: PHP function name, 2: version number, 3: alternative function name */
- trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
- } else {
- /** translators: 1: PHP function name, 2: version number */
- trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
- }
- } else {
- if ( ! is_null( $replacement ) ) {
- trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
- } else {
- trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
- }
- }
- }
- }