Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/6ac86a119fa70e05efee9c2cb062c787 to your computer and use it in GitHub Desktop.
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.
<?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