-
-
Save Japh/4564616 to your computer and use it in GitHub Desktop.
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
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage of Japh/wp-butler@f55bcc0