Home / Admin / Hide plugins from admin list of plugins
Duplicate Snippet

Embed Snippet on Your Site

Hide plugins from admin list of plugins

This snippet can be used to hide certain plugins from the list of plugins in the admin based on the user role.

<10
Code Preview
php
<?php
function wpcode_custom_hide_plugins() {
	// Replace "administrator" with the user role you want to target.
	if ( ! current_user_can( 'administrator' ) ) {
		return;
	}
	// Modify the array to match the plugins you want to hide.
	$plugins_to_hide = array(
		'plugin-slug/plugin-file.php',
	);
	global $wp_list_table;
	$plugins         = $wp_list_table->items;
	foreach ( $plugins as $key => $val ) {
		if ( in_array( $key, $plugins_to_hide, true ) ) {
			unset( $wp_list_table->items[ $key ] );
		}
	}
}
add_action( 'pre_current_active_plugins', 'wpcode_custom_hide_plugins' );

Comments

Add a Comment