Description
Filters the form rows before they are put together for the form.
Parameters
$rows
(array) (required) An array of the forms row elements. Each row element will include the following keys:
- order – the field order (currently not used)
- label_text – the raw text for the label (static)
- type – The field type (i.e. text, checkbox, dropdown, textarea)
- value – The field value (only populated if error state or profile edit)
- values – The possible values for the field (dropdown select, multiple select/checkbox, radio group) – 3.1 and higher only
- row_before – HTML tags before the row
- label – HTML label tag
- field_before – HTML tags before the field input tag
- field – HTML input
- field_after – HTML tags after the field input tag
- row_after = HTML tags after the row
$tag
(string) (optional) Indicates the form that is being displayed (new|edit).
Usage
add_filter( 'wpmem_register_form_rows', 'my_register_form_rows_filter', 10, 2 ); function my_register_form_rows_filter( $rows, $toggle ) { /* Form rows are assembled as an array and the entire array is passed through this filter. Each row will have an array key equal to its optionname (meta_key). order, label_type, type, value, and values are all passed for doing value comparisons. The remaining keys are form output and changes here will be reflected in the displayed form. $rows['meta_key'] = array ( 'order' => 1, 'type' => 'text', 'value' => '', 'row_before' => '', 'label' => '<label for="option_name" class="text">Field Label</label>', 'field_before' => '<div class="div_text">', 'field' => '<input name="option_name" type="text" id="option_name" value="" class="textbox" />', 'field_after' => '</div>', 'row_after' => '', ); $rows['meta_key']['label'] can be generated with wpmem_form_label() $rows['meta_key']['field'] can be generated with wpmem_form_field() */ return $rows; } /* * The following example changes an element's output. */ add_filter( 'wpmem_register_form_rows', 'my_new_element', 10, 2 ); function my_new_element( $rows, $tag ) { // Change the label for a field with "my_field" as the meta key $rows['my_field']['label'] = "<label>My Custom Field Label</label>"; return $rows; } /* * The following example adds a div wrapper with the * class "my_row_wrapper" to all form rows. */ add_filter( 'wpmem_register_form_rows', 'my_row_wrapper', 10, 2 ); function my_row_wrapper( $rows, $tag ) { foreach ( $rows as $meta_key => $row ) { $rows[ $meta_key ]['row_before'] = '<div class="my_row_wrapper">'; $rows[ $meta_key ]['row_after'] = '</div>'; } return $rows; } /* * The following example adds a "heading" row between the name * fields and the address fields. This is just a single example * of how wpmem_register_form_rows can be used to put additional * rows into the form (note: it can also be used to remove rows). * * This example also uses wpmem_array_insert(). * @see: https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_array_insert/ */ add_filter( 'wpmem_register_form_rows', 'my_field_separator', 10, 2 ); function my_field_separator( $rows, $tag ) { /* * Define an array of row elements. * Unused elements can be empty ('') * but must still be defined. */ $new_row['address_heading'] = array( 'order' => '', 'meta' => '', 'type' => '', 'value' => '', 'row_before' => '', 'label' => '<label class="text"></label>', 'field_before' => '<div class="div_text">', 'field' => '<h3>Please include your address information</h3>', 'field_after' => '</div>', 'row_after' => '' ); /* * Add your new row into the $rows array using * wpmem_array_insert( $array, $new, $key ) * - $array The array you are adding to. * - $new The new element being added. * - $key The key in $array you will add after. */ $rows = wpmem_array_insert( $rows, $new_row, 'last_name' ); // If additional rows are needed, repeat the process. // Return filtered $rows array. return $rows; } // end of my_field_separator()
Notes
- When using wpmem_register_form_rows to generate new field or label HTML, the following API functions can be used:
wpmem_form_label()
wpmem_form_field() - New array values can be inserted using wpmem_array_insert()
Changelog
Introduced in version 2.9.0
Added “label_text” key in 3.0.9
Added “values” key in 3.1.0
Deprecated “order” key in 3.1.2
Source
wpmem_register_form_rows is located in includes/class-wp-members-forms.php