Last active
August 14, 2016 16:30
-
-
Save lenivene/3050f7cfbceafedec536e9400b2615fe to your computer and use it in GitHub Desktop.
List all user by date WordPress
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
<?php | |
/** | |
* Add user date register in column | |
* | |
* @author Lenivene Bezerra | |
* @return columns and filter orderby date user registered | |
*/ | |
add_filter( 'manage_users_columns', 'column_user_registered' ); | |
function column_user_registered( $columns ) { | |
$columns[ 'user_registered' ] = __( 'Date' ); | |
return $columns; | |
} | |
add_action( 'manage_users_custom_column', 'add_column_user_registered', 10, 3); | |
function add_column_user_registered( $value, $column_name, $user_id ) { | |
if( '' == $user_id ) | |
return; | |
if( 'user_registered' == $column_name ){ | |
$user = get_userdata( $user_id ); | |
return $user->user_registered; | |
} | |
} | |
add_filter( 'manage_users_sortable_columns', 'manage_sortable_column_user_registered' ); | |
function manage_sortable_column_user_registered( $columns ) { | |
$custom = array( | |
'user_registered' => 'user_registered' | |
); | |
return wp_parse_args($custom, $columns ); | |
} | |
add_filter( 'request', 'request_orderby_column_user_registered' ); | |
function request_orderby_column_user_registered( $vars ) { | |
if ( isset( $vars['orderby'] ) && 'status' == $vars['orderby'] ) { | |
$vars = array_merge( $vars, array( | |
'meta_key' => 'user_registered', | |
'orderby' => 'meta_value' | |
) ); | |
} | |
return $vars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment