Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/dd4fe4a29d0f643b44fb to your computer and use it in GitHub Desktop.
Save greathmaster/dd4fe4a29d0f643b44fb to your computer and use it in GitHub Desktop.
Redirect away from the level page if you don't have a required level with Paid Memberships Pro.
/*
Redirect away from the level page if you don't have membership
*/
function my_template_redirect_upgrade()
{
global $pmpro_pages, $pmpro_level;
if(empty($pmpro_pages))
return;
$member_level = pmpro_getMembershipLevelForUser();
if(is_page($pmpro_pages['levels']) && pmpro_hasMembershipLevel() && !pmpro_isLevelExpiringSoon($member_level->ID))
{
wp_redirect(site_url()); //change redirect url here
exit;
}
}
add_action('template_redirect', 'my_template_redirect_upgrade');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment