• Resolved shyton

    (@shyton)


    Hi can you please help me with this code ,I’m using a theme that doesn’t allow me to restrict access to some pages using your plugin so can you help me deny access using this code bellow

    add_action( ‘template_redirect’, ‘role_based_redirect’ );
    function role_based_redirect() {
    if( is_page( array( 1488, 2413, 2379, 2265, 2396, 2370, 2366, 4600 ) ) ) { //check the list of “corporate” pages
    $user = wp_get_current_user();
    $valid_roles = [ ‘administrator’, ‘corporate’, ‘editor’ ];

    $the_roles = array_intersect( $valid_roles, $user->roles );

    // The current user does not have any of the ‘valid’ roles.
    if ( empty( $the_roles ) ) {
    wp_redirect( home_url( ‘/access-denied/’ ) );
    exit;
    }
    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter shyton

    (@shyton)

    here is another one I found but this one blocks all pages ,,can you make it so that it doesn’t block the home page

    /* 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() );
        }
      }
    }
    Plugin Author Andrew Lima

    (@andrewza)

    Hi @shyton

    Thank you for reaching out to Paid Memberships Pro, the code provided looks correct to me after glancing over it.

    Regarding your second code snippet, you may add the if( is_page( array(1,2,3) ) from your first code snippet to only run on certain pages.

    Our support doesn’t cover custom development, I recommend reaching out to a local WordPress developer or posting to jobs.wordpress.net

    I hope this helps get you started.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Subscription not working on some pages’ is closed to new replies.