AI要約
説明
wpforms_datetime_date_formats フィルターは、フォームビルダーの日付ピッカーで利用可能な日付フィールドのフォーマットをフィルター処理します。
パラメーター
- $formats
- (配列) (必須) 日付フォーマットオプション。
ソース
wpforms/includes/functions/data-presets.php
詳細情報
このフィルターは、日付フィールドのフォーマットオプションを含む配列に適用されます。これらのオプションは、日付ピッカーオプションを使用する際にフォームビルダー内で提供されます。
このフィルターを使用して、追加のフォーマットオプションを追加できます。フォーマットは、ユーザーに日付フィールドの選択がどのように表示されるか、エントリーや通知に日付がどのように表示されるか、そしてデータベース内で日付フィールドの選択がどのように表示されるかを決定します。
デフォルトの日付フォーマットオプションには以下が含まれます:
- m/d/Y: 2019/01/31
- d/m/Y: 31/01/2019
- F j, Y: 2019年1月31日
追加のフォーマットオプションについては、PHPの日付リファレンスを参照してください。
例
以下の例では、すべてのデフォルトの日付オプションを保持しつつ、
l j \of F Y を使用してTuesday 27 of August 2019 のように表示される新しいオプションを追加します。
スニペットで、of という単語をバックスラッシュ(\)でエスケープしていることに注意してください。
/**
* Filters the date field formats available for the Date Picker in the form builder.
*
* @link https://wpforms.com/developers/wpforms_datetime_date_formats/
*
* @param array $formats Date format options.
* @return array
*/
function wpf_dev_date_field_formats( $formats ) {
// Item key is JS date character - see https://flatpickr.js.org/formatting/
// Item value is in PHP format - see http://php.net/manual/en/function.date.php
// Adds new format Monday, 20th of December 2021
$formats[ 'l, J \of F Y' ] = 'l, jS \of F Y';
return $formats;
}
add_filter( 'wpforms_datetime_date_formats', 'wpf_dev_date_field_formats', 10, 1 );
関連
記事参照: 日付フィールドの追加フォーマットの作成方法