这是一个剪下来的。确保在用户登录后运行此代码
//To get logged in user information
$user = wp_get_current_user();
//Condition to check weather user is subscriber or not
if ( in_array( \'subscriber\', (array) $user->roles ) ) {
//The user has the "subscriber" role
}else{
// redirect user to different section and end their session
wp_logout(); // user is logged out
wp_redirect( home_url( \'/\' ) ); // user is redirected to home page
}
一定要让我知道这对你是否有用