Last active
August 26, 2020 15:39
-
-
Save max-kk/4a3afc5e16bbeecfaf6314d66c7a28a2 to your computer and use it in GitHub Desktop.
LRM :: save custom fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // How to add html: https://monosnap.com/file/2MVkjClgYE3W3U9cgPEjy4VXXCzXf2 | |
| // COPY AFTER | |
| $lrm_fields = [ 'billing_city'=>'City', 'billing_state'=>'State', 'billing_postcode' => 'Postcode', 'ETC'=>'ETC' ]; | |
| add_filter( 'registration_errors',function ( $errors, $sanitized_user_login, $user_email ) use($lrm_fields) { | |
| foreach( $lrm_fields as $lrm_field=>$lrm_field_label ) { | |
| if ( empty( $_POST[$lrm_field ] ) ) { | |
| $errors->add( $lrm_field .'_error', '<strong>ERROR</strong>: Please enter your ' . $lrm_field_label . '.' ); | |
| } | |
| } | |
| return $errors; | |
| }, 10, 3 ); | |
| add_action( 'user_register', function ( $user_id ) use($lrm_fields) { | |
| foreach( $lrm_fields as $lrm_field=>$lrm_field_label ) { | |
| if ( ! empty( $_POST[$lrm_field] ) ) { | |
| update_user_meta( $user_id, $lrm_field, sanitize_text_field($_POST[$lrm_field] ) ); | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // How to add html: https://monosnap.com/file/2MVkjClgYE3W3U9cgPEjy4VXXCzXf2 | |
| // COPY AFTER | |
| $lrm_fields = [ 'phone'=>'Phone', 'address'=>'Address' ]; | |
| add_filter( 'registration_errors',function ( $errors, $sanitized_user_login, $user_email ) use($lrm_fields) { | |
| foreach( $lrm_fields as $lrm_field=>$lrm_field_label ) { | |
| if ( empty( $_POST[$lrm_field ] ) ) { | |
| $errors->add( $lrm_field .'_error', '<strong>ERROR</strong>: Please enter your ' . $lrm_field_label . '.' ); | |
| } | |
| } | |
| return $errors; | |
| }, 10, 3 ); | |
| add_action( 'user_register', function ( $user_id ) use($lrm_fields) { | |
| foreach( $lrm_fields as $lrm_field=>$lrm_field_label ) { | |
| if ( ! empty( $_POST[$lrm_field] ) ) { | |
| update_user_meta( $user_id, $lrm_field, sanitize_text_field($_POST[$lrm_field] ) ); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to send custom fields as an email to user and admin?