概要
フィルタ tec_events_custom_tables_v1_show_series_title
は、The Events Calendar プラグインにおいて、イベントのシリーズタイトルを表示するかどうかをカスタマイズするために使用されるフックです。このフィルタを利用することで、表示したい情報の制御や、特定の条件に基づいたカスタマイズが可能となります。主な利用シーンとしては、以下のような機能の実装が考えられます。
- シリーズタイトルの表示・非表示の切り替え
- イベントリストにおけるスタイリングの調整
- 特定のユーザーやロールに応じたタイトルの表示
- 多言語サイトにおけるタイトルの翻訳管理
- 条件に基づくシリーズタイトルのデフォルト値の変更
- タイトルの装飾やフォーマットの変更
構文
add_filter('tec_events_custom_tables_v1_show_series_title', 'custom_show_series_title', 10, 2);
パラメータ
$show_series_title
(bool): 初期値は true。シリーズタイトルを表示するかどうか。$event
(WC_Event): 現在のイベントオブジェクト。
戻り値
- (bool): シリーズタイトルを表示する場合は true、表示しない場合は false。
バージョン情報
- The Events Calendar: 5.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('tec_events_custom_tables_v1_show_series_title', function($show_series_title) {
return false;
});
サンプルコード2: 管理画面でユーザー役割によって表示を変更
このコードは、管理者ユーザーがイベントを表示する場合のみシリーズタイトルを表示します。
add_filter('tec_events_custom_tables_v1_show_series_title', function($show_series_title, $event) {
if (current_user_can('administrator')) {
return true;
}
return false;
}, 10, 2);
サンプルコード3: 特定の条件によるタイトルの変更
このコードは、特定の条件に応じてタイトルを表示します。たとえば、特定のカスタムフィールドが設定されている場合にのみ表示。
add_filter('tec_events_custom_tables_v1_show_series_title', function($show_series_title, $event) {
if (get_post_meta($event->ID, 'show_series_title', true)) {
return true;
}
return false;
}, 10, 2);
サンプルコード4: 表示するタイトルのフォーマットを変更
このコードは、シリーズタイトルを太字で表示しますが、実際にはフックの中でスタイルを付加する例です。
add_filter('tec_events_custom_tables_v1_show_series_title', function($show_series_title) {
if ($show_series_title) {
echo '<strong>' . $show_series_title . '</strong>';
}
return $show_series_title;
});
サンプルコード5: イベントに基づく条件付き表示
このコードでは、イベントカテゴリに基づいてシリーズタイトルを表示または非表示にします。
add_filter('tec_events_custom_tables_v1_show_series_title', function($show_series_title, $event) {
if (has_term('特定のカテゴリ', 'tribe_events_cat', $event->ID)) {
return true;
}
return false;
}, 10, 2);
上記のサンプルコードはすべて、著作権フリーのものであり、特定の状況や要件に基づいてカスタマイズできます。