Created
October 25, 2020 07:22
-
-
Save johnalarcon/d6080b4401bfba3c9f759a260ef1c882 to your computer and use it in GitHub Desktop.
Remove plugins from search results in ClassicPress dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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