在 WordPress 后台,用户是按照用户名排序的,并且没有显示注册时间,如果我们希望能够在后台看到用户的注册时间,并且按照注册时间排序,可以通过下面的代码实现:
复制代码代码如下:
/*
Plugin Name: 按照用户注册时间排序
Plugin URI: http://blog.wpjam.com/m/order-by-user-registered-time/
Description: 显示用户注册时间,并按照用户注册时间排序。
Version: 0.1
Author: Denis
Author URI: http://blog.wpjam.com/
*/
add_filter('manage_users_columns','wpjam_add_users_column_reg_time');
function wpjam_add_users_column_reg_time($column_headers){
$column_headers['reg_time'] = '注册时间';
return $column_headers;
}
add_filter('manage_users_custom_column', 'wpjam_show_users_column_reg_time',11,3);
function wpjam_show_users_column_reg_time($value, $column_name, $user_id){
if($column_name=='reg_time'){
$user = get_userdata($user_id);
return get_date_from_gmt($user->user_registered);
}else{
return $value;
}
}
add_filter( "manage_users_sortable_columns", 'wpjam_users_sortable_columns' );
function ys_users_sortable_columns($sortable_columns){
$sortable_columns['reg_time'] = 'reg_time';
return $sortable_columns;
}
add_action( 'pre_user_query', 'wpjam_users_search_order' );
function wpjam_users_search_order($obj){
if(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='reg_time' ){
if( !in_array($_REQUEST['order'],array('asc','desc')) ){
$_REQUEST['order'] = 'desc';
}
$obj->query_orderby = "ORDER BY user_registered ".$_REQUEST['order']."";
}
}
将上面的保存为一个插件,上传激活之后,就可以在用户界面看到注册时间,并且按照注册时间排序了:
复制代码代码如下:
/*
Plugin Name: 按照用户注册时间排序
Plugin URI: http://blog.wpjam.com/m/order-by-user-registered-time/
Description: 显示用户注册时间,并按照用户注册时间排序。
Version: 0.1
Author: Denis
Author URI: http://blog.wpjam.com/
*/
add_filter('manage_users_columns','wpjam_add_users_column_reg_time');
function wpjam_add_users_column_reg_time($column_headers){
$column_headers['reg_time'] = '注册时间';
return $column_headers;
}
add_filter('manage_users_custom_column', 'wpjam_show_users_column_reg_time',11,3);
function wpjam_show_users_column_reg_time($value, $column_name, $user_id){
if($column_name=='reg_time'){
$user = get_userdata($user_id);
return get_date_from_gmt($user->user_registered);
}else{
return $value;
}
}
add_filter( "manage_users_sortable_columns", 'wpjam_users_sortable_columns' );
function ys_users_sortable_columns($sortable_columns){
$sortable_columns['reg_time'] = 'reg_time';
return $sortable_columns;
}
add_action( 'pre_user_query', 'wpjam_users_search_order' );
function wpjam_users_search_order($obj){
if(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='reg_time' ){
if( !in_array($_REQUEST['order'],array('asc','desc')) ){
$_REQUEST['order'] = 'desc';
}
$obj->query_orderby = "ORDER BY user_registered ".$_REQUEST['order']."";
}
}
将上面的保存为一个插件,上传激活之后,就可以在用户界面看到注册时间,并且按照注册时间排序了:
关键字词: