I saw a post on the Sure Crafted Facebook group about hiding Otto kit (SureTriggers) from other admins they didn’t want people interfering with the workflows but they needed admin access.
I answered this post saying I am sure it could be done with a snippet and said I would look at it as soon as i got some time well its been a few weeks and i’ve been super busy but I had a spare hour tonight and began working on a solution and that solution is below.
The truth is you will never be able to totally stop an admin user or someone with FTP access from getting to something in WordPress but you can me it a little harder the following code in a mu-plugin is how I would achieve this.
It is a simple 5 step process
- only run the code if I am not the designated otto admin
- Remove Ottokit from the plugin list
- remove its row in the activate/ deactivate and settings links
- remove its admin / menu and page
- block direct access to its pages
- hide this mu-plugin.
<?php
// 1) Only run for other users
function only_hide_for_others() {
return get_current_user_id() !== 1; // change "1" to your user ID if different
}
// 2) Remove plugin from Plugins list
add_filter( 'all_plugins', function( $plugins ){
if ( only_hide_for_others() ) {
unset( $plugins['suretriggers/suretriggers.php'] );
}
return $plugins;
});
// 3) Remove its row-actions (activate/deactivate/settings links)
add_filter( 'plugin_action_links_suretriggers/suretriggers.php', function( $actions ){
if ( only_hide_for_others() ) {
return []; // hide all links
}
return $actions;
}, 10, 1 );
// 4) Remove its admin menu/page
add_action( 'admin_menu', function(){
if ( only_hide_for_others() ) {
remove_menu_page( 'suretriggers' ); // top-level
//remove_submenu_page( 'tools.php', 'my-plugin-slug' ); // if under Tools
}
}, 999 );
// 5) Block direct URL access to its pages
add_action( 'admin_init', function(){
if ( only_hide_for_others() && isset( $_GET['page'] ) && $_GET['page'] === 'admin.php?page=suretriggers' ) {
wp_safe_redirect( admin_url() );
exit;
}
});
add_filter( 'plugins_list', function( $plugins ) {
if ( only_hide_for_others() ) {
// 'mustuse' is the slice of the list for MU-plugins
// replace 'mu-helper.php' with *your* filename
unset( $plugins['mustuse']['otto.php'] );
}
return $plugins;
}, 10, 1 );
PHP