I have this code in WordPress custom plugin I'm writing:
public function __construct()
{
add_action( 'admin_menu', array($this, 'hide_default_menu_pages') );
}
public function hide_default_menu_pages()
{
$restricted_users = array(
'USERONE',
'USERTWO',
);
// Getting the current user
$current_user = wp_get_current_user();
// Getting the current user registered username
$username = get_the_author_meta( 'nickname', $current_user->ID );
// Checking into the $restricted_users if the current logged user is blacklisted
if( in_array( $username, $restricted_users ) ){
remove_menu_page( 'themes.php' );
remove_menu_page( 'plugins.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'tools.php' );
remove_menu_page( 'options-general.php' );
remove_menu_page( 'edit.php' );
remove_menu_page( 'upload.php' );
remove_menu_page( 'wc-admin' );
}
}
I want to remove for some users the ability to see the woocommerce pages and elementor pages, but the remove_menu_page() function seems not working, I think this will occur because the plugin pages don't really have a slug like the core pages of wordpress but use a querystring like this admin.php?page=wc-admin and admin.php?page=elementor. How I can achive the desired result?
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand