WordPress 后台用户根据注册时间排序

//WordPress 后台用户根据注册时间排序
//添加用户注册时间列
add_filter( 'manage_users_columns', 'my_users_columns' );
function my_users_columns( $columns ){
    $columns[ 'registered' ] = '注册时间';
    return $columns;
}
//通过 manage_users_custom_column 钩子返回值排序
add_action( 'manage_users_custom_column', 'output_my_users_columns', 10, 3 );
function  output_my_users_columns( $var, $column_name, $user_id ){
    switch( $column_name ) {
        case "last_activity" :
            return get_user_meta($user_id, 'last_activity', true);
        case "registered" :
            return get_user_by('id', $user_id)->data->user_registered;
        case "sex" :
            return get_user_meta($user_id, 'sex', true);
        case "occ" :
            return get_user_meta($user_id, 'occ', true);
        case "qq" :
            return get_user_meta($user_id, 'qq', true);
            break;
    }
}
//让添加的“注册时间”可以点击,也就是添加链接并且右边有一个小箭头
add_filter( "manage_users_sortable_columns", 'wenshuo_users_sortable_columns' );
function wenshuo_users_sortable_columns($sortable_columns){
    $sortable_columns['registered'] = 'registered';
    return $sortable_columns;
}
//最后根据浏览器的 url,重新设置 wordpress 的查询函数
add_action( 'pre_user_query', 'wenshuo_users_search_order' );
function wenshuo_users_search_order($obj){
    if(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='registered' ){
        if( !in_array($_REQUEST['order'],array('asc','desc')) ){
            $_REQUEST['order'] = 'desc';
        }
        $obj->query_orderby = "ORDER BY user_registered ".$_REQUEST['order']."";
    }
}