プラグインElementorのelementor/template_library/is_template_supports_exportフィルタの使用方法・解説

概要

elementor/template_library/is_template_supports_export フィルタは、Elementor プラグインにおいてテンプレートのエクスポートがサポートされているかどうかを判断する際に使用されます。このフィルタを利用することで、特定のテンプレートがエクスポート可能であるかどうかをカスタマイズできます。これにより、ユーザーはテンプレートのエクスポート機能を条件付きで制御でき、さまざまなニーズに応じた調整が可能になります。

このフィルタは、以下のような機能を実装する際によく使用されます。

  1. テンプレートのエクスポートの条件をカスタマイズする。
  2. 特定のカスタムポストタイプのテンプレートだけをエクスポート可能とする。
  3. ユーザーの権限に応じてエクスポート機能を制限する。
  4. テンプレートのステータス(公開、非公開など)に基づいてエクスポートの可否を判断する。
  5. 特定のカテゴリやタグに属するテンプレートをエクスポート可能とする。
  6. サードパーティ製のプラグインによるテンプレートのエクスポート機能を拡張する。

構文

add_filter( 'elementor/template_library/is_template_supports_export', 'my_custom_export_support', 10, 2 );

パラメータ

  • bool $supports_export – テンプレートがエクスポートをサポートするかどうかのブール値。
  • array $template – テンプレートの情報を含む配列。

戻り値

  • bool – エクスポートがサポートされる場合は true、そうでない場合は false を返します。

使用可能なバージョン

  • Elementor: 3.0.0 以降
  • 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_filter( 'elementor/template_library/is_template_supports_export', function( $supports_export, $template ) {
    if ( 'my_custom_post_type' === $template['type'] ) {
        return true; // このテンプレートはエクスポートできます
    }
    return $supports_export; // デフォルトの設定を維持
} );

このコードは、特定のカスタムポストタイプに対してテンプレートのエクスポートを許可するものです。

サンプル2: ユーザーの権限に基づいてエクスポートを制限する

add_filter( 'elementor/template_library/is_template_supports_export', function( $supports_export, $template ) {
    if ( ! current_user_can( 'export_templates' ) ) {
        return false; // ユーザーにエクスポート権限がない場合、エクスポートを無効に
    }
    return $supports_export; 
} );

このコードは、ユーザーが特定の権限を持っていない場合にエクスポート機能を無効にします。

サンプル3: テンプレートの公開状態による制御

add_filter( 'elementor/template_library/is_template_supports_export', function( $supports_export, $template ) {
    if ( 'draft' === $template['status'] ) {
        return false; // 下書き状態のテンプレートはエクスポートできない
    }
    return true; // 公開済みの場合はエクスポート可能
} );

このコードは、非公開または下書き状態のテンプレートに対してエクスポートを制限します。

サンプル4: 特定の条件でエクスポートを許可する

add_filter( 'elementor/template_library/is_template_supports_export', function( $supports_export, $template ) {
    if ( isset( $template['category'] ) && 'special-category' === $template['category'] ) {
        return true; // 特定のカテゴリに属する場合はエクスポートを許可
    }
    return $supports_export; 
} );

このコードは、特定のカテゴリに属するテンプレートだけエクスポートを許可します。

サンプル5: エクスポート機能の拡張

add_filter( 'elementor/template_library/is_template_supports_export', function( $supports_export, $template ) {
    if ( function_exists( 'my_plugin_is_template_exportable' ) && ! my_plugin_is_template_exportable( $template ) ) {
        return false; // サードパーティプラグインによるエクスポート判定を使用
    }
    return $supports_export; 
} );

このコードは、サードパーティのプラグインによるエクスポート判定を使用するサンプルです。

これらのサンプルはすべて著作権フリーで、自由に使用できます。

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


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