LLMS_Form_Handler::maybe_modify_edit_account_field_settings( array $posted_data, string $location, array[] $fields )
Modify LifterLMS Fields prior to performing submit handler validations.
Parameters Parameters
- $posted_data
-
(array) (Required) User submitted form data (passed by reference).
- $location
-
(string) (Required) Form location ID.
- $fields
-
(array[]) (Required) Array of LifterLMS Form Fields (passed by reference).
Return Return
(void)
Source Source
File: includes/forms/class-llms-form-handler.php
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | public function maybe_modify_edit_account_field_settings( & $posted_data , $location , & $fields ) { if ( 'account' !== $location ) { return ; } /** * If email address and passwords aren't submitted we can mark them as "optional" fields. * * These fields are dynamically toggled and disabled if they're not modified. * Process `password_current` as last as it depends on `password` field submission. */ foreach ( array ( 'email_address' , 'password' , 'password_current' ) as $field_id ) { // If the field exists and it's not included (or empty) in the posted data. $index = LLMS_Forms::instance()->get_field_by( $fields , 'id' , $field_id , 'index' ); if ( false !== $index && empty ( $posted_data [ $fields [ $index ][ 'name' ] ] ) ) { // When updating a password, the `password_current` is mandatory. if ( 'account' === $location && 'password_current' === $field_id ) { // Get `password` field. $password_index = LLMS_Forms::instance()->get_field_by( $fields , 'id' , 'password' , 'index' ); // If a `passowrd` feld has been submitted then the `password_current` cannot be skipped. if ( false !== $password_index && ! empty ( $posted_data [ $fields [ $password_index ][ 'name' ] ] ) ) { continue ; } } // Remove the field so we don't accidentally save an empty value later. unset( $posted_data [ $fields [ $index ][ 'name' ] ] ); // Mark the field as optional (for validation purposes). $fields [ $index ][ 'required' ] = false; // Check if there's a confirm field and do the same. $con_index = LLMS_Forms::instance()->get_field_by( $fields , 'id' , "{$field_id}_confirm" , 'index' ); if ( false !== $con_index && empty ( $posted_data [ $fields [ $con_index ][ 'name' ] ] ) ) { unset( $posted_data [ $fields [ $con_index ][ 'name' ] ] ); $fields [ $con_index ][ 'required' ] = false; } } } } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.1.0 | Do not allow submitting a password change without providing a password_current |
5.0.0 | Introduced. |