Forked from kimcoleman/my_template_redirect_require_membership_access.php
Last active
January 17, 2020 02:36
-
-
Save ipokkel/6ac86a119fa70e05efee9c2cb062c787 to your computer and use it in GitHub Desktop.
Redirects members-only content to the Membership Levels page if a user is logged out or not a member in a multisite network using the PMPro Multisite Membership Add On.
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 | |
/* | |
* Redirects members-only content to the Membership Levels page if a user is logged out or not a member. | |
*/ | |
function my_template_redirect_require_membership_access() { | |
if ( function_exists( 'pmpro_has_membership_access' ) && ! pmpro_has_membership_access() ) { | |
if ( ! is_multisite() && ! function_exists( 'pmpro_multisite_membership_init' ) ) { | |
wp_safe_redirect( pmpro_url( 'levels' ) ); | |
exit; | |
} else { | |
wp_safe_redirect( get_blog_permalink( get_current_site()->id, get_blog_option( get_current_site()->id, 'pmpro_levels_page_id' ) ) ); | |
exit; | |
} | |
} | |
} | |
add_action( 'template_redirect', 'my_template_redirect_require_membership_access' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment