_deprecated_argument

函数
_deprecated_argument ( $function, $version, $message = '' )
参数
  • (string) $function The function that was called.
    Required:
  • (string) $version The version of WordPress that deprecated the argument used.
    Required:
  • (string) $message Optional. A message regarding the change. Default empty.
    Required:
    Default: (empty)
定义位置
相关方法
rest_handle_deprecated_argument_deprecated_function_deprecated_file_deprecated_hook_deprecated_constructor
引入
3.0.0
弃用
-

deprecated_argument: 一个函数,当使用已弃用的函数参数时,会触发一个弃用通知。

将一个函数参数标记为弃用的,并在它被使用时通知。

每当使用一个弃用的函数参数时,都要使用这个函数。在这个函数被调用之前,必须通过与默认值比较或评估参数是否为空来检查参数是否被使用。

比如说

if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, ‘3.0.0’ )。
}

有一个将被调用的钩子deprecated_argument_run,可以用来获取回溯,直到哪个文件和函数使用了这个被弃用的参数。

目前的行为是,如果WP_DEBUG为真,会触发一个用户错误。

function _deprecated_argument( $function, $version, $message = '' ) {

	/**
	 * 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 ( $message ) {
				trigger_error(
					sprintf(
						/* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
						__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
						$function,
						$version,
						$message
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						/* translators: 1: PHP function name, 2: Version number. */
						__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
						$function,
						$version
					),
					E_USER_DEPRECATED
				);
			}
		} else {
			if ( $message ) {
				trigger_error(
					sprintf(
						'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
						$function,
						$version,
						$message
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
						$function,
						$version
					),
					E_USER_DEPRECATED
				);
			}
		}
	}
}

常见问题

FAQs
查看更多 >