• Resolved ameratech

    (@ameratech)


    Hi. Building a site with pages reserved for logged in users. Is there a way to redirect blocked users to another (login) page? Currently I can only see an option to display a text message which you can edit in settings.

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

    (@caseproof)

    Hi @ameratech

    To redirect users to different page, you can use this code snippet and add it at the end of your theme’s functions.php file:

    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('contact') && ( ! is_user_logged_in() || ( ! empty($user) && in_array( 'author', (array) $user->roles ) ) ) ) {
        $redirect = 'https://your-domain.com/unauthorized'; // Change this to the correct URL
        wp_redirect( $redirect );
        exit;
      }
    } );

    Hopefully, that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Blocked user redirect’ is closed to new replies.