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.
}
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.
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 );