問題描述

WordPress 3.3 已經棄用了 add_contextual_help() 功能,它是過濾器,所以為了繼續支持 3.0 – 3.2.1 並且還符合 3.3,我做了以下工作:

global $wp_version;
if ($wp_version >= '3.3') {
    // New method
    add_action("load-$admin_page", 'CrayonSettingsWP::help_screen');
} else {
    // Depreciated method
    add_filter('contextual_help', 'CrayonSettingsWP::cont_help', 10, 3);
}

有更好的方法嗎?

最佳解決方案

我的看法沒有任何錯誤。但是我要採取不同的方式:不支持舊版本的 WP 。

從 WP 社區獲得的一般印象是進步。通過支持當前版本和轉發,您正在幫助推動社區使用最新版本的 WordPress 。

摘自 WordPress Plugin Development(這是一本很好的書!):

In the WordPress development community, backward compatibility may sometimes be even looked down upon. Users are expected to stay updated with the latest version of the software.

次佳解決方案

更好的版本檢查是您使用 PHP 的默認功能為此要求; 看這個例子。

if ( version_compare( $GLOBALS['wp_version'], '3.3alpha', '>=' ) ) {

PHP 中的版本更多的是 3 個字符串,liek 3.3!檢查穩定版本較小的版本很重要。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。