Skip to content

Instantly share code, notes, and snippets.

@Garconis
Last active May 22, 2023 03:07
Show Gist options
  • Save Garconis/3674f897893589f55ab6e17e3a0dd605 to your computer and use it in GitHub Desktop.
Save Garconis/3674f897893589f55ab6e17e3a0dd605 to your computer and use it in GitHub Desktop.
WooCommerce | Remove the Extensions menu item from all users except for ones with a certain email address
<?php
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('admin_menu', 'fs_remove_admin_menu_links', 999);
function fs_remove_admin_menu_links() {
// get current User
$user = wp_get_current_user();
// get their email address
$email = $user->user_email;
// check the email's domain
$domain = 'yourdomain.com';
// check if email address matches domain list
$banned = strpos($email, $domain) === false;
// if current user's email addess doesn't match domain list, then hide the menu items
if( $user && $banned ) {
remove_submenu_page('woocommerce', 'wc-addons');
}
}
}
@joelcrump
Copy link

Thanks this is just what I was looking for, this should really be an option in Woocommerce as it's annoying building sites for multiple clients that can see and download any plugins you have a licence for! Thanks again! I put this in the must use plugins too stop people from deactivating it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment