LLMS_Forms_Dynamic_Fields::maybe_add_required_block_fields( array[] $blocks, string $location, array $args )
Maybe add the required email and password block to a form.
Parameters Parameters
- $blocks
-
(array[]) (Required) Array of parsed WP_Block arrays.
- $location
-
(string) (Required) The request form location ID.
- $args
-
(array) (Required) Additional arguments passed to the short-circuit filter.
Return Return
(array[])
Source Source
File: includes/forms/class-llms-forms-dynamic-fields.php
public function maybe_add_required_block_fields( $blocks, $location, $args ) {
$fields_to_require = $this->get_required_fields_for_location( $location, $args );
if ( empty( $fields_to_require ) ) {
return $blocks;
}
foreach ( $fields_to_require as $field_id => $field_block_name ) {
$block = $this->find_block( $field_id, $blocks );
if ( ! empty( $block ) ) {
// Fields in non checkout forms are always visible - see LLMS_Forms::get_form_html().
$blocks = 'checkout' === $location ? $this->make_block_visible( $block[1], $blocks, $block[0] ) : $blocks;
unset( $fields_to_require[ $field_id ] );
if ( empty( $fields_to_require ) ) { // All the required blocks are present.
return $blocks;
}
}
}
return $this->add_required_block_fields( $fields_to_require, $blocks, $location );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.4.1 | Make sure added reusable blocks contain the actual required field, otherwise fall back on the dynamically generated ones. |
| 5.1.0 | Introduced. |