0
add_action('admin_menu', 'remove_admin_menu_links');
        function remove_admin_menu_links(){
            $user = wp_get_current_user();
            if( $user && isset($user->user_email) && 'email@address.com' == $user->user_email ) {

                remove_menu_page('upload.php'); // Media - works(remove)

                remove_menu_page( 'gf_edit_forms' ); //Forms - doesn't work(visibile)

                remove_menu_page('edit.php?post_type=page'); // Pages - works(removed)

                remove_menu_page('wpseo_dashboard'); // SEO  - works(remove)
                remove_menu_page('admin.php?page=wpseo_dashboard'); // SEO  - works(remove)

                remove_menu_page('envanto-market'); // Envanto Market  - doesn't work(visibile)
                remove_menu_page('admin.php?page=envanto-market'); // Envanto Market - doesn't work(visibile)

                remove_menu_page('gadwp_settings'); // Google Analytics - doesn't work(visibile)
                remove_menu_page('admin.php?page=gadwp_settings'); // Google Analytics - doesn't work(visibile)
        }
    }

add_action( 'admin_menu', 'remove_admin_menus_links' , 9999 );

Outlined above shows the action added to remove menu items from a specific admin users menu items.

I cant seem to be able to remove Forms, Envanto Market or Google Analytics. The rest of the menu items have been removed, bit I cant figure out why these few don't appear to moving.

If anyone can see why these menu items are still available?

Also, there is a full list of these menu items still available in the admin_bar_menu, new_Post option at the top of the page. If Anyone can point me in the right direction to remove these too?

I've tried adding to functions.php:

// admin_bar_menu hook
add_action('admin_bar_menu', 'update_adminbar', 999);

and in the /plugins/admin_bar.php :

<?php
// update toolbar
function update_adminbar($wp_adminbar) {

  // remove unnecessary items
  $wp_adminbar->remove_node('wp-logo');
  $wp_adminbar->remove_node('customize');
  $wp_adminbar->remove_node('comments');
  $wp_adminbar->remove_node('post-new');

}
?>
0

The admin bar is hooked incorrectly.It should be hooked to wp_before_admin_bar_render.

This is what I use (and works):

function alter_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu( 'customize' );
    $wp_admin_bar->remove_menu( 'ddw-gravityforms-toolbar' );
    $wp_admin_bar->remove_menu( 'members-new-role' );
    $wp_admin_bar->remove_menu( 'new-media' );
    $wp_admin_bar->remove_menu( 'new-post' );
    $wp_admin_bar->remove_menu( 'new-user' );
    $wp_admin_bar->remove_menu( 'wp-logo' );
}
add_action( 'wp_before_admin_bar_render', 'alter_admin_bar' );

Regarding the side menu I don't know. My first guess would be that you're using incorrect identifiers.

  • Thanks, that seems to work, but now I need to change the access to specific users. I've replaced the global rule with the specific user as outlined in the remove_admin_menu_links as per email address, but it looses the top menu bar all together and doesn't give the user access to anything at all, just showing a blank window in the main section, no matter which menu item I choose. – cjones Mar 18 '18 at 12:46
  • Just to make clear, using the per users email option to does only remove access for that specific user. I still have access to everything with my login details including the main window to edit and add – cjones Mar 18 '18 at 12:49
  • in addition to the inability to remove certain menu items such as Forms, etc. It appears that Gravity have there own specific method to remove menu items – cjones Mar 18 '18 at 12:52
  • Can't you filter it with current_user_can ? Instead of by email ? – Beee Mar 18 '18 at 17:19
1

There's a typo on your callback function name.

add_action( 'admin_menu', 'remove_admin_menus_links' , 9999 );

should be:

add_action( 'admin_menu', 'remove_admin_menu_links' , 9999 );

If you correct that, the action will get fired later and the GADWP menu link will get removed.

  • brilliant! Needed new glasses! – cjones Mar 22 '18 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.