_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
檢視更多 >