お問い合わせはコチラから

default-thumbnail-plusプラグインでcontextual_helpフックの警告が出る時の消し方

サイト運営

かなり昔に保守されなくなったdefault-thumbnail-plusプラグインと言うプラグインを愛用しています。

Query monitorというプラグインのバージョンアップをしたら、default-thumbnail-plusプラグイン関連で以下のような警告が出るようになりました。

Deprecated: contextual_help is deprecated since version 3.3.0! Use get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab() instead.

内容としては、Wordpress3.3以降ではcontextual_helpフックは使わずに、get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()を使いなさい、ということらしいです。

ちなみにQuery monitorのバージョンアップで警告が出るようになった理由は、次の内容によるためです。

3.13.0

  • Adds a dedicated panel for “Doing it Wrong” and deprecated functionality usage
https://wordpress.org/plugins/query-monitor/#developers

deprecated functionality usage警告が発生する箇所

問題の箇所は以下のadd_filter('contextual_help'の場所です。

if ( is_admin() ){ 
    // admin actions
    include('include'.DIRECTORY_SEPARATOR.'slt-file-select.php');

    add_action('admin_menu',            array('DefaultPostThumbnailPlugin', 'init_plugin_menu')); 
    add_action('admin_enqueue_scripts', array('DefaultPostThumbnailPlugin', 'backend_enqueue_scripts') );
    add_action('admin_init',            array('DefaultPostThumbnailPlugin', 'register_settings'));

    add_filter('contextual_help', array('DefaultPostThumbnailPlugin', 'contextual_help'), 10, 3);
} else {
    // non admin actions
    if(get_option('dpt_hook_post_meta', true))
        DefaultPostThumbnailPlugin::add_filter_post_metadata();
}

この部分を変える必要があります。

修正方法

こちらの記事を見ると、add_filter('contextual_help'add_action('current_screen'に変更すれば良さそうでした。

Deprecated use of contextual_help
Deprecated use of contextual_help Resolved Garrett Hyder (@garrett-eclipse) 4 years, 3 months ago Hello, On a clean inst...

add_action('current_screen'とは?

公式サイトによれば、このアクションフックが発火されるのは、
Fires after the current screen has been set.
とあります。

do_action( ‘current_screen’, WP_Screen $current_screen )

current_screen – Hook | Developer.WordPress.org
Fires after the current screen has been set.

$current_screenオブジェクトを受け取って、処理するcallback関数を書けば良さそうです。

修正コード

再度こちらを見ると、以下のようなコードが書かれています。

$screen = get_current_screen();
$help_content = ‘<p>Hallo world</p>’;
$screen->add_help_tab(
array( ‘id’ => ‘my-contextual-screen-id’,
‘title’ => ‘Screen information’,
‘content’ => $help_content, ));

この内容をdefault-thumbnail-plusプラグインにあわせて、callback関数で処理してあげれば良さそうです。

contextual_help($screen)というcallback関数を新規に定義します。

if ( is_admin() ){ 
    // admin actions
    include('include'.DIRECTORY_SEPARATOR.'slt-file-select.php');

    add_action('admin_menu',            array('DefaultPostThumbnailPlugin', 'init_plugin_menu')); 
    add_action('admin_enqueue_scripts', array('DefaultPostThumbnailPlugin', 'backend_enqueue_scripts') );
    add_action('admin_init',            array('DefaultPostThumbnailPlugin', 'register_settings'));

    //add_filter('contextual_help', array('DefaultPostThumbnailPlugin', 'contextual_help'), 10, 3);
    add_action('current_screen', 'contextual_help', 10);
} else {
    // non admin actions
    if(get_option('dpt_hook_post_meta', true))
        DefaultPostThumbnailPlugin::add_filter_post_metadata();
}
function contextual_help($screen){
    global $dpt_plugin_hook;
    $contextual_help = '<a target="_blank" href="http://www.pjgalbraith.com/2011/12/default-thumbnail-plus/">Full Documentation with Images!</a><br><a target="_blank" href="http://wordpress.org/extend/plugins/default-thumbnail-plus/">WordPress.org Plugin Page</a>';


$screen->add_help_tab(array(
        'id'  => $dpt_plugin_hook,
        'title' => 'Screen information',
        'content' => $contextual_help,
));
}

まとめ

今回の警告が影響するのは、管理画面の設定⇒default-thumbnail-plusと進んで、画面最上部に表示されるhelpタブの部分です。

機能的には全く影響がないものですが、警告を消したいという場合は自己責任で行いましょう。

この記事を書いた人
ブーン

はるばる日本よりオランダ王国へやってまいりました。
自分の経験が少しでも参考になれば嬉しいです。
お問い合わせは、『こちら』からお願い致します。

\ブーンをフォロー/
スポンサーリンク
サイト運営
\シェアお願いします!/
\ブーンをフォロー/
こんな記事も読まれています

失敗しないレンタルサーバーランキング

mixhost

不正アクセスに強くて使いやすいおススメサーバー
\本サイトで利用中/
メリット①:自動ウィルス駆除対応
メリット②:サイトの表示速度が速い!
メリット③:転送量の上限が多い!
メリット④:自由にプラン変更ができ、アクセス増にも対応できる!
メリット⑤:バックアップデータが無料で復元できる!
メリット⑥:Wordpressが簡単にインストールできる!
メリット⑦:どのプランでも初期費用が無料!
メリット⑧:10日間の無料お試し期間と30日の返金保証!

Conoha Wing

国内Wordpress最速の最強サーバー
メリット①:圧倒的な表示速度
メリット②:レンタルサーバーと独自ドメインがセットでお得◎
メリット③:プラン変更はすべてのプランで自由自在
メリット④:一か月の利用転送量の制限が緩い(9TB~)
メリット⑤:WordPresサイトの移行が簡単

エックスサーバー

国内シェアNo1の安定性と実績が魅力。ALL SSDで死角なしの万能サーバー。
メリット①:サイトの表示速度が安定して速い!
メリット②:アクセス負荷に強くて安定性が高い!
メリット③:24時間365日の充実サポートで安心!電話サポートもあり!
メリット④:転送量が多い!
メリット⑤:自動バックアップ機能付き!
メリット⑥:WordPressが簡単にインストールできる!
メリット⑦:10日の無料お試し期間がある!

タイトルとURLをコピーしました