You can add a sortable user registration date column in two ways. First one is by using plugin and second one is by adding custom code in your theme functions.php file or in your custom created plugin.
Step 1: Add new column in users page
Using the following code we can add or remove any column from users table using "manage_users_columns" hook.
add_filter( 'manage_users_columns', 'ad_modify_user_table' );
function ad_modify_user_table( $columns ) {
// unset( $columns['posts'] ); // maybe you would like to remove default columns
$columns['registration_date'] = 'Registration date'; // add new column
return $columns;
}
Step 2: Get the registration date value from users table.
add_filter( 'manage_users_custom_column', 'ad_modify_user_table_row', 10, 3 );
function ad_modify_user_table_row( $row_output, $column_id_attr, $user ) {
$date_format = 'j M, Y H:i';
switch ( $column_id_attr ) {
case 'registration_date' :
return date( $date_format, strtotime( get_the_author_meta( 'registered', $user ) ) );
break;
default:
}
return $row_output;
}
Step 3: Make registration date column sortable.
add_filter( 'manage_users_sortable_columns', 'ad_make_registered_column_sortable' );
function ad_make_registered_column_sortable( $columns ) {
return wp_parse_args( array( 'registration_date' => 'registered' ), $columns );
}
0 Comments