Php Code to add Unique Id number or member id number to wordpress user on registration
Below is the code I found in WordPress forum, which helped me to add Unique client id to my website with every new user registration form as “New User Meta”.
I have used Ultimate members (Free) plugin for Login and Registration form.
add_action(“user_register”,”um_012022_generate_unique_account_id”);
function um_012022_generate_unique_account_id( $user_id ) {
$unique_account_id = ’22’ . str_pad( $user_id, 5, ‘0’, STR_PAD_LEFT );
update_user_meta( $user_id, “um_unique_account_id”, $unique_account_id );
}
Php Code to add Unique Id number or member id number to wordpress admin area user list.
Below code also I found in WordPress forum which helped me to show my Unique Id to user list of Admin Area.
function add_custom_column_name($columns) {
$columns[‘columns_array_name’] = ‘Client ID Number’;
return $columns;
}
function show_custom_column_values($value, $column_name, $user_id) {
if ( ‘columns_array_name’ == $column_name )
return get_user_meta( $user_id, ‘um_unique_account_id’, true );
}
add_filter(‘manage_users_columns’, ‘add_custom_column_name’);
add_action(‘manage_users_custom_column’, ‘show_custom_column_values’, 10, 3);
Php Code to add Phone number to wordpress admin area user list.
add_filter(‘manage_users_columns’, ‘um_060721_column_order’);
function um_060721_column_order($columns) {
$n_columns = array();
$before = ’email’; // move before this
foreach($columns as $key => $value) {
if ($key==$before){
$n_columns[‘birth_date’] = ”;
$n_columns[‘status’] = ”;
}
$n_columns[$key] = $value;
}
return $n_columns;
}
function um_070821_custom_define() {
$custom_meta_fields = array();
$custom_meta_fields[‘phone_number’] = ‘phone Number’;
return $custom_meta_fields;
}
function um_070821_columns($defaults) {
$meta_number = 0;
$custom_meta_fields = um_070821_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
$defaults[(‘um_070821-usercolumn-‘ . $meta_number . ”)] = __($meta_disp_name, ‘user-column’);
}
return $defaults;
}
function um_070821_custom_columns($value, $column_name, $id) {
$meta_number = 0;
$custom_meta_fields = um_070821_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
if( $column_name == (‘um_070821-usercolumn-‘ . $meta_number . ”) ) {
$value = get_user_meta( $id, $meta_field_name, true );
}
}
return $value;
}
add_action(‘manage_users_custom_column’, ‘um_070821_custom_columns’, 15, 3);
add_filter(‘manage_users_columns’, ‘um_070821_columns’, 15, 1);
Add Search or Filter Option to WordPress admin area user list with User Meta (I have Client ID as new User meta)
Below plugin helped me to enable search/filter with my newly created User meta (Client ID) in WordPress admin area User List.
Plugin Name: Better User Search
I feel this codes are helpful for many new wordpress developer that’s why posted this codes on my blog. If any one feels this is helpful please comment. [Special thanks to WordPress Forum & Stack Over Flow website