_doing_it_wrong()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
_doing_it_wrong( string $function_name, string $message, string $version )
Описание
Существует хук 'doing_it_wrong_run', который будет вызван и с помощью которого можно получить трассировку вплоть до того, какой файл и функция вызвали устаревшую функцию.
Текущее поведение — сгенерировать пользовательскую ошибку, если WP_DEBUG равно true.
Оригинал (английский)
There is a ‘doing_it_wrong_run’ hook 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.
Параметры
$function_name
string
обязательный
$message
string
обязательный
$version
string
обязательный
Исходный код
wp-includes/functions.php:6022
function _doing_it_wrong( $function_name, $message, $version ) {
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function_name, $message, $version );
/**
* Filters whether to trigger an error for _doing_it_wrong() calls.
*
* @since 3.1.0
* @since 5.1.0 Added the `$function_name`, `$message`, and `$version` parameters.
*
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
* @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function_name, $message, $version ) ) {
if ( function_exists( '__' ) ) {
if ( $version ) {
/* translators: %s: Version number. */
$version = sprintf( __( '(This message was added in version %s.)' ), $version );
}
$message .= ' ' . sprintf(
/* translators: %s: Documentation URL. */
__( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
__( 'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/' )
);
$message = sprintf(
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
__( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
$function_name,
$message,
$version
);
} else {
if ( $version ) {
$version = sprintf( '(This message was added in version %s.)', $version );
}
$message .= sprintf(
' Please see <a href="%s">Debugging in WordPress</a> for more information.',
'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/'
);
$message = sprintf(
'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
$function_name,
$message,
$version
);
}
wp_trigger_error( '', $message );
}
}
История изменений
| Версия | Описание |
|---|---|
| 5.4.0 | This function is no longer marked as "private". |
| 3.1.0 | Introduced. |

