• Resolved tkempcc

    (@tkempcc)


    So to start, I love this plugin. It works perfect for what we need.

    The problem I’m having though is that when I have other users with lower permissions attempt to login, they don’t go to the WP Dashboard. It goes to a Directorlist submission page.

    I thought maybe this was a conflict with another plugin, so I removed all other plugins, re-installed directorlist, and am having the same issue.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Great to know that you loved the plugin and working perfectly for you.

    Directorist allows only administrator to redirect to the WP Dashboard after successful login. We have a plan to add an option giving the control on this. For the time being, you can use the code below editing $my_users = array(‘administrator’,’editor’). You just have to add the role the way showed in comma separated quotation. Please place the code in your child theme’s functions.php file.

    function redirect_non_admin_to_dashboard($redirect_to, $requested_redirect_to, $user ) {
        global $user;
        if( ! isset( $user->ID ) ) {
            return $redirect_to;
        }
        if( !class_exists('Directorist_Base') ) {
            return $redirect_to;
        }
        $my_users = array('administrator','editor');
        if ( ! array_intersect( apply_filters('atbdp_login_redirect_to_wp_dashboard', $my_users), (array) $user->roles ) ) {
            $redirect_to  = ATBDP_Permalink::get_dashboard_page_link();
        }else{
            $redirect_to = admin_url();
        }
        return wp_validate_redirect( $redirect_to, home_url() ); // return a safe redirect url between the site.
    }
    Thread Starter tkempcc

    (@tkempcc)

    I’ve tried to implement this code, after installing the development version of the plugin, but it just seems to crash my site, getting the error:

    The site is experiencing technical difficulties.

    On my dashboard and home page. I had to delete the code to return it all.

    Thread Starter tkempcc

    (@tkempcc)

    Okay, I’ve got it to not error, but my re-directs still don’t take me back to the wp dashboard outside the admin.

    Oh! Missed the last part of the code at the time of copying it which is

    add_filter( 'login_redirect', 'redirect_non_admin_to_dashboard', 10, 3 );

    Full code

    function redirect_non_admin_to_dashboard($redirect_to, $requested_redirect_to, $user ) {
        global $user;
        if( ! isset( $user->ID ) ) {
            return $redirect_to;
        }
        if( !class_exists('Directorist_Base') ) {
            return $redirect_to;
        }
        $my_users = array('administrator','editor');
        if ( ! array_intersect( apply_filters('atbdp_login_redirect_to_wp_dashboard', $my_users), (array) $user->roles ) ) {
            $redirect_to  = ATBDP_Permalink::get_dashboard_page_link();
        }else{
            $redirect_to = admin_url();
        }
        return wp_validate_redirect( $redirect_to, home_url() ); // return a safe redirect url between the site.
    }
    
    add_filter( 'login_redirect', 'redirect_non_admin_to_dashboard', 10, 3 );
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Login Redirect’ is closed to new replies.