Skip to content

Instantly share code, notes, and snippets.

@filipvanreeth
Created October 2, 2017 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipvanreeth/b6a4466ccc93c150e0cd505525d897f4 to your computer and use it in GitHub Desktop.
Save filipvanreeth/b6a4466ccc93c150e0cd505525d897f4 to your computer and use it in GitHub Desktop.
Remove admin menu pages with 5 lines of code
function disable_admin_menu_pages() {
// Check if the plugin exists and is active
if ( class_exists( 'Woocommerce' ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
// Set a user capability to disable the menu pages. In this case the menu pages will be removed for all users who don't have the 'manage_options' capability.
if ( ! current_user_can( 'manage_options' ) ) {
remove_menu_page( 'woocommerce' ); // Remove the WooCommerce menu page
remove_menu_page( 'edit.php?post_type=product' ); // Remove the products menu page.
}
}
}
// Action Hook
add_action( 'admin_menu', 'disable_admin_menu_pages' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment