Skip to content

Instantly share code, notes, and snippets.

@Japh
Forked from spivurno/gist:4560722
Created January 18, 2013 13:45
Show Gist options
  • Save Japh/4564616 to your computer and use it in GitHub Desktop.
Save Japh/4564616 to your computer and use it in GitHub Desktop.
<?php
add_filter('wp_butler_ajax_keyword_actions', 'wp_butler_switch_plugins_action', 10, 2);
function wp_butler_switch_plugins_action($term_and_actions) {
list($term, $actions) = $term_and_actions;
$term_words = explode( ' ', $_REQUEST['term'] );
$keyword = $term_words[0];
if($keyword != 'activate')
return $term_and_actions;
array_shift( $term_words );
$term = implode( ' ', $term_words );
$plugins = get_plugins();
$plugin_matches = array();
foreach($plugins as $plugin_file => $plugin) {
if ( preg_match( '/' . $term . '/i', $plugin['Title'] ) && !is_plugin_active($plugin_file) ) {
$actions[] = array(
'label' => html_entity_decode( "{$plugin['Title']} v{$plugin['Version']}", ENT_QUOTES, get_option( 'blog_charset' ) ),
'url' => add_query_arg( '_wpnonce', wp_create_nonce( 'activate-plugin_' . $plugin_file ), "plugins.php?action=activate&plugin={$plugin_file}&deactivate_existing=1")
);
}
}
return array($term, $actions);
}
@Japh
Copy link
Author

Japh commented Jan 18, 2013

Example usage of Japh/wp-butler@f55bcc0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment