你可以利用login_redirect 滤器
文档中的示例与您的问题非常相似:
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user\'s data.
* @return string
*/
function wpse306427_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if (isset($user->roles) && is_array($user->roles)) {
//check for subscribers
if (in_array(\'subscriber\', $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = home_url();
}
}
return $redirect_to;
}
add_filter( \'login_redirect\', \'wpse306427_login_redirect\', 10, 3 );
您可以将此代码放在插件或主题函数中。php。