WordPress:WordPress Deprecated Functions Hook

来自站长百科
跳转至: 导航、​ 搜索

Deprecated Functions[ ]

取消的函数[ ]

There is a need to inform both theme and plugin developers and users of the usage of deprecated functions. In WordPress 2.4, a way to do that was added.

不需要同时通知主题和插件开发人员和用户,取消的函数的用法。在WordPress2.4版本中,添加了方法来实现那一点。

The following gives instructions on how to turn on the deprecated functions reporting, what hooks can be used for when deprecated functions are used, and code snippets demonstrating how all of this can be accomplished.

下面有指示说明,关于怎样打开deprecated 函数 reporting,当使用了deprecated的函数的时候,可以使用哪个hooks,而且代码snippets阐述了实现这些。

Normal Deprecated Function Reporting[ ]

普通的 Deprecated Function Reporting[ ]

When WP_DEBUG is enabled in wp-config.php, it will turn on the notices that deprecated functions were used. When WP_DEBUG is turned off or does not exist, then no reporting will be given.

在wp-config.php中激活了WP_DEBUG的时候,就会有通知显示,使用了deprecated函数。当关闭WP_DEBUG或者WP_DEBUG不存在的时候,就不会有reporting。

This prevents the notices for everyday users who are uninterested in receiving these reports. As a consequence, only the users who actively enable WP_DEBUG will receive the information. Those users will not know to upgrade, unless they use a plugin which they download and activate.

这阻止了每天给用户发一个通知,而用户对接到这些通知又不感兴趣。因此,只有主动激活了WP_DEBUG的用户,才会收到通知。那些用户不会知道要更新,除非他们下载并且激活了一个插件。

The following code snippet enables WP_DEBUG and needs to be placed in wp-config.php.

下面的代码snippet激活了WP_DEBUG,而且需要放置在wp-config.php内。

define('WP_DEBUG', true);

define('WP_DEBUG', true);

Deprecated Function/File Action Hooks[ ]

Deprecated 函数/文件Action Hooks[ ]

When a deprecated function is used, the 'deprecated_function_run' hook is called. Whenever a deprecated file is included, the 'deprecated_file_included' hook is called. These hooks are actions and do not return anything. The 'deprecated_function_run' is passed the function and the replacement. The 'deprecated_file_included' is passed the file and which file replaced the deprecated one.

使用deprecated 函数的时候,会用到'deprecated_function_run' hook。无论什么时候包含了deprecated文件,都会调用'deprecated_file_included' hook。这些hooks是actions而且不会返回任何内容。'deprecated_function_run'通过了函数和置换。'deprecated_file_included'通过了文件而且文件替换了deprecated one。

If the hooked function wishes to keep track of which deprecated function were run and how many times, the hooked function will have to do that itself.

如果hooked函数希望明了,哪个函数在运行,而且运行了多少次,hooked函数需要自己解决这个问题。

Which function called the deprecated function or file is not known and is up to the plugin to preform a back trace to get that information.

哪个函数调用了deprecated函数或者文件,是未知的,而且取决于插件执行向后追踪已得到信息。

Preventing the Notices From Displaying[ ]

阻止显示通知[ ]

When a plugin uses the above hooks, it could prevent notices from being displayed, even with WP_DEBUG enabled. It is then assumed that if a plugin hooked into both 'deprecated_function_run' and 'deprecated_file_included' that it would record and display the information in a more friendly matter.

插件使用以上的hooks,可以阻止显示通知,即使WP_DEBUG是激活的,也能够阻止。然后,假设插件hooked进'deprecated_function_run' 和 'deprecated_file_included',插件就可以以更友好的方式,显示和记录信息。

To prevent the notices from displaying for functions, the 'deprecated_function_trigger_error' filter hook should return false. To prevent notices from displaying for files, the 'deprecated_file_trigger_error' filter hook should return false.

阻止通知显示函数,'deprecated_function_trigger_error' filter hook应该返回错误的。阻止通知显示文件,'deprecated_file_trigger_error' filter hook应该返回错误的。

If a plugin does not have a way to display the deprecated function or file usage, then the plugin should not prevent the notices from appearing when WP_DEBUG is turned on. It should also make sure that the deprecated information is not displayed where any visitor can see it.

如果插件没有方法,显示deprecated函数或者文件,那么插件应该在WP_DEBUG开启的状态下,阻止出现通知。插件也要确定没有显示通知,任何访客都不会看到通知。