プラグインElementorのelementor/connect/apps/registerアクションの使用方法・解説

概要

elementor/connect/apps/registerは、Elementorの拡張機能やアプリ連携を実装する際に使用されるフックです。このアクションは、外部アプリケーションとの連携を行うとき、特にElementorのカスタムウィジェットや追加機能を登録するために用いられます。

次のような機能を実装する際に頻繁に使用されます:

  1. 外部APIとの連携機能
  2. 新しいウィジェットの作成
  3. 特定のデータを送信するカスタムフォームの作成
  4. Elementor内でのカスタムエレメントの表示
  5. アプリの統計データの収集
  6. Elementorのテーマカスタマイズの拡張

構文

add_action( 'elementor/connect/apps/register', 'your_callback_function' );

パラメータ

  • $app_name – 登録するアプリの名前(文字列)
  • $app_info – アプリに関する情報を含む配列(例:バージョン、説明)

戻り値

このアクションは戻り値を持たないため、特に何も返却されません。主にアプリの登録を目的としています。

使用可能なプラグインとバージョン

  • Elementorのバージョン: 3.0以上
  • WordPressのバージョン: 5.2以上

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

アクション名 使用例
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/connect/apps/register', function( $app_name, $app_info ) {
    ElementorPlugin::instance()->widgets_manager->register_widget_type( new My_Custom_Widget() );
} );

このコードは、Elementorにカスタムウィジェットを登録します。ウィジェットクラスはMy_Custom_Widgetである必要があります。

サンプル2: APIからデータを取得する

add_action( 'elementor/connect/apps/register', function( $app_name, $app_info ) {
    $response = wp_remote_get( 'https://api.example.com/data' );
    if ( is_array( $response ) && ! is_wp_error( $response )) {
        // データの処理
    }
} );

このサンプルは、指定したAPIからデータを取得し、Elementor内で使用するために処理します。

サンプル3: カスタムエレメントの登録

add_action( 'elementor/connect/apps/register', function( $app_name, $app_info ) {
    ElementorPlugin::instance()->elements_manager->add_widget( new My_Custom_Element() );
} );

このコードでは、カスタムエレメントをElementorの要素管理者に追加します。

サンプル4: 統計データの送信

add_action( 'elementor/connect/apps/register', function( $app_name, $app_info ) {
    // ユーザーアクションに関する統計データを送信
    $data = array( 'action' => 'user_action', 'user_id' => get_current_user_id() );
    wp_remote_post( 'https://api.example.com/track', array( 'body' => $data ) );
} );

このサンプルコードは、ユーザーのアクションを追跡するためにAPIにデータを送信します。

サンプル5: カスタムフォームの作成

add_action( 'elementor/connect/apps/register', function( $app_name, $app_info ) {
    // Elementorにカスタムフォームを追加
    add_shortcode( 'my_custom_form', 'render_my_custom_form' );
} );

function render_my_custom_form() {
    return '<form action="#" method="post"><input type="text" name="data" /><input type="submit" /></form>';
}

このコードは、Elementorにカスタムフォームを追加するショートコードを登録します。フォームはマークアップとPHPで構成されています。

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


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