概要
wpforms_dash_widget_timespan_options
フィルタは、WPForms のダッシュボードウィジェットにおけるタイムスパンオプションをカスタマイズするために使用されるフックです。このフィルタを利用することで、デフォルトのタイムスパン選択肢を変更したり、独自のタイムスパンオプションを追加したりすることができます。このフィルタは以下のような機能を実装する際によく使われます。
- 特定の期間のフォームエントリを表示する機能
- 管理者がカスタムタイムスパンを設定できる機能
- ダッシュボードの表示をユーザーに合わせて調整する機能
- フォームのアナリティクスをより詳細に分析する機能
- プラグインの UI をカスタマイズする機能
- ワードプレスの管理画面でのユーザーエクスペリエンスを向上させる機能
構文
add_filter( 'wpforms_dash_widget_timespan_options', 'your_function_name' );
パラメータ
array $timespan_options
:既存のタイムスパンオプションの配列
戻り値
- カスタマイズされたタイムスパンオプションの配列
使用可能なWPFormsのバージョン
- WPForms 1.0 以降
使用可能なワードプレスのバージョン
- WordPress 4.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: デフォルトのタイムスパンオプションを変更する
このコードは、デフォルトのタイムスパンオプションを「1週間」「1か月」に変更します。
add_filter( 'wpforms_dash_widget_timespan_options', function( $timespan_options ) {
return [
'last_7_days' => '1週間',
'last_30_days' => '1か月',
];
} );
引用元: https://wpforms.com/docs/wpforms_dash_widget_timespan_options-filter/
サンプル2: カスタムタイムスパンを追加する
このコードは、カスタムタイムスパン「3日間」を追加します。
add_filter( 'wpforms_dash_widget_timespan_options', function( $timespan_options ) {
$timespan_options['last_3_days'] = '3日間';
return $timespan_options;
} );
引用元: https://wpforms.com/docs/wpforms_dash_widget_timespan_options-filter/
サンプル3: 期間に基づく条件でタイムスパンを変更する
このコードは、特定の条件に基づいてタイムスパンオプションを動的に変更します。
add_filter( 'wpforms_dash_widget_timespan_options', function( $timespan_options ) {
if ( is_admin() ) {
$timespan_options['last_24_hours'] = '過去24時間';
}
return $timespan_options;
} );
引用元: https://wpforms.com/docs/wpforms_dash_widget_timespan_options-filter/
サンプル4: タイムスパンオプションを並べ替える
このコードは、タイムスパンオプションの順序を変更します。
add_filter( 'wpforms_dash_widget_timespan_options', function( $timespan_options ) {
$timespan_options = array_reverse( $timespan_options );
return $timespan_options;
} );
引用元: https://wpforms.com/docs/wpforms_dash_widget_timespan_options-filter/
サンプル5: 不要なタイムスパンオプションを削除する
このコードは、特定のタイムスパンオプションを削除します。
add_filter( 'wpforms_dash_widget_timespan_options', function( $timespan_options ) {
unset( $timespan_options['last_7_days'] );
return $timespan_options;
} );
引用元: https://wpforms.com/docs/wpforms_dash_widget_timespan_options-filter/