プラグインElementorのelementor/core/admin/noticesアクションの使用方法・解説

概要

elementor/core/admin/noticesアクションは、Elementorプラグイン内で管理者向けの通知メッセージを表示するためのフックです。このフックは、特に管理画面でのユーザーエクスペリエンス向上に寄与します。以下のような機能を実装する際によく使われます。

  1. プラグインのアップデート情報を表示する。
  2. 設定が正しくない場合の警告メッセージを出す。
  3. テンプレートやウィジェットの利用に関する情報を表示する。
  4. ライセンスの状態を通知する。
  5. インストールが成功した場合の確認メッセージを表示する。
  6. 環境設定が不足している場合の注意メッセージを表示する。

構文

do_action( 'elementor/core/admin/notices' );

パラメータ

このアクションには追加のパラメータはありません。

戻り値

このアクションは何も戻しません。ただし、通知メッセージが画面に表示されます。

Elementorバージョン

このアクションはElementorのバージョン2.0以降で使用可能です。

WordPressバージョン

WordPressのバージョンは5.0以降でサポートされています。

この関数のアクションでの使用可能性

アクション 使用例
mu_plugin_loaded
registered_post_type
plugins_loaded
wp_roles_init
setup_theme
after_setup_theme
set_current_user
init
register_sidebar
wp_loaded
send_headers
parse_query
pre_get_posts
wp
template_redirect
get_header
wp_head

サンプルコード1

add_action( 'elementor/core/admin/notices', function() {
    ElementorPlugin::instance()->admin->add_notice( 'Your Elementor version is up to date.', 'success' );
});

このコードは、Elementorの管理画面に「あなたのElementorのバージョンは最新です」という成功メッセージを表示します。

サンプルコード2

add_action( 'elementor/core/admin/notices', function() {
    ElementorPlugin::instance()->admin->add_notice( 'Please configure your settings to proceed.', 'warning' );
});

このコードは、Elementorの設定を行う必要がある場合に警告メッセージを表示します。

サンプルコード3

add_action( 'elementor/core/admin/notices', function() {
    ElementorPlugin::instance()->admin->add_notice( 'Your license is about to expire. Please renew.', 'error' );
});

このコードは、Elementorのライセンスが期限切れ間近であることを通知します。

サンプルコード4

add_action( 'elementor/core/admin/notices', function() {
    ElementorPlugin::instance()->admin->add_notice( 'New features are available in the latest version of Elementor.', 'info' );
});

このコードは、Elementorの最新バージョンに新機能があることを知らせる情報メッセージを表示します。

サンプルコード5

add_action( 'elementor/core/admin/notices', function() {
    if ( ! get_option( 'elementor_template_library' ) ) {
        ElementorPlugin::instance()->admin->add_notice( 'Please install the Elementor template library to access more templates.', 'info' );
    }
});

このコードは、Elementorテンプレートライブラリがインストールされていない場合に、そのインストールを促すメッセージを表示します。

この関数について質問する


上の計算式の答えを入力してください