Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Last active August 25, 2021 15:19
Show Gist options
  • Save anythinggraphic/ef149ed37477d7f89ecaba4bc97a5f8c to your computer and use it in GitHub Desktop.
Save anythinggraphic/ef149ed37477d7f89ecaba4bc97a5f8c to your computer and use it in GitHub Desktop.
WordPress: Hide plugins from displaying on the WP Admin > Plugins page.
<?php
/**
* Hide Plugins.
*
* Removes plugin(s) from displaying on the list of installed plugins on
* the WP Admin > Plugins page.
*
* @param array $hidden_plugins Array of plugins to hide.
*
* TODO: Does the parent folder 'have' to be specified? Why or why not?
*/
add_action(
'pre_current_active_plugins',
function() {
// Get global variable.
global $wp_list_table;
// Array of plugins to hide. Include parent folder and plugin's main file.
$hidden_plugins = array(
// Name of Plugin.
'folder/file.php',
);
// Get all plugins that are installed.
$installed_plugins = $wp_list_table->items;
/**
* For each plugin found above, look at each one and see if there's
* a match in $hidden_plugins.
*/
foreach ( $installed_plugins as $key => $val ) {
if ( in_array( $key, $hidden_plugins, true ) ) {
unset( $wp_list_table->items[ $key ] );
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment