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.


Top ↑

Parameters Parameters

$blocks

(array[]) (Required) WP_Block list.


Top ↑

Return Return

(array[])


Top ↑

Source Source

File: includes/forms/class-llms-forms-dynamic-fields.php

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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 );
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.1 Add aria-live=polite to ensure password strength is announced for screen readers.
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.