Skip to content

Instantly share code, notes, and snippets.

@tonydjukic
Created November 6, 2017 18:46
Show Gist options
  • Save tonydjukic/881b0cf9a647a88ec235268a7cdb3afc to your computer and use it in GitHub Desktop.
Save tonydjukic/881b0cf9a647a88ec235268a7cdb3afc to your computer and use it in GitHub Desktop.
Hide Automattic's Poll Daddy plugin's menu items from a specific user role. Using the normal remove_menu_page() and remove_submenu_page() doesn't work in this instance and I couldn't find a solid solution online, so here's what I came up with after digging into the Poll Daddy plugin itself.
<?php
function remove_menus_for_USER_ROLE () {
if ( is_user_logged_in() && current_user_can('USER_ROLE') ) {
global $menu;
$restricted = array(
//__( 'Settings' ), //Uncomment if you still have POLLS showing up under settings, it really depends on the user role you're targeting.
__( 'Feedback' ),
__( 'Polls' ),
__( 'Ratings' ),
);
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
}
add_action('admin_menu', 'remove_menus_for_USER_ROLE', 999);
//To get this to work you'll need to replace USER_ROLE with whatever the user role you're targeting is.
//I did it for a custom 'vendor' user role created by WCMp (WooCommerce MarketPlace).
//While the WCMp plugin itself hides almost everything necessary, Poll Daddy by Automattic was still showing up.
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment