[英]Redirecting users on a custom login & registration page and allowing only admin to login by default wp-login.php
I want users to register & login only by custom pages not by default pages, instead only admin can login by the default wp-login.php 我希望用户仅通过自定义页面进行注册和登录,而不能通过默认页面进行注册,而是仅管理员可以通过默认wp-login.php登录
I found this .. but it is redirecting login & register both on same page. 我发现了这个..但它正在重定向登录并在同一页面上同时注册。 google.com in this case. 在这种情况下为google.com。
add_action('init','possibly_redirect');
function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
wp_redirect('http://google.com/');
exit();
}
}
I hate to post "you can't do that answers" because it is very easy to go wrong, but generally speaking you can't do this. 我不喜欢发布“您无法做到这一点的答案”,因为它很容易出错,但总的来说您不能这样做。 Until someone logs in, WordPress doesn't know if that person is an admin or not. 在某人登录之前,WordPress不会知道该人是否是管理员。 How are you going to toggle based on information that is not available? 您将如何根据不可用的信息进行切换?
There are only a few of not very good solutions I can think of: 我只能想到一些不太好的解决方案:
user-login.php
and admin-login.php
-- and never publish the later publicly. 您可以创建两个自定义登录页面-user user-login.php
和admin-login.php
并且永远不会公开发布后者。 You'd then redirect all logins to user-login.php
except for attempts to get to admin-login.php
, which presumably only your admins know about. 然后,您将所有登录重定向到user-login.php
除了尝试访问admin-login.php
,这大概只有您的管理员知道。 That is really just obfuscation but maybe that will work for you. 那实际上只是混淆,但也许对您有用。 Either solution is going to be unstable and work sometimes but not others. 两种解决方案都不稳定,有时可以工作,而其他解决方案则无法。
Redirecting users to some particular page after login is pretty easy. 登录后将用户重定向到某个特定页面非常容易。 The hard part is using different login pages for users before they log in. 困难的部分是在用户登录之前使用不同的登录页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.