返回介绍

_deprecated_hook()

发布于 2017-09-11 13:20:55 字数 3719 浏览 1016 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_deprecated_hook( string $hook,  string $version,  string $replacement = null,  string $message = null )

Marks a deprecated action or filter hook as deprecated and throws a notice.


description

Use the ‘deprecated_hook_run’ action to get the backtrace describing where the deprecated hook was called.

Default behavior is to trigger a user error if WP_DEBUG is true.

This function is called by the do_action_deprecated() and apply_filters_deprecated() functions, and so generally does not need to be called directly.


参数

$hook

(string) (Required) The hook that was used.

$version

(string) (Required) The version of WordPress that deprecated the hook.

$replacement

(string) (Optional) The hook that should have been used.

Default value: null

$message

(string) (Optional) A message regarding the change.

Default value: null


源代码

File: wp-includes/functions.php

function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
	/**
	 * 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 ( ! is_null( $replacement ) ) {
			/* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
			trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
		} else {
			/* translators: 1: WordPress hook name, 2: version number */
			trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
		}
	}
}

更新日志

Versiondescription
4.6.0Introduced.

相关函数

Uses

  • wp-includes/functions.php: deprecated_hook_run
  • wp-includes/functions.php: deprecated_hook_trigger_error
  • wp-includes/l10n.php: __()
  • wp-includes/plugin.php: do_action()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/plugin.php: apply_filters_deprecated()
  • wp-includes/plugin.php: do_action_deprecated()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文