将函数标记为已弃用,并在使用时通知。

原型

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

描述

有一个’hook deprecated_function_run’将被调用,可用于获取回溯到哪个文件和函数称为已弃用的函数。

参数

$function (string) (Required) 被调用的函数。

$version (string) (Required) 弃用该函数的WordPress版本。

$replacement (string) (Optional)  应该调用的函数。

源文件

路径:wp-includes/functions.php

<?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 an error for deprecated functions.
	 *
	 * @since 2.5.0
	 *
	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', 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 ) );
			}
		}
	}
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_deprecated_function/