Skip to content

Instantly share code, notes, and snippets.

@numediaweb
Last active October 25, 2022 22:46
Show Gist options
  • Select an option

  • Save numediaweb/7dc94a428d0bc9d175b1 to your computer and use it in GitHub Desktop.

Select an option

Save numediaweb/7dc94a428d0bc9d175b1 to your computer and use it in GitHub Desktop.

Revisions

  1. Abdessamad Idrissi revised this gist Jan 2, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion functions.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,6 @@ function filter_admin_menues() {

    // Edit
    'edit.php',
    'post-new.php',

    // Media
    'upload.php'
  2. Abdessamad Idrissi created this gist Jan 2, 2015.
    57 changes: 57 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    function filter_admin_menues() {

    // If administrator then do nothing
    if (current_user_can('activate_plugins')) return;

    // Remove main menus
    $main_menus_to_stay = array(

    // Dashboard
    'index.php',

    // Edit
    'edit.php',
    'post-new.php',

    // Media
    'upload.php'
    );

    // Remove sub menus
    $sub_menus_to_stay = array(

    // Dashboard
    'index.php' => ['index.php'],

    // Edit
    'edit.php' => ['edit.php', 'post-new.php'],

    // Media
    'upload.php' => ['upload.php', 'media-new.php'],


    );


    if (isset($GLOBALS['menu']) && is_array($GLOBALS['menu'])) {
    foreach ($GLOBALS['menu'] as $k => $main_menu_array) {
    // Remove main menu
    if (!in_array($main_menu_array[2], $main_menus_to_stay)) {
    remove_menu_page($main_menu_array[2]);
    } else {

    // Remove submenu
    foreach ($GLOBALS['submenu'][$main_menu_array[2]] as $k => $sub_menu_array) {

    if (!in_array($sub_menu_array[2], $sub_menus_to_stay[$main_menu_array[2]])) {

    remove_submenu_page($main_menu_array[2], $sub_menu_array[2]);
    }
    }
    }
    }
    }
    }

    // Filter admin side navigation menues
    add_action('admin_init', 'filter_admin_menues');