• Resolved designbysue

    (@designbysue)


    I have set up a roll specifically for committee members and have a roll called committee. I have set up a page that I want accessible only to committee members and have selected Limit access to the content to users of the selected roles as this committee role. I have set up the error message there to give a link to log in. When the user logs in from the log in (currently using the built in log in page from wordpress) the user is then taken to the wordpress dashboard for that user. I need this to go directly to the page the user was trying to access. And to make it more complicated, if the user enters the page address and goes to it they get the error message and the only way to access the page is to refresh the page – then they get access to it.

    I know this sounds confusing but what I need is a way for the user to log in and be immediately taken to the protected page where they are automatically able to view the page.

    What am I doing wrong?? Any quick reply will be gratefully appreciated as I have been working on this for about 2 weeks and really need to get this done.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi @designbysue

    To redirect users with specific role to one particular page after login, you could try to use this code snippet:

    function members_login_redirect_roles($user_login, $user) {
      if( in_array( 'committee',$user->roles ) ){
        exit( wp_redirect('Your page link goes here' ) );
      }   
    }
    add_action( 'wp_login', 'members_login_redirect_roles', 10, 2);

    Hopefully, that helps.

    Thread Starter designbysue

    (@designbysue)

    I must have something wrong as even with the code as below the user is taken to his profile. Can you see what I might be missing – thanks this is exactly what I need to do so I hope I can work this out. (I put this in the functions.php in the child theme – is that correct?

    function members_login_redirect_roles($user_login, $user) {
    if( in_array( ‘Committee’,$user->roles ) ){
    exit( wp_redirect(‘https://loxalucieheadwaters.org/committee-page/’ ) );
    }
    }
    add_action( ‘wp_login’, ‘members_login_redirect_roles’, 10, 2);

    Thread Starter designbysue

    (@designbysue)

    Thanks again for your help – and it really helped even though I could not make the code work because it gave me something to search for. I found a plugin that works perfectly – LoginWP in case others have this issue.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Content Permissions’ is closed to new replies.