
如何将PHP代码添加到WordPress文章或页面
_deprecated_argument ( $function, $version, $message = '' )
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 ); } } } }