您的位置 首页 技术

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 。

以上就是WordPress前台如何显示登录用户的最后登录时间的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/13483.html

为您推荐

返回顶部