AI要約
説明
wpforms_display_field_before アクションは、ラベルなどの特定のフォーム要素の位置を決定するために、フォームが表示される前に発生します。
パラメーター
- $fields
- (配列)サニタイズされたエントリーフィールドの値/プロパティ。
- $form_data
- (配列)フォームの設定/データ。
ソース
wpforms/src/Frontend/Frontend.php
詳細情報
フォームが表示される前にアクションが実行されます。このアクションを使用して、フォームフィールドラベルなどのフォームの属性を移動できます。
例
この例では、アクションを削除することでラベルを完全に削除します。
/**
* Action fires before the form is displayed to determine the position of certain form elements such as labels.
*
* @link https://wpforms.com/developers/wpforms_display_field_before/
*
* @param array $fields Sanitized entry field values/properties.
* @param array $form_data Form settings/data.
* @return array
*/
function wpf_dev_display_field_before( $field, $form_data ) {
// Only run this snippet on the form with the ID of 879
if ( absint( $form_data[ 'id' ] ) !== 879 ) {
return;
}
remove_action( 'wpforms_display_field_before', array( wpforms()->frontend, 'field_label' ), 15, 2 );
}
add_action( 'wpforms_display_field_before', 'wpf_dev_display_field_before', 10, 2 );