经过一点思考,我想出了一个允许wp登录的解决方案。php将为公众/客户重定向,但不为管理员重定向。我通过获取推荐人的URL来实现这一点。这是我的更新代码,但我对其他想法持开放态度。
//Redirect for login from wp-login.php to my-account if not admin
add_action(\'init\', \'prevent_wp_login\');
function prevent_wp_login() {
// WP tracks the current page - global the variable to access it
global $pagenow;
// Check if a $_GET[\'action\'] is set, and if so, load it into $action variable
$action = (isset($_GET[\'action\'])) ? $_GET[\'action\'] : \'\';
//check if we came from the admin page or wp-admin
$refer = urlencode($_SERVER["REQUEST_URI"]);
if (strpos($refer, \'wp-admin\') !== false) {
// stay on wp-login.php
} else {
// Check if we\'re on the login page, and ensure the action is not \'logout\'
if( $pagenow == \'wp-login.php\' && ( ! $action || ( $action && ! in_array($action, array(\'logout\', \'lostpassword\', \'rp\', \'resetpass\'))))) {
// Load the home page url
// Redirect to the home page
wp_redirect(\'/my-account/\');
// Stop execution to prevent the page loading for any reason
exit();
}
}
}