_deprecated_hook

函数
_deprecated_hook ( $hook, $version, $replacement = '', $message = '' )
Access
Private
参数
  • (string) $hook The hook that was used.
    Required:
  • (string) $version The version of WordPress that deprecated the hook.
    Required:
  • (string) $replacement Optional. The hook that should have been used. Default empty.
    Required:
    Default: (empty)
  • (string) $message Optional. A message regarding the change. Default empty.
    Required:
    Default: (empty)
定义位置
相关方法
_deprecated_file_deprecated_constructor_deprecated_function_deprecated_argumentms_deprecated_blogs_file
引入
4.6.0
弃用
-

deprecated_hook: 当使用一个已弃用的钩子时,触发一个弃用通知的函数。

将一个已弃用的动作或过滤器钩子标记为已弃用,并抛出一个通知。

使用{@see ‘deprecated_hook_run’}动作来获得回溯,描述被弃用的钩子被调用的地方。

默认行为是在`WP_DEBUG`为真时触发一个用户错误。

这个函数被do_action_deprecated()和apply_filters_deprecated()函数调用,所以一般不需要直接调用。

function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) {
	/**
	 * Fires when a deprecated hook is called.
	 *
	 * @since 4.6.0
	 *
	 * @param string $hook        The hook that was called.
	 * @param string $replacement The hook that should be used as a replacement.
	 * @param string $version     The version of WordPress that deprecated the argument used.
	 * @param string $message     A message regarding the change.
	 */
	do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );

	/**
	 * Filters whether to trigger deprecated hook errors.
	 *
	 * @since 4.6.0
	 *
	 * @param bool $trigger Whether to trigger deprecated hook errors. Requires
	 *                      `WP_DEBUG` to be defined true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
		$message = empty( $message ) ? '' : ' ' . $message;

		if ( $replacement ) {
			trigger_error(
				sprintf(
					/* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
					__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
					$hook,
					$version,
					$replacement
				) . $message,
				E_USER_DEPRECATED
			);
		} else {
			trigger_error(
				sprintf(
					/* translators: 1: WordPress hook name, 2: Version number. */
					__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
					$hook,
					$version
				) . $message,
				E_USER_DEPRECATED
			);
		}
	}
}

常见问题

FAQs
查看更多 >