简体   繁体   English

在自定义登录和注册页面上重定向用户,默认情况下仅允许管理员登录wp-login.php

[英]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: 我只能想到一些不太好的解决方案:

  1. If your admin(s) have a static IP, or static IPs, you could switch based on that. 如果您的管理员有一个或多个静态IP,则可以基于该IP进行切换。 Of course, this won't work if an admin tries to log in from Mom's house or from a coffee shop. 当然,如果管理员尝试从妈妈家或咖啡店登录,则此方法将无效。
  2. You could set some very long term cookie (not any cookie used by WordPress) that marks a user as an admin and switch on that. 您可以设置一些非常长期的cookie(而不是WordPress使用的任何cookie),以将用户标记为管理员,然后将其打开。 This, of course, only works for users who are on computers that have the cookie set. 当然,这仅适用于已设置Cookie的计算机上的用户。
  3. You could create two custom login pages-- user-login.php and admin-login.php -- and never publish the later publicly. 您可以创建两个自定义登录页面-user user-login.phpadmin-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.

相关问题 如何将wordpress的默认登录页面从wp-login.php更改为自定义登录页面? - how to change the default login page of wordpress from wp-login.php to custom login page? 无法登录 wp-admin(重定向到主页),但可以登录 wp-login.php - Cant login to wp-admin (redirecting to homepage), But CAN login to wp-login.php WP-login.php重定向到错误的URL - WP-login.php is Redirecting to the wrong URL 在wp-login.php页面的页脚中包含自定义javascript - Include custom javascript in the footer of wp-login.php page WordPress-/ wp-admin /登录后重定向到/wp-login.php - Wordpress - /wp-admin/ redirecting to /wp-login.php, when logged-in 停止WooCommerce将wp-login.php和wp-admin重定向到帐户页面 - Stop WooCommerce redirecting wp-login.php and wp-admin to account pages Wordpress模式登录,无需重定向到wp-login.php页面 - Wordpress modal login without redirect to wp-login.php page wp_login_form()重定向到wp-login.php,即使登录凭据正确 - wp_login_form() redirecting to wp-login.php eventhough login crediantials are correct 如何在Wordpress中将/ wp-admin页面重定向到另一个页面(不是wp-login.php)? - How to redirect /wp-admin page to another page (not wp-login.php) in wordpress? 自定义 wp-login.php 登录标题 - Customize wp-login.php Login Title
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM