With a plain-vanilla Wordpress install, a subscriber can access /wp-login.php, login and visit the dashboard.
I've found that after installing WooCommerce, if a subscriber is logged in and then tries to revisit the wp-admin or wp-login.php they are redirected to the my-account page set in the WooCommerce settings.
I wondered if there is anyway to remove this functionality as it isn't right for my site.
Any thoughts much appreciated.
Solution
I have found a solution and posted it on this related question
Here a way to achieve that for the "subscriber" user role:
// Conditional function code for 'subscriber' User Role
function is_subscriber_user(){
if( current_user_can('subscriber') ) return true;
else return false;
}
// Redirect 'subscriber' User Role to the User edit prodile on WooCommerce's My Account
// So when he get looged or it register too
add_filter('template_redirect', 'wp_subscriber_my_account_redirect' );
function wp_subscriber_my_account_redirect() {
if( is_subscriber_user() && is_account_page() )
wp_redirect( get_edit_profile_url( get_current_user_id() ) );
}
// Prevent automatic woocommerce redirection for 'subscriber' User Role
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', 'wc_subscriber_auto_redirect', 20, 1 );
function wc_subscriber_auto_redirect( $boolean ) {
if( is_subscriber_user() )
$prevent_access = true;
return $boolean;
}
// Allow 'subscriber' User Role to view the Dashboard
add_filter( 'woocommerce_prevent_admin_access', 'wc_subscriber_admin_access', 20, 1 );
function wc_subscriber_admin_access( $prevent_access ) {
if( is_subscriber_user() )
$prevent_access = false;
return $prevent_access;
}
// Show admin bar for 'subscriber' User Role
add_filter( 'show_admin_bar', 'wc_subscriber_show_admin_bar', 20, 1 );
function wc_subscriber_show_admin_bar( $show ) {
if ( is_subscriber_user() )
$show = true;
return $show;
}
Code goes in function.php file of the active child theme (or active theme).
Tested and works.
If you want the "subscriber" user to be redirected to the dashboard instead of the edit profile, you just have to replace
get_edit_profile_url()
function byget dashboard url()
…