Forked from kimcoleman/my_template_redirect_require_membership_access.php
Last active
September 8, 2021 07:49
-
-
Save andrewlimaza/8d6a332eaa9ed14949b5720094f29113 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.
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 | |
/* | |
* 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() || pmpro_hasMembershipLevel( array( '1' ) ) ) ) { | |
wp_redirect( pmpro_url( 'levels' ) ); | |
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