説明

について wpforms_field_properties フィルタはフォームのロード時に起動し、ラベル、サブラベル、説明などのフィールドプロパティをフォームフィールドの上に表示します。

パラメータ

プロパティ
(配列)ラベル、サブラベル、説明などのフィールドプロパティの配列。
フィールド
(配列)サニタイズされたフィールドデータ。
フォームデータ
(配列) 処理済みのフォーム設定/データ。

ソース

wpforms/includes/fields/class-base.php

詳細情報

フィルタは特定のフォームフィールドプロパティの配列に適用されます。このフィルタを使うと、すべてのフォームフィールドが変更されます。

各フォームフィールドはそれぞれ固有のフィルター名を持ちます。文書化された例の完全なリストは以下のセクションをご覧ください。たとえば 電子メール フォーム・フィールドでは wpforms_field_properties_email.

以下の例では、この関数はフィールドの上にフィールドの説明を表示しますが、フォームID225に対してのみ表示します。

/**
 * Move the field description above the form field.
 *
 * @link   https://wpforms.com/developers/wpforms_field_properties/
 *
 * @param  array $properties Field properties.
 * @param  array $field      Field settings.
 * @param  array $form_data  Form data and settings.
 *
 * @return array
 */

function wpf_dev_field_properties( $properties, $field, $form_data ) {

    // Only process this snippet on the form ID 225
    if ( absint( $form_data[ 'id' ] ) !== 225 ) {

        return $properties;
    } 

    // move the field description from under the form field to above the form field
    $properties[ 'description' ][ 'position' ] = 'before';

    return $properties;

}
add_filter( 'wpforms_field_properties', 'wpf_dev_field_properties', 10, 3 );

参考記事