WordPress默认提供的用于显示用户的信息不满足要求?好,那就自定义吧。
[caption id="attachment_3421" align="aligncenter" width="1250"]
WordPress用户信息自定义[/caption]
[codesyntax lang="php"]
add_filter('manage_users_columns', 'suren_manage_user_columns', 10, 2);
add_action('manage_users_custom_column', 'suren_manage_user_custom_column', 10, 3);
add_action('wp_login', 'suren_wp_login');
function suren_manage_user_columns($columns)
{
$columns["last_login"] = "LastLogin";
$columns["last_ip"] = "LastIP";
unset($columns['name']);
return $columns;
}
function suren_manage_user_custom_column($value, $column_name, $user_id)
{
$user = get_userdata($user_id);
if('last_login' == $column_name)
{
if($user->last_login)
{
$value = get_user_meta($user->ID, 'last_login', true);
}
else
{
$value = 'Not Login';
}
}
else if('last_ip' == $column_name)
{
if($user->last_ip)
{
$value = get_user_meta($user->ID, 'last_ip', true);
}
else
{
$value = 'Unknow';
}
}
else
{
$value = 'Not Login';
}
return $value;
}
function suren_wp_login($login)
{
global $user_id;
$user = get_userdatabylogin($login);
update_user_meta($user->ID, 'last_login', current_time('mysql'));
update_user_meta($user->ID, 'last_ip', get_remote_ip());
}
function get_remote_ip()
{
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknow'))
{
$ip = getenv('HTTP_CLIENT_IP');
}
else if(getenv('HTTP_X_FORWARD_FOR') && strcasecmp(getenv('HTTP_X_FORWARD_FOR'), 'unknow'))
{
$ip = getenv('HTTP_X_FORWARD_FOR');
}
else if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknow'))
{
$ip = getenv('REMOTE_ADDR');
}
else if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknow'))
{
$ip = $_SERVER['REMOTE_ADDR'];
}
else
{
$ip = 'unknow';
}
return $ip;
}
[/codesyntax]
[codesyntax lang="php"]
add_action('show_user_profile', 'suren_show_user_profile');
function suren_show_user_profile($user)
{
echo get_the_author_meta('last_login', $user->ID);
echo '
';
echo get_the_author_meta('last_ip', $user->ID);
}
[/codesyntax]