Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yanknudtskov/b5b1e77c6a7c82ae6704da01387b4c46 to your computer and use it in GitHub Desktop.
Save yanknudtskov/b5b1e77c6a7c82ae6704da01387b4c46 to your computer and use it in GitHub Desktop.
Add a column to the Users overview in WordPress Admin to display the registration date
<?php
/*
* Create a column. And maybe remove some of the default ones
* @param array $columns Array of all user table columns {column ID} => {column Name}
*/
add_filter( 'manage_users_columns', 'yanco_modify_user_table' );
function yanco_modify_user_table( $columns ) {
// unset( $columns['posts'] ); // maybe you would like to remove default columns
$columns['registration_date'] = 'Registreret'; // add new
return $columns;
}
/*
* Fill our new column with the registration dates of the users
* @param string $row_output text/HTML output of a table cell
* @param string $column_id_attr column ID
* @param int $user user ID (in fact - table row ID)
*/
add_filter( 'manage_users_custom_column', 'yanco_modify_user_table_row', 10, 3 );
function yanco_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;
}
/*
* Make our "Registration date" column sortable
* @param array $columns Array of all user sortable columns {column ID} => {orderby GET-param}
*/
add_filter( 'manage_users_sortable_columns', 'yanco_make_registered_column_sortable' );
function yanco_make_registered_column_sortable( $columns ) {
return wp_parse_args( array( 'registration_date' => 'registered' ), $columns );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment