Skip to content

Instantly share code, notes, and snippets.

@seventhqueen
Last active November 18, 2020 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seventhqueen/5195ee620b9c82f10e34d2b4623d64ae to your computer and use it in GitHub Desktop.
Save seventhqueen/5195ee620b9c82f10e34d2b4623d64ae to your computer and use it in GitHub Desktop.
Restrict users access to whole site and force them to Paid memberships Pro levels page
<?php
/* Redirect user to levels page until he subscribes for a membership */
add_action( 'template_redirect', 'sq_membership_restrict' );
function sq_membership_restrict() {
global $pmpro_pages, $post;
if ( is_user_logged_in() && ! pmpro_hasMembershipLevel() ) {
if (isset( $post->ID ) && ! in_array( $post->ID, $pmpro_pages )) {
wp_redirect( pmpro_url() );
}
}
}
@zup44
Copy link

zup44 commented Jan 9, 2020

Hello,
Your code is very practical !!

I'm new to PHP and I'm just trying to block a page by id to the non-connected (idenfiant 1 and 2 authorized to see the content) and force them to access the page of the paid subscription levels Pro. I think your rib should be a lead for my problem ?? Or if not can you explain to me how?

thank you in advance
Nico

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