Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kimcoleman/be5429f52732dc0d56380cdd4da41636 to your computer and use it in GitHub Desktop.
Save kimcoleman/be5429f52732dc0d56380cdd4da41636 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.
<?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() ) {
wp_redirect( pmpro_url( 'levels' ) );
exit;
}
}
add_action( 'template_redirect', 'my_template_redirect_require_membership_access' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Redirect Non-members Away from Member Content" at Paid Memberships Pro here: https://www.paidmembershipspro.com/redirect-non-members-away-from-member-content/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment