WC_Admin::prevent_admin_access()
Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin.
Метод класса: WC_Admin{}
Возвращает
null
. Ничего (null).
Использование
$WC_Admin = new WC_Admin(); $WC_Admin->prevent_admin_access();
Код WC_Admin::prevent_admin_access() WC Admin::prevent admin access WC 9.4.2
public function prevent_admin_access() { $prevent_access = false; // Do not interfere with admin-post or admin-ajax requests. $exempted_paths = array( 'admin-post.php', 'admin-ajax.php' ); if ( /** * This filter is documented in ../wc-user-functions.php * * @since 3.6.0 */ apply_filters( 'woocommerce_disable_admin_bar', true ) && isset( $_SERVER['SCRIPT_FILENAME'] ) && ! in_array( basename( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ), $exempted_paths, true ) ) { $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; } }