我正试图限制内容的使用。我需要实现的是,一旦用户注销,他们将无法在接下来的24小时内登录。或者,如果那不可行,我该怎么做,用户只能在24小时内登录一次?使用WordPress
答案 0 :(得分:0)
您可以通过为配置文件添加一个last_login_timestamp
的自定义字段来解决这种情况(即,当用户注册时)。基本上,每当用户注销时,您都可以使用wp_logout
挂钩来更新此自定义字段。像
function slug_update_user_last_login_hook() {
if(! is_admin()) { // obviously not for admin
// logic to update custom form field for user
}
}
add_action('wp_logout', 'slug_update_user_last_login_hook');
当用户登录时,您可以检查上次登录时间是否小于或等于24小时。
function slug_24_hour_login_check() {
if(! is_admin()) { // obviously not for admin
//compare the the time of custom form field of logged in user's id
//if not you can logout user and redirect to another page using wp_redirect
wp_redirect( $url_of_24_hour_login_notice );
}
}
add_action('wp_login', 'slug_24_hour_login_check');
让我知道它是如何工作的。