Last active
July 26, 2023 18:23
-
-
Save petertwise/5468e4d793c7ad89a32cb8e27de8ae3c to your computer and use it in GitHub Desktop.
Hide Stream plugin from all users except one Admin
This file contains hidden or 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: Square Candy Hide Stream (activity monitor plugin) | |
Plugin URI: https://gist.github.com/petertwise/5468e4d793c7ad89a32cb8e27de8ae3c | |
Version: 1.0 | |
Author: Square Candy | |
Author URI: https://squarecandydesign.com | |
License: GPLv2 | |
SETUP INSTRUCTIONS: | |
1. Add this file to /wp-content/mu-plugins | |
2. Add the one user id that should be able to access this to wp-config.php like this: | |
`define( 'SQUARECANDY_SUDO_USER', 1 );` | |
*/ | |
add_action( 'admin_init', 'squarecandy_hide_stream_remove_menu_pages' ); | |
function squarecandy_hide_stream_remove_menu_pages() { | |
global $user_ID; | |
// check if the current admin user is our special user | |
if ( defined( 'SQUARECANDY_SUDO_USER' ) && (int) $user_ID !== (int) SQUARECANDY_SUDO_USER ) { | |
// hide the admin pages | |
remove_menu_page( 'toplevel_page_wp_stream' ); | |
remove_menu_page( 'wp_stream' ); | |
remove_menu_page( 'edit.php?post_type=wp_stream_alerts' ); | |
remove_menu_page( 'wp_stream_settings' ); | |
// filter it out of the list of plugins | |
add_filter( 'all_plugins', 'squarecandy_hide_stream_hide_plugin' ); | |
// hide all mu plugins | |
add_filter( 'views_plugins', 'squarecandy_hide_mu_plugins' ); | |
} | |
} | |
function squarecandy_hide_mu_plugins( $views ) { | |
if ( isset( $views['mustuse'] ) ) { | |
unset( $views['mustuse'] ); | |
} | |
return $views; | |
} | |
function squarecandy_hide_stream_hide_plugin( $plugins ) { | |
unset( $plugins['stream/stream.php'] ); | |
return $plugins; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment