当前位置: 首页 > 阿里云优惠 > 阿里云服务器优惠>> WordPress登录后,显示用户最后登录时间 – WordPress 教程

WordPress登录后,显示用户最后登录时间 – WordPress 教程


Wordpress登录后,显示用户最后登录时间 – WordPress 教程

WordPress用户功能比较弱,很多国人熟习的一些用户信息都无默认的调用代码,比如用户注册时间、最后登录时间等,上篇《登录后,让WordPress显示用户的注册时间》可以在前台显示用户注册时间,这里再分享一个前台显示用户最后登录时间的代码。

可以将下面的代码添加到当前主题functions.php中:

// 记录登录时间function user_last_login($user_login) {    global $user_ID;    // 纠正8小时时差    date_default_timezone_set(PRC);    $user = get_user_by( 'login', $user_login );    update_user_meta($user->ID, 'last_login', date('Y-m-d H:i:s'));}add_action('wp_login','user_last_login');// 调用最后登录时间function get_last_login($user_id) {    $last_login = get_user_meta($user_id, 'last_login', true);    $date_format = get_option('date_format') . ' ' . get_option('time_format');    $the_last_login = mysql2date($date_format, $last_login, false);    echo $the_last_login;}

在主题模板适当位置添加调用代码:

<?php global $userdata; get_currentuserinfo(); get_last_login($userdata->ID); ?>

如果想在后台用户列表中显示最后登录时间可以安装插件:WP Last Login 。


服务器购买/咨询热线:1563700917115617636856

本文链接:http://www.sqxnmj.com/alfwq/28690.html
tags:
腾讯云服务器特惠

  • 关注微信
是否收录:

猜你喜欢

微信公众号