Skip to content

Instantly share code, notes, and snippets.

@johnalarcon
Created October 25, 2020 07:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnalarcon/d6080b4401bfba3c9f759a260ef1c882 to your computer and use it in GitHub Desktop.
Save johnalarcon/d6080b4401bfba3c9f759a260ef1c882 to your computer and use it in GitHub Desktop.
Remove plugins from search results in ClassicPress dashboard
/**
* Remove plugins from search results in ClassicPress dashboard.
* A little ditty by Code Potent. https://codepotent.com
*/
// Add slugs for any individual plugins to remove.
function codepotent_plugins_to_remove() {
$slugs = [
'wordfence',
'jetpack',
];
return $slugs;
}
// Add WordPress usernames to remove; removes all their plugins from result.
function codepotent_authors_to_remove() {
$usernames = [
'takayukister',
'joostdevalk',
];
return $usernames;
}
// This is where the magic happens.
function codepotent_remove_plugins_from_search($res, $action, $args) {
if (basename($_SERVER['REQUEST_URI']) === 'plugin-install.php') {
$plugins = codepotent_plugins_to_remove();
$authors = codepotent_authors_to_remove();
foreach ($res->plugins as $n=>$plugin) {
if (in_array($plugin->slug, $plugins, true)) {
unset($res->plugins[$n]);
} else if (in_array(basename($plugin->author_profile), $authors, true)) {
unset($res->plugins[$n]);
}
}
}
return $res;
}
add_filter('plugins_api_result', 'codepotent_remove_plugins_from_search', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment