I’m glad it worked! If what you want is to remove any trace of the plugin (both from the wp-admin
menus and the plugins lists) for non super-admins you can try this one:
// Function to restrict access to test-plugin settings and hide it from non-super-admin users
function restrict_and_hide_test_plugin($plugins) {
// Check if current user is not a super-admin
if (!is_super_admin()) {
// Remove the plugin's menu item
remove_menu_page('test-plugin');
// Optionally, you can also hide the plugin's settings submenu
remove_submenu_page('test-plugin', 'test-plugin-settings');
// Check if the test-plugin is in the list of plugins
if (isset($plugins['test-plugin/test-plugin.php'])) {
// Remove the test-plugin from the list
unset($plugins['test-plugin/test-plugin.php']);
}
}
return $plugins;
}
add_action('admin_menu', 'restrict_and_hide_test_plugin');
add_filter('all_plugins', 'restrict_and_hide_test_plugin');
Again, remember to replace test-plugin
with the right plugin slug.