如何使用PHP在WordPress中使用其ID获取所有用户状态(登录或注销)的列表



//我想使用php

在//wordpress中显示所选用户ID的状态(登录或注销(
 <?php 
/**
 * Capture user login and add it as timestamp in user meta data
 *
 */
function user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', 'user_last_login', 10, 2 );

/** *显示最后登录时间 * */

function wpb_lastlogin() 
 { 
    $last_login = get_the_author_meta('last_login');
    $the_login_date = human_time_diff($last_login);
    return $the_login_date; 
 } 
 /**
 * Add Shortcode lastlogin 
 *
 */
 add_shortcode('lastlogin','wpb_lastlogin');
?>
//i want this kind of code for all users

一旦登录用户,您试图拥有用户集的元值的方法非常好。

您必须将该值重置为一个用户注销后将其重置为null。

现在,您可以查找该元数据的值并显示"登录",如果用户元具有您设置的一个值,如果没有设置的值,则显示"登录"。

此外,您可以检查用户最后登录时间的差异超过5分钟未更新,因为某个时间用户未注销并直接关闭站点。

最新更新