Removing an admin page added by a 3rd party plugin. Gravity forms in this example

I’m trying to hide a help page from editors, added by the gravity forms plugin. I believe I’ve run into the same issue before with other plugins, so I’d like to know the correct way to do it for 3rd party plugins. This is what I have so far which does not work. It does of course work for other WP menus so I’m wondering if the function is only limited to WP menus?

function remove_menu_links() {
  if( !current_user_can('manage_options') ) {
    remove_menu_page('admin.php?page=gf_help'); // this is the pages url
  }
}
add_action( 'admin_menu', 'remove_menu_links');

Related posts

Leave a Reply

6 comments

  1. Ok, Eugene’s Answer works in the case of a plugin that doesn’t deals with custom capabilities.

    http://codex.wordpress.org/Roles_and_Capabilities
    The WordPress Plugin API allows Roles and Capabilities to be added, removed and changed. Since Plugins might change Roles and Capabilities, just the default ones are addressed in this article.


    So, if his code works without checking for the capability, we have to look how GravityForms executes his add_submenu_page action.
    And for that, we drop the whole plugin folder inside a good code editor (NotePad++, TextMate, etc) and do a global search and find our stuff.

    // wp-content/plugins/gravityforms/gravityforms.php
    // all parameters removed from the original code, except $page_title and $capability
    add_submenu_page( 
        $parent_slug, 
        __("Help", "gravityforms"),
        $menu_title,
        $has_full_access ? "gform_full_access" : $min_cap, 
        $menu_slug, 
        $function 
    );
    

    And a few lines before we see:

    $has_full_access = current_user_can("gform_full_access");
    $min_cap = GFCommon::current_user_can_which(GFCommon::all_caps());
    if(empty($min_cap))
        $min_cap = "gform_full_access";
    

    Now we go ahead with Members plugin, which btw GF recognizes, and we have the following in its config screen for the Editor role.
    BUT NOTING THAT gform_full_access doesn’t appears in this list. It has to be manually added through the plugin interface…

    enter image description here

    After that and marking the full access capability, the remove_submenu_page works as expected to the Editor role.



    Reference code for all submenus (remembering the first one is the very top menu).

    function remove_menu_links() {
        if( !current_user_can( 'manage_options' ) ) {
            // remove_submenu_page( 'gf_edit_forms', 'gf_edit_forms' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_new_form' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_new_formf_help' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_entries' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_settings' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_export' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_update' ); 
            // remove_submenu_page( 'gf_edit_forms', 'gf_addons' ); 
            remove_submenu_page( 'gf_edit_forms', 'gf_help' ); 
        }
    }
    add_action( 'admin_menu', 'remove_menu_links', 9999 );
    

    Plugin of interest

    Adminimize does this hiding magic in the blink of an eye and is completely PRO.

  2. You need to add your hook at the end of the queue and then remove menu by slug:

    function remove_menu_links() {
        if( !current_user_can( 'manage_options' ) ) {
            remove_menu_page( 'gf_edit_forms' ); // this is the pages url
        }
    }
    add_action( 'admin_menu', 'remove_menu_links', 9999 );
    

    If you want to remove submenu you need to use following snippet:

    function remove_menu_links() {
        if( !current_user_can( 'manage_options' ) ) {
            remove_submenu_page( 'gf_edit_forms', 'gf_help' ); 
        }
    }
    add_action( 'admin_menu', 'remove_menu_links', 9999 );
    
  3. The GravityForms plugin renames the top level menu item to match the first of the sub-menu.

    For example; if you’ve added just the gravityforms_view_entries capability to the Editor role, then the first sub-menu item will be “Entries”, so the parent menu will be “gf_entries” not “gf_edit_forms”. So, the following code will remove the “Help” item from the sub-menu for Editors with just that capability:

    function remove_menu_links() {
        remove_submenu_page( 'gf_entries', 'gf_help' );
    }
    add_action( 'admin_menu', 'remove_menu_links', 9999 )
    ;
    

    Hope this helps.

  4. This was driving me insane. The answers provided here got me most of the way, but that particular darned Gravity Forms menu item is a little weird.

    I managed to get to the root of it by analysing the $submenu global variable which contains all the menu data. The following snippet should kill the update submenu item for you, when hooked into admin_menu() as listed above 🙂

    remove_submenu_page( 'gf_edit_forms', 'gf_update' ); 
    
  5. you can hide it with css only if you want,
    search for a plugin to add css on admin panel :

    a[href="admin.php?page=gf_help"] {
        display: none !important;
    }