プラグインWPFormsのwpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statusesフィルタの使用方法・解説

概要

wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses フィルタは、WPFormsにおいて、特定のエントリ制限を適用する際に使用されます。このフィルタは、許可されていない状態のエントリを除外し、ロックされたフォームを管理するためのカスタマイズを行うことができます。主に次のような機能を実装する際に使用されます。

  1. 特定の投稿ステータスを持つエントリを除外する。
  2. ユーザーの権限に基づいてエントリを表示または非表示にする。
  3. ロックされたフォームのエントリ制限を柔軟に設定する。
  4. エントリの状態による表示制御を行う。
  5. カスタム条件を使ってエントリをフィルタリングする。
  6. エラーメッセージをユーザーに応じて変更する。

構文

function your_custom_function( $excluded_statuses ) {
    // ここにカスタマイズコードを入れる
    return $excluded_statuses;
}
add_filter( 'wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses', 'your_custom_function' );

パラメータ

  • $excluded_statuses:除外される投稿ステータスの配列。

戻り値

  • 除外する投稿ステータスの配列。

WPFormsバージョン

  • WPForms 1.6.0以降

WordPressバージョン

  • WordPress 5.0以降

サンプルコード

サンプル1: 特定の投稿ステータスを除外

function exclude_custom_post_status( $excluded_statuses ) {
    $excluded_statuses[] = 'trash'; // ゴミ箱状態を除外
    return $excluded_statuses;
}
add_filter( 'wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses', 'exclude_custom_post_status' );

このコードは、ゴミ箱状態の投稿をエントリの除外リストに追加します。

サンプル2: ユーザー権限に基づいて除外

function exclude_for_non_admins( $excluded_statuses ) {
    if ( ! current_user_can( 'administrator' ) ) {
        $excluded_statuses[] = 'pending'; // 非管理者に対して保留中のエントリを除外
    }
    return $excluded_statuses;
}
add_filter( 'wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses', 'exclude_for_non_admins' );

このコードは、非管理者のユーザーに対して保留中のエントリを除外します。

サンプル3: テーマオプションに基づく条件付き除外

function exclude_based_on_theme_option( $excluded_statuses ) {
    if ( get_option( 'disable_pending_entries' ) ) {
        $excluded_statuses[] = 'pending'; // テーマオプションが有効な場合、保留中を除外
    }
    return $excluded_statuses;
}
add_filter( 'wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses', 'exclude_based_on_theme_option' );

このコードは、テーマオプションに基づいて保留中のエントリを除外します。

サンプル4: カスタム条件によるフィルタリング

function custom_exclude_based_on_condition( $excluded_statuses ) {
    if ( some_custom_condition() ) {
        $excluded_statuses[] = 'spam'; // 特定の条件に基づいてスパムを除外
    }
    return $excluded_statuses;
}
add_filter( 'wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses', 'custom_exclude_based_on_condition' );

このコードは、特定のカスタム条件が成立している場合にスパムエントリを除外します。

サンプル5: 複数のステータスを一度に除外

function exclude_multiple_post_statuses( $excluded_statuses ) {
    $excluded_statuses = array_merge( $excluded_statuses, array( 'draft', 'private' ) ); // 下書きと非公開を除外
    return $excluded_statuses;
}
add_filter( 'wpforms_locker_lockers_entry_limit_exclude_not_allowed_entries_excluded_statuses', 'exclude_multiple_post_statuses' );

このコードは、下書きと非公開のエントリを一度に除外します。

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

アクション名 使用可否
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

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


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