Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hides specific menus from any users if they don't have the given ID
<?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
You can’t perform that action at this time.