• Resolved stellasidus

    (@stellasidus)


    Hello,

    I would like to make a page (of a product) inaccessible for a role called Professional and make it accessible for the rest of the people including people without an account.
    Is this possible?

Viewing 1 replies (of 1 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi @stellasidus

    To protect one of the page/product, you could use the following code snippet and adjust it:

    add_action( 'template_redirect', function() {
      // Redirect users from specific page 
      // when user doesn't have particular role 
      $user = wp_get_current_user();
      if ( is_page( array('product-page')) && ( ! is_user_logged_in() || ( ! empty($user) && in_array( 'professional', (array) $user->roles ) ) ) ) {
        $redirect = 'https://your-domain.com/wp-login.php'; // Change this to the correct URL
        wp_redirect( $redirect );
        exit;
      }
    } );

    I’m not sure if is_page will work in your case, so you might use different conditions.

    I hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Rectristion and Guest account’ is closed to new replies.