WC_Admin::prevent_admin_access()
Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin.
Method of the class: WC_Admin{}
Hooks from the method
Return
null
. Nothing.
Usage
$WC_Admin = new WC_Admin(); $WC_Admin->prevent_admin_access();
WC_Admin::prevent_admin_access() WC Admin::prevent admin access code WC 7.5.1
public function prevent_admin_access() { $prevent_access = false; if ( apply_filters( 'woocommerce_disable_admin_bar', true ) && ! wp_doing_ajax() && isset( $_SERVER['SCRIPT_FILENAME'] ) && basename( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) !== 'admin-post.php' ) { $has_cap = false; $access_caps = array( 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' ); foreach ( $access_caps as $access_cap ) { if ( current_user_can( $access_cap ) ) { $has_cap = true; break; } } if ( ! $has_cap ) { $prevent_access = true; } } if ( apply_filters( 'woocommerce_prevent_admin_access', $prevent_access ) ) { wp_safe_redirect( wc_get_page_permalink( 'myaccount' ) ); exit; } }