LLMS_Forms_Dynamic_Fields::add_password_strength_meter( array[] $blocks, $location )
Adds a password strength meter to a block list
Description Description
This function will programmatically add an html block containing the necessary markup for the password strength meter to function.
This will locate the user password block and output the meter immediately after the block. If the password block is within a group it’ll output it after the group block.
Parameters Parameters
- $blocks
-
(array[]) (Required) WP_Block list.
Return Return
(array[])
Source Source
File: includes/forms/class-llms-forms-dynamic-fields.php
public function add_password_strength_meter( $blocks, $location ) { $password = $this->find_block( 'password', $blocks ); // No password field in the form. if ( ! $password ) { return $blocks; } list( $index, $block ) = $password; // Meter not enabled. if ( empty( $block['attrs']['meter'] ) || ! llms_parse_bool( $block['attrs']['meter'] ) ) { return $blocks; } $meter_settings = array( 'type' => 'html', 'id' => 'llms-password-strength-meter', 'classes' => 'llms-password-strength-meter', 'description' => ! empty( $block['attrs']['meter_description'] ) ? $block['attrs']['meter_description'] : '', 'min_length' => ! empty( $block['attrs']['html_attrs']['minlength'] ) ? $block['attrs']['html_attrs']['minlength'] : '', 'min_strength' => ! empty( $block['attrs']['min_strength'] ) ? $block['attrs']['min_strength'] : '', 'llms_visibility' => ! empty( $block['attrs']['llms_visibility'] ) ? $block['attrs']['llms_visibility'] : '', 'attributes' => array( 'aria-live' => 'polite', ), ); if ( 'account' === $location ) { $meter_settings['wrapper_classes'] = 'llms-visually-hidden-field'; } /** * Filters the settings used to create the dynamic password strength meter block * * @since 5.0.0 * * @param array $meter_settings Array or block attributes/settings. */ $meter_settings = apply_filters( 'llms_password_strength_meter_field_settings', $meter_settings ); return $this->add_block( $blocks, $meter_settings, $index ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.0.1 | Add aria-live=polite to ensure password strength is announced for screen readers. |
5.0.0 | Introduced. |