Created
October 2, 2017 05:29
-
-
Save filipvanreeth/b6a4466ccc93c150e0cd505525d897f4 to your computer and use it in GitHub Desktop.
Remove admin menu pages with 5 lines of code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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