【WordPress教程】后台用户排序改成注册时间排序教程与PHP源代码

教程说明

代码插入到/wp-content/themes/您正在使用的主题目录/functions.php
例如RiPro:/wp-content/themes/ripro/functions.php

//用户注册时间排序
add_filter('manage_users_columns', function($column_headers){
	$column_headers['registered'] = '注册时间';
	return $column_headers;
});

add_filter('manage_users_custom_column', function($value, $column_name, $user_id){
	if($column_name=='registered'){
		$user = get_userdata($user_id);
		return get_date_from_gmt($user->user_registered);
	}else{
		return $value;
	}
},11,3);


add_filter('manage_users_sortable_columns', function($sortable_columns){
	$sortable_columns['reg_time'] = 'reg_time';
	return $sortable_columns;
});

add_action('pre_user_query', function($query){
	if(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='reg_time' ){
		if( !in_array($_REQUEST['order'],array('asc','desc')) ){
			$_REQUEST['order'] = 'desc';
		}
		$query->query_orderby = "ORDER BY user_registered ".$_REQUEST['order']."";
	}
});
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码

    暂无评论内容