My Account

Forums

Forums General Role-based redirection after Login

Viewing 4 reply threads
  • Author
    Posts
    • #49296
      eugenek
      Participant

      Hello.

      Is there a simple solution on a role-based redirection after successful log in submission?

      Many thanks,
      Eugene

      P.S. Thanks very much for creating How To Redirect Existing Users By Role solution following my earlier enquiry 🙂

    • #49298
      Mark Westguard
      Keymaster

      Hi Eugene

      The knowledge base you reference above is how you can achieve this.

      While our conditional logic is extensive, post form processing based upon user criteria needs to be handle by a WordPress hook. Our conditional logic primarily deals with pre-post events.

      Thanks

      Mark

    • #49299
      eugenek
      Participant

      Thanks Mark,

      Looking at your example given in How To Redirect Existing Users By Role:

      1) How do you reference a particular (Login) form? It looks like this widget would apply to all forms.
      2) How do you include multiple redirections for multiple roles?

      Many thanks.

      Eugene

    • #49303
      eugenek
      Participant

      For multiple redirection, I suppose the following code would apply:

          $admin_redirect_url = '/redirect-admin/';
          $author_redirect_url = '/redirect-author/';
          $subscriber_redirect_url = '/redirect-subscriber/';
          // etcetera
      
                  // Check user role
                  if( in_array( 'administrator', $user->roles ) ) {
                      $field_error_action_array[] = array(
                          'action' => 'redirect',
                          'url' => $admin_redirect_url
                      );
                  }
      
                  if( in_array( 'author', $user->roles ) ) {
                      $field_error_action_array[] = array(
                          'action' => 'redirect',
                          'url' => $author_redirect_url
      
                  }
      
                  if( in_array( 'subscriber', $user->roles ) ) {
                      $field_error_action_array[] = array(
                          'action' => 'redirect',
                          'url' => $subscriber_redirect_url
                      );
                  }

      am I correct?

    • #49304
      Mark Westguard
      Keymaster

      Yes that code looks correct. You do not need to reference a particular login form, each field ID in WS Form is unique and associated to a single form. You just need to change the field ID in the code sample we provide in the knowledge base article.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.

Login