Last active
May 29, 2020 21:24
-
-
Save MaryOJob/32d64c7754be1dd95aec0a89d31b860c to your computer and use it in GitHub Desktop.
Redirect all WP User roles except Subscribers to Home Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // DO NOT COPY THIS LINE | |
/** | |
* Redirect all non-subscriber users' after they login to your website's home page. | |
* Documentation for login_redirect filter - https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect | |
*/ | |
function pmpro_redirect_after_login( $redirect_to, $request, $user ) { | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
//check if user is not a subscriber. | |
if ( !in_array( 'subscriber', $user->roles ) ) { | |
$redirect_to = home_url(); | |
} | |
} | |
return $redirect_to; | |
} | |
add_filter( 'login_redirect', 'pmpro_redirect_after_login', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment