Created
December 21, 2017 07:31
-
-
Save pbrocks/ef7273d2ff8d89161e4f82ccd8a3564e to your computer and use it in GitHub Desktop.
Redirect away from PMPro subsite
This file contains hidden or 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 | |
/** | |
* Plugin Name: PMPro Customizations | |
*/ | |
add_action( 'template_redirect', 'redirect_away_from_site_two' ); | |
function redirect_away_from_site_two() { | |
global $current_user; | |
// Administrators are unaffected by the redirection. | |
if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { | |
return; | |
} | |
$blog_id = get_current_blog_id(); | |
// Set the location of the redirection. | |
$location = network_site_url(); | |
// Redirect visitors away. | |
if ( ! is_user_logged_in() && 2 === $blog_id ) { | |
wp_safe_redirect( $location ); | |
exit; | |
} | |
// Redirect members away from site 2 if not in level 2. | |
if ( is_user_logged_in() ) { | |
$level = pmpro_getMembershipLevelForUser( $current_user->ID ); | |
if ( 2 === $blog_id && ! in_array( $level->id, array( 2 ) ) ) { | |
wp_safe_redirect( $location ); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment