wordpress更改用户列表排序(按注册时间排序)教程
<p><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在 WordPress 后台,用户是按照用户名排序的,并且没有显示注册时间,如果我们希望能够在后台看到用户的注册时间,并且按照注册时间排序,可以通过下面的代码实现: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
<?php <br>
/* <br>
Plugin Name: 按照用户注册时间排序 <br>
Plugin URI: http://blog.wpjam.com/m/order-by-user-registered-time/ <br>
Description: 显示用户注册时间,并按照用户注册时间排序。 <br>
Version: 0.1 <br>
Author: Denis <br>
Author URI: http://blog.wpjam.com/ <br>
*/ <br>
add_filter('manage_users_columns','wpjam_add_users_column_reg_time'); <br>
function wpjam_add_users_column_reg_time($column_headers){ <br>
$column_headers['reg_time'] = '注册时间'; <br>
return $column_headers; <br>
} <br>
add_filter('manage_users_custom_column', 'wpjam_show_users_column_reg_time',11,3); <br>
function wpjam_show_users_column_reg_time($value, $column_name, $user_id){ <br>
if($column_name=='reg_time'){ <br>
$user = get_userdata($user_id); <br>
return get_date_from_gmt($user->user_registered); <br>
}else{ <br>
return $value; <br>
} <br>
} <br>
add_filter( "manage_users_sortable_columns", 'wpjam_users_sortable_columns' ); <br>
function ys_users_sortable_columns($sortable_columns){ <br>
$sortable_columns['reg_time'] = 'reg_time'; <br>
return $sortable_columns; <br>
} <br>
add_action( 'pre_user_query', 'wpjam_users_search_order' ); <br>
function wpjam_users_search_order($obj){ <br>
if(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='reg_time' ){ <br>
if( !in_array($_REQUEST['order'],array('asc','desc')) ){ <br>
$_REQUEST['order'] = 'desc'; <br>
} <br>
$obj->query_orderby = "ORDER BY user_registered ".$_REQUEST['order'].""; <br>
} <br>
} </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>将上面的保存为一个插件,上传激活之后,就可以在用户界面看到注册时间,并且按照注册时间排序了:</span></p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><img title="wordpress更改用户列表排序(按注册时间排序)教程" alt="wordpress更改用户列表排序(按注册时间排序)教程" src="https://zhuji.jb51.net/uploads/img/202305/7423db2906ded4bf0def4e175f8fec75.jpg" style="max-width:100%!important;height:auto!important;border: 1px solid rgb(204, 204, 204); vertical-align: middle; padding: 1px; overflow: hidden; max-width: 696px; font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px; width: 600px; height: 468px;'></p>
頁:
[1]