Last active
November 24, 2019 20:57
-
-
Save wpmudev-sls/0b16a48c6c8d4ae8efe5bc8b62b2bc55 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Plugin Name: Plugin Toggler | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: A simple plugin that quickly activates/deactivates plugins | |
* Author: Alessandro Kaounas @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
die(); | |
} | |
function wpmudev_plugin_toggle_admin( $wp_admin_bar ) { | |
global $wp_admin_bar; | |
$function = is_multisite() ? 'network_admin_url' : 'admin_url'; | |
// You can add more plugins below | |
$plugins = array( | |
'Forminator' => 'forminator/forminator.php' | |
); | |
$wp_admin_bar->add_menu( array( | |
'id' => 'plugin-toggler', | |
'title' => 'Plugin Toggler', | |
'href' => false | |
) ); | |
foreach( $plugins as $name => $plugin ){ | |
$wp_admin_bar->add_menu( array( | |
'parent' => 'plugin-toggler', | |
'id' => 'plugin-toggler-' . sanitize_title( $name ), | |
'title' => $name, | |
'href' => false | |
) ); | |
$wp_admin_bar->add_menu( array( | |
'id' => 'plugin-toggler-' . sanitize_title( $name ) . '-activate', | |
'parent' => 'plugin-toggler-' . sanitize_title( $name ), | |
'title' => 'Activate', | |
'href' => wp_nonce_url( add_query_arg( array( | |
'action' => 'activate', | |
'plugin' => $plugin, | |
'plugin_status' => 'all', | |
'paged' => '1' | |
), $function( 'plugins.php', 'activate-plugin_' . $plugin ) ), 'activate-plugin_' . $plugin ) | |
) ); | |
$wp_admin_bar->add_menu( array( | |
'id' => 'plugin-toggler-' . sanitize_title( $name ) . '-deactivate', | |
'parent' => 'plugin-toggler-' . sanitize_title( $name ), | |
'title' => 'Deactivate', | |
'href' => wp_nonce_url( add_query_arg( array( | |
'action' => 'deactivate', | |
'plugin' => $plugin, | |
'plugin_status' => 'all', | |
'paged' => '1' | |
), $function( 'plugins.php', 'deactivate-plugin_' . $plugin ) ), 'deactivate-plugin_' . $plugin ) | |
) ); | |
} | |
} | |
add_action( 'admin_bar_menu', 'wpmudev_plugin_toggle_admin', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment