. */ class Active_Plugins { /** * Get hooked in * * @return void */ function __construct() { add_action( 'init', array( $this, 'init' ) ); } /** * Initialize setup. * Only prep admin page if we're on multisite * * @return void */ function init() { if ( ! is_multisite() ) { add_action( 'admin_notices', array( $this, 'admin_notices' ) ); } else { add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } } /** * Print for-multisite-only notice * * @return void */ function admin_notices() { // Lazy notice. Dismissable, but we're not keeping track. echo '

'; _e( 'Acitve Plugins is for multisite use only.', 'active-plugins' ); echo '

'; } /** * Register menu page * * @return void */ function network_admin_menu() { add_submenu_page( 'settings.php', __( 'Active Plugins Across Network', 'active-plugins' ), __( 'Active Plugins', 'active-plugins' ), 'unfiltered_html', __FILE__, array( $this, 'page' ) ); } /** * Print admin page * * @return void */ function page() { echo '
'; echo '

' . __( 'Active Plugins Across Network', 'active-plugins' ) . '

'; $links = array( sprintf( __( 'Network-Activated Plugins', 'active-plugins' ), network_admin_url( 'plugins.php?plugin_status=active' ) ), sprintf( __( 'MU Plugins', 'active-plugins' ), network_admin_url( 'plugins.php?plugin_status=mustuse' ) ), ); echo '

' . sprintf( __( 'List does not include: %s', 'active-plugins' ), implode( ', ', $links ) ) . '

'; global $wpdb; $blog_list = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs}, {$wpdb->registration_log} WHERE site_id = '%d' AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id" , $wpdb->siteid ), ARRAY_A ); // get blogs /* $all_plugins * Multi-dimensional array of plugins. e.g. * * [active-plugins-on-multisite/active-plugins.php] => Array * ( * [Name] => Active Plugins * [PluginURI] => http://trepmal.com/plugins/active-plugins-on-multisite/ * [Version] => 1.6 * [Description] => Get number of users for each active plugin (minus network-activated). Then break down by site. * [Author] => Kailey Lampert * [AuthorURI] => http://kaileylampert.com/ * [TextDomain] => active-plugins-on-multisite * [DomainPath] => * [Network] => 1 * [Title] => Active Plugins * [AuthorName] => Kailey Lampert * ) * */ $all_plugins = get_plugins(); $plugins_list = array_keys( $all_plugins ); /* $pi * "Plugins Installed" */ $pi = array(); // add main site to beginning $blog_list[-1] = array( 'blog_id' => 1 ); ksort( $blog_list ); // loop through the blogs foreach ( $blog_list as $k => $info ) { // store active plugins in giant array, index by blog id $bid = $info['blog_id']; $pi[ $bid ] = get_blog_option( $bid, 'active_plugins' ); } // $pi = array_filter( $pi ); // remove empties $pi_count = array(); foreach ( $pi as $k => $v_array ) { // put all active plugins into one array, we can then count duplicate values $pi_count = array_merge( $pi_count, $v_array ); } echo '

'; _e( 'Totals each active plugin and how many users', 'active-plugins' ); echo '

'; $totals = $tags = array_count_values( $pi_count ); ksort( $totals ); echo ''; $links = array( '' . __( 'Select all', 'active-plugins' ) . '', '' . __( 'Deselect all', 'active-plugins' ) . '', '' . __( 'Toggle', 'active-plugins' ) . '', ); echo '

' . implode( ' | ', $links ) . '

'; // find which are network-activated $network_plugins = array_flip( get_site_option('active_sitewide_plugins') ); // remove those from our list $remove_network = array_diff( $plugins_list, $network_plugins ); // show which not-network-activated plugins have 0 users _e( 'Plugins with zero (0) users:', 'active-plugins' ); echo ''; /* Output plugins for each site */ echo '
'; echo '

' . __( 'Show sites with no active plugins', 'active-plugins' ) . '

'; foreach ( $pi as $siteid => $list ) { switch_to_blog( $siteid ); $edit = network_admin_url( "site-info.php?id=$siteid" ); $view = home_url(); $dash = admin_url(); $plugins = admin_url('/plugins.php'); $blogname = get_bloginfo('name'); $edit_label = __( 'Edit', 'active-plugins' ); $view_label = __( 'View', 'active-plugins' ); $dashboard_label = __( 'Dashboard', 'active-plugins' ); $plugins_label = __( 'Plugins', 'active-plugins' ); $group_class = $list ? '' : ' no-plugins'; echo "
"; echo "

$blogname (ID: $siteid) [$edit_label] [$view_label] [$dashboard_label] [$plugins_label]

"; echo $list ? '' : ''; echo '
'; restore_current_blog(); } echo '
'; } // end page() /** * Enqueue JavaScript * Inline script with jQuery dependency * * @return void */ function enqueue_scripts( $hook ) { if ( 'settings_page_active-plugins-on-multisite/active-plugins' !== $hook ) { return; } ob_start(); ?> jQuery( document ).ready( function($) { $('a.select-all').click( function(ev) { ev.preventDefault(); $('.show-plugin:not(:checked)').click(); }); $('a.deselect-all').click( function(ev) { ev.preventDefault(); $('.show-plugin:checked').click(); }); $('a.toggle-all').click( function(ev) { ev.preventDefault(); $('.show-plugin').click(); }); $('a.show-empty').click( function(ev) { ev.preventDefault(); $('.no-plugins').toggle(); }); $('.show-plugin').change( function() { plugin = $(this).val(); $('li.'+plugin).toggle(); } ); }); .site-group.no-plugins { display: none; }