Last active
September 11, 2019 08:51
-
-
Save max-kk/83c30c3e0be6d967d0c0e733e4e1a338 to your computer and use it in GitHub Desktop.
lrm_save_custom_field
This file contains 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 | |
// ONLY IF you want the user login via phone-number | |
// COPY after | |
add_filter('lrm/login_info_filter', function ($info) { | |
$user_login = $info['user_login']; | |
// Optionally | |
// $user_login = str_replace(["+", "-", " "], '', $info['user_login']); | |
// Commnets this to allow phone duplicates | |
$users = get_users(array( | |
'meta_key' => 'phone', | |
'meta_value' => $user_login, | |
)); | |
if ( $users ) { | |
$info['user_login'] = $users[0]->user_login; | |
} | |
return $info; | |
}); |
This file contains 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 | |
add_filter( 'registration_errors',function ( $errors, $sanitized_user_login, $user_email ) { | |
if ( empty( $_POST['phone'] ) ) { | |
$errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'LANG_DOMAIN' ) ); | |
} else { | |
// Commnets this to allow phone duplicates | |
$users = get_users(array( | |
'meta_key' => 'phone', | |
'meta_value' => $_POST['phone'], | |
)); | |
if ( $users ) { | |
$errors->add( 'phone_error', __( '<strong>ERROR</strong>: This Phone is already registered!', 'LANG_DOMAIN' ) ); | |
} | |
} | |
return $errors; | |
}, 10, 3 ); | |
add_action( 'user_register', function ( $user_id ) { | |
if ( ! empty( $_POST['phone'] ) ) { | |
update_user_meta( $user_id, 'phone', sanitize_text_field($_POST['phone'] ) ); | |
} | |
}); |
This file contains 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 | |
// COPY AFTER | |
/** | |
* Back end display | |
*/ | |
add_action( 'show_user_profile', 'lrm_show_extra_profile_fields' ); | |
add_action( 'edit_user_profile', 'lrm_show_extra_profile_fields' ); | |
function lrm_show_extra_profile_fields( $user ) { | |
?> | |
<h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="phone"><?php esc_html_e( 'Phone', 'LANG_DOMAIN' ); ?></label></th> | |
<td><?php echo esc_html( get_user_meta( $user->ID, 'phone', true ) ); ?></td> | |
</tr> | |
</table> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment