回答
用户特定的内容是一个伟大的插件,顺利允许您通过角色或用户名指定的个人或用户组,并让他们访问特定内容。
更新: 您可以使用彼得登录重定向定义一组针对特定用户,用户与特定的角色,用户具有特定的功能重定向规则,以及所有其他用户的毯子规则。另外,请为注册后设置重定向网址。
重定向在第一次登录的用户在WordPress
在会员制的WordPress网站和要显示一个特殊的欢迎信息或新的用户指令的其他网站,你可以实现一些自定义登录重定向功能。该功能只会为每个用户启动一次(或前几次登录)。
这些功能的代码端的重要元素是使用内置的WordPress“login_redirect”过滤器,并存储有关用户是否已获得“第一次登录”处理的信息。有几种可能的方法来存储信息,无论是在cookie中还是在用户的元信息中(存储在“wp_usermeta”表中的WordPress数据库中)。
下面是一些示例代码,您可以在主题functions.php文件或插件使用方法:
基于Cookie的解决方案
// Send new users to a special page
function redirectOnFirstLogin($redirect_to, $requested_redirect_to, $user)
{
// URL to redirect to
$redirect_url = 'http://yoursite.com/firstloginpage';
// How many times to redirect the user
$num_redirects = 1;
// Cookie-based solution: captures users who registered within the last n hours
// The reason to set it as "last n hours" is so that if a user clears their cookies or logs in with a different browser,
// they don't get this same redirect treatment long after they're already a registered user
// 172800 seconds = 48 hours
$message_period = 172800;
// If they're on the login page, don't do anything
if(!isset($user->user_login))
{
return $redirect_to;
}
$key_name = 'redirect_on_first_login_' . $user->ID;
if(strtotime($user->user_registered) > (time() - $message_period)
&& (!isset($_COOKIE[$key_name]) || intval($_COOKIE[$key_name]) < $num_redirects)
)
{
if(isset($_COOKIE[$key_name]))
{
$num_redirects = intval($_COOKIE[$key_name]) + 1;
}
setcookie($key_name, $num_redirects, time() + $message_period, COOKIEPATH, COOKIE_DOMAIN);
return $redirect_url;
}
else
{
return $redirect_to;
}
}
add_filter('login_redirect', 'redirectOnFirstLogin', 10, 3);
Download the cookie-based redirect on first login plugin
基于用户元表的解决方案
// Send new users to a special page
function redirectOnFirstLogin($redirect_to, $requested_redirect_to, $user)
{
// URL to redirect to
$redirect_url = 'http://yoursite.com/firstloginpage';
// How many times to redirect the user
$num_redirects = 1;
// If implementing this on an existing site, this is here so that existing users don't suddenly get the "first login" treatment
// On a new site, you might remove this setting and the associated check
// Alternative approach: run a script to assign the "already redirected" property to all existing users
// Alternative approach: use a date-based check so that all registered users before a certain date are ignored
// 172800 seconds = 48 hours
$message_period = 172800;
// If they're on the login page, don't do anything
if(!isset($user->user_login))
{
return $redirect_to;
}
$key_name = 'redirect_on_first_login';
// Third parameter ensures that the result is a string
$current_redirect_value = get_user_meta($user->ID, $key_name, true);
if(strtotime($user->user_registered) > (time() - $message_period)
&& ('' == $current_redirect_value || intval($current_redirect_value) < $num_redirects)
)
{
if('' != $current_redirect_value)
{
$num_redirects = intval($current_redirect_value) + 1;
}
update_user_meta($user->ID, $key_name, $num_redirects);
return $redirect_url;
}
else
{
return $redirect_to;
}
}
add_filter('login_redirect', 'redirectOnFirstLogin', 10, 3);
非常感谢你的帮助,我真的很感激。 如何在管理中将一个页面分配给用户。 –
我想为每个用户创建私人页面。该页面的内容仅在登录后才由页面的所有者在前端访问。 –
它比使用自己的插件更适合使用插件。检查此链接https://wploop.com/specify-users-name-role-show-exclusive-content/ – EniGma
- 1. Rails/Devise如何在登录后重定向到特定页面
- 2. 如何在laravel登录后重定向特定页面
- 3. 如何在页面刷新后重定向到登录页面
- 4. 如何在wordpress完成表格后重定向登录页面
- 5. 如何在登录后重定向WordPress
- 6. Sitefinity 4登录后重定向到特定页面
- 7. 登录后重定向到特定页面
- 8. WordPress的登录页面重定向到“找不到网页”
- 9. 如何在Facebook登录后使用javascript重定向到页面?
- 10. 如何在登录后重定向到Routing.prefixes页面?
- 11. 如何在登录后重定向到同一页面
- 12. 如何在jsp登录后重定向到同一页面?
- 13. 重定向到特定页面,如果没有登录 - .htaccess
- 14. 如何重定向到登录页面,然后再返回在WordPress
- 15. 在Wordpress注册后重定向到特定页面
- 16. 用户登录后页面重定向
- 17. 登录页面重定向
- 18. 重定向到IFrame的登录页面
- 19. 成功登录后不断重定向到登录页面
- 20. Magento成功登录后重定向到登录页面
- 21. 重定向后,登录定制登录页面WP
- 22. Facebook登录:如何登录后重定向到一个特定的URL在
- 23. 成功登录后如何重定向到页面?
- 24. 在laravel重置密码后重定向到登录页面
- 25. 重定向HTTP到HTTPS,不重定向到登录页面
- 26. LightOpenId不重定向到登录页面
- 27. 重定向到https登录页面
- 28. 重定向到登录页面/彩盒
- 29. asp.net重定向到登录页面
- 30. 重定向到登录页面
检查此https://stackoverflow.com/questions/4267285/redirect-user-after-first-login-in-wordpress?rq=1 – EniGma