Last active
October 14, 2022 14:57
-
-
Save shishirraven/b4ab2e9755eec7accae8ec3b7a863abc to your computer and use it in GitHub Desktop.
Adding a Phone number to the wordPress users.
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
lwp_register_rest_route | |
add_action('edit_user_profile_update', array(&$this, 'lwp_update_phonenumber_field')); | |
add_action('personal_options_update', array(&$this, 'lwp_update_phonenumber_field')); | |
add_action('edit_user_profile', array(&$this, 'lwp_add_phonenumber_field')); | |
add_action('show_user_profile', array(&$this, 'lwp_add_phonenumber_field')); | |
function lwp_add_phonenumber_field($user) | |
{ | |
$phn = get_the_author_meta('phone_number', $user->ID); | |
?> | |
<h3><?php esc_html_e('Personal Information', 'crf'); ?></h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="phone_number"><?php esc_html_e('phone_number', $this->textdomain); ?></label></th> | |
<td> | |
<input type="text" | |
step="1" | |
id="phone_number" | |
name="phone_number" | |
value="<?php echo esc_attr($phn); ?>" | |
class="regular-text" | |
/> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
function lwp_update_phonenumber_field($user_id) | |
{ | |
if (!current_user_can('edit_user', $user_id)) { | |
return false; | |
} | |
// if ( ! empty( $_POST['year_of_birth'] ) && intval( $_POST['year_of_birth'] ) >= 1900 ) { | |
update_user_meta($user_id, 'phone_number', $_POST['phone_number']); | |
// } | |
} | |
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
add_filter('manage_users_columns', array(&$this, 'lwp_modify_user_table')); | |
add_filter('manage_users_custom_column', array(&$this, 'lwp_modify_user_table_row'), 10, 3); | |
add_filter('manage_users_sortable_columns', array(&$this, 'lwp_make_registered_column_sortable')); | |
function lwp_modify_user_table($column) | |
{ | |
$column['phone_number'] = __('Phone number', $this->textdomain); | |
$column['activation_code'] = __('Activation code', $this->textdomain); | |
$column['registered_date'] = __('Registered date', $this->textdomain); | |
return $column; | |
} | |
function lwp_modify_user_table_row($val, $column_name, $user_id) | |
{ | |
$udata = get_userdata($user_id); | |
switch ($column_name) { | |
case 'phone_number' : | |
return get_the_author_meta('phone_number', $user_id); | |
case 'activation_code' : | |
return get_the_author_meta('activation_code', $user_id); | |
case 'registered_date' : | |
return $udata->user_registered; | |
default: | |
} | |
return $val; | |
} | |
function lwp_make_registered_column_sortable($columns) | |
{ | |
return wp_parse_args(array('registered_date' => 'registered'), $columns); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment