Add columns:
function new_modify_user_table( $column ) {
$column['phone'] = 'Phone';
$column['xyz'] = 'XYZ';
return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );
function new_modify_user_table_row( $val, $column_name, $user_id ) {
switch ($column_name) {
case 'phone' :
return get_the_author_meta( 'phone', $user_id );
case 'xyz' :
return '';
default:
}
return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );
Remove columns:
$c = array( ‘cb’ => ‘<input type=”checkbox” />’, ‘username’ => __( ‘Username’ ), ‘name’ => __( ‘Name’ ), ’email’ => __( ‘E-mail’ ), ‘role’ => __( ‘Role’ ), ‘posts’ => __( ‘Posts’ ) ); |
If for example you need to remove E-mail column you should unset a column with ’email’ ID. Let’s go to the final step:
add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
if (current_user_can('moderator')) {
unset($column_headers['email']);
}
return $column_headers;
}
We use manage_users_columns
filter to achieve this purpose. This code removes ‘E-mail’ folder for users with ‘moderator’ role. Replace it with your own one.
In order to remove other column replace ’email’ column ID to that column ID: role, posts, etc.
Other variant for the list of roles:
add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
$roles = array('moderator', 'users-list-viewer');
foreach($roles as $role) {
if (current_user_can($role)) {
unset($column_headers['email']);
break;
}
}
return $column_headers;
}
Another variant for the list of users ID:
add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
global $current_user;
$users = array(27, 70530, 70531, 70532);
if (in_array($current_user->ID, $users)) {
unset($column_headers['email']);
}
return $column_headers;
}