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

原型

_deprecated_argument( string $function, string $version, string $message = null )

描述

只要使用不推荐使用的函数参数,就会使用此函数。在调用此函数之前,必须通过将参数与其默认值进行比较或评估它是否为空来检查参数是否已被使用。例如:

参数

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

$version (string) (Required) 不赞成使用的参数的WordPress版本。

$message (string) (Optional)  有关更改的消息。

源文件

路径:wp-includes/functions.php

<?php
...
function _deprecated_argument( $function, $version, $message = null ) {
	/**
	 * Fires when a deprecated argument is called.
	 *
	 * @since 3.0.0
	 *
	 * @param string $function The function that was called.
	 * @param string $message  A message regarding the change.
	 * @param string $version  The version of WordPress that deprecated the argument used.
	 */
	do_action( 'deprecated_argument_run', $function, $message, $version );
	/**
	 * Filters whether to trigger an error for deprecated arguments.
	 *
	 * @since 3.0.0
	 *
	 * @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
		if ( function_exists( '__' ) ) {
			if ( ! is_null( $message ) ) {
				/* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
				trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
			} else {
				/* translators: 1: PHP function name, 2: version number */
				trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
			}
		} else {
			if ( ! is_null( $message ) ) {
				trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
			} else {
				trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
			}
		}
	}
}
...
?>

其他

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