Last active
September 2, 2021 22:44
-
-
Save wpmudev-sls/e46e1991c6e108cdfa4654a61bb041e9 to your computer and use it in GitHub Desktop.
Hides specific menus from any users if they don't have the given ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Hide Plugins | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Hides specific plugins from Admin Menus & Plugins List | |
* Version: 1.0.0 | |
* Author: Konstantinos Xenos @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
add_action( 'pre_current_active_plugins', 'hide_plugins_from_list_if_not_admin' ); | |
function hide_plugins_from_list_if_not_admin() { | |
if ( is_user_logged_in() ) { | |
$user = wp_get_current_user(); | |
if ( '1' != $user->ID ) { | |
global $wp_list_table; | |
$plugins_list = $wp_list_table->items; | |
// add any plugin loader into the array | |
$hidden_plugins = array( 'ultimate-branding/ultimate-branding.php' ); | |
foreach ( $plugins_list as $key => $val ) { | |
if ( in_array( $key, $hidden_plugins ) ) { | |
unset( $wp_list_table->items[ $key ] ); | |
} | |
} | |
} | |
} | |
} | |
add_action( 'admin_menu', 'hide_plugins_from_menu', 15 ); | |
function hide_plugins_from_menu() { | |
if ( is_user_logged_in() ) { | |
$user = wp_get_current_user(); | |
if ( '1' != $user->ID ) { | |
// add any menu-slug into the array | |
$menu_items = array( 'branding' ); | |
foreach ( $menu_items as $menu_item ) { | |
remove_menu_page( $menu_item ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment