WordPress.org

Forums

Remove stubborn admin menu page (gettin pissed)) (3 posts)

  1. aggropixel
    Member
    Posted 2 years ago #

    So, I have managed to remove most menu items from the WP admin. However, I have a theme that uses a custom Options panel. This one I have tired like a million things including the following that is suppose to work.

    Screenshot: http://d.pr/i/B3ht
    Code I am using that doesn't work for this one in functions.php.
    remove_menu_page('admin.php?page=goodlayers_admin_panel');

    Please help me, it is critical I get this removed so the client doesn't change crap.

    Thanks,
    Josh

  2. You will need to remove the action that adds the menu page. Search the code and find add_action( 'admin_menu', 'function_name' ); //function_name will be the actual name of the function that adds the menu.

    Now add this code somewhere in your functions.php or a plugin.

    remove_action( 'admin_menu', 'function_name' ); //This should be written exactly as the function was added except we are using remove_action instead of add_action.

  3. scattered810
    Member
    Posted 2 years ago #

    This example is to remove the "portfolio" menu item from the "editor" roles. Change the line with the portfolio info to yours (admin.php?page=goodlayers_admin_panel) and change editor to the admin user role. This snippet gets added to functions.php

    function custom_remove_menus(){
    
        // Get current user's data
        $current_user = wp_get_current_user();
        $user_id = $current_user->ID;
    
        // Check user's roles
        $user = new WP_User( $user_id );
        if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
            if( in_array( 'editor', $user->roles ) ) {
                // Remove menu items
                remove_menu_page( 'edit.php?post_type=portfolio');
            }
        }
    }
    add_action( 'admin_menu', 'custom_remove_menus' );

Topic Closed

This topic has been closed to new replies.

About this Topic