WordPress后台用户列表添加用户注册时的IP地址方法
- Wordpress
- 2023-09-01
- 106热度
- 0评论
我们只需将下面代码添加到当前WordPress模板函数functions.php中即可:
function log_ip($user_id){ $ip = $_SERVER['REMOTE_ADDR']; update_user_meta($user_id, 'signup_ip', $ip); } add_action('user_register', 'log_ip'); // 添加IP地址栏目 function signup_ip($column_headers) { $column_headers['signup_ip'] = __('IP地址', 'signup_ip'); return $column_headers; } if ( is_multisite() ) { // 多站点支持 add_filter('wpmu_users_columns', 'signup_ip'); } else { // 单站点支持 add_filter('manage_users_columns', 'signup_ip'); } // 格式化输出内容 function ripms_columns($value, $column_name, $user_id) { if ( $column_name == 'signup_ip' ) { $ip = get_user_meta($user_id, 'signup_ip', true); if ($ip != ""){ $ret = '<em>'.__($ip, 'signup_ip').'</em>'; return $ret; } else { $ret = '<em>'.__('暂无数据', 'signup_ip').'</em>'; return $ret; } } return $value; } add_action('manage_users_custom_column', 'ripms_columns', 10, 3);
WordPress后台用户列表怎么按用户注册时间排序
//添加用户注册时间列 add_filter( 'manage_users_columns', 'zhuige_manage_users_columns' ); function zhuige_manage_users_columns( $columns ){ $columns[ 'registered' ] = '注册时间'; return $columns; } //通过 manage_users_custom_column 钩子返回值排序 add_action( 'manage_users_custom_column', 'zhuige_manage_users_custom_column', 10, 3 ); function zhuige_manage_users_custom_column( $var, $column_name, $user_id ){ switch( $column_name ) { case "registered" : return get_user_by('id', $user_id)->data->user_registered; } } //让添加的“注册时间”可以点击 add_filter( "manage_users_sortable_columns", 'zhuige_manage_users_sortable_columns' ); function zhuige_manage_users_sortable_columns($sortable_columns){ $sortable_columns['registered'] = 'registered'; return $sortable_columns; }