When you develop a WordPress website, you may need to hide a plugin, so customers won’t access it or change its settings.
In this blog post, I will show how to hide the WPGraphQL plugin from the plugins page. Edit functions.php inside your themes folder, add the following code
add_filter('all_plugins', function ($plugins) {
unset($plugins['wp-graphql/wp-graphql.php1']);
return $plugins;
});
Now the plugin will not be listed on the Plugins page inside the WordPress Admin area.
Hide Menus
The plugin still displays the Menu on the sidebar and top bar. To hide the menu, add the following code in the functions.php file inside the theme folder.
add_action('admin_print_scripts', function () {
echo '<style>';
echo '#toplevel_page_graphiql-ide { display: none; }';
echo '#wp-admin-bar-graphiql-ide { display: none; }';
echo '</style>';
});
To only do this for admin users, use the following code
if (current_user_can('administrator') && !array_key_exists('show_all', $_GET)) {
add_filter('all_plugins', function ($plugins) {
unset($plugins['wp-graphql/wp-graphql.php1']);
return $plugins;
});
add_action('admin_print_scripts', function () {
echo '<style>';
echo '#toplevel_page_graphiql-ide { display: none; }';
echo '#wp-admin-bar-graphiql-ide { display: none; }';
echo '</style>';
});
}
To show the hidden menu items and plugin, add ?show_all to the end of the URL, for example
https://serverok.in/wp-admin/plugins.php?show_all
Back to WordPress
Leave a Reply