WordPress.org

Ready to get started?Download WordPress

Forums

Active Directory Integration
[resolved] It's working great, but is it causing problems with roles and capabilities? (4 posts)

  1. gpspake
    Member
    Posted 1 year ago #

    So here's the issue we're having, and we aren't quite sure if it's the plugin that's causing it...

    I have added a function to functions.php to redirect users to posts-new.php after login and it works. However, I only want this to happen if the user logging in is a contributor. So I added the following:

    /** Redirect after login */
        function mysite_login_redirect(){
            if ( current_user_can( 'manage_options' ) ) {
               return 'http://mysite.com/wp-admin/index.php';}
            else {
               return 'http://mysite.com/wp-admin/post-new.php';}
        }
    add_action( 'login_redirect', 'mysite_login_redirect');

    In this state, both contributors and admins are redirected to post-new.php. To test it I modified the function so that users without the capability would be redirected:

    if ( !current_user_can( 'ma ...

    when I modified the function, both contributors and admins are redirected to index.php.

    So the function seems to work but this implies to me that it's not seeing the 'manage_options' capability for admins. I've tried several admin-exclusive capabilities with the same results. Weird huh?

    The function doesn't work correctly and the problem seems to be that neither roles nor capabilities are being recognized by the function correctly. If I set current_user_has() to an administrator specific role, or just 'administrator', it should use the 'if' url if I log in as an admin, and the 'else' url if I log in as a contributor. Either way, whether I set the function to 'current_user_can' or '!current_user_can', the administrator login and the contributor login behave the same as if the capabilities are not any different.

    Is this because the plugin is affecting capabilities?

    http://wordpress.org/extend/plugins/active-directory-integration/

  2. gpspake
    Member
    Posted 1 year ago #

    Ok, so I wasn't going about this correctly. Here is the proper way to redirect users after login based on their roles. http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

  3. glatze
    Member
    Plugin Author

    Posted 1 year ago #

    Yup, this is not an ADI issue.

  4. gpspake
    Member
    Posted 1 year ago #

    Sorry, should have resolved this. ADI is working great! Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic