. */ class activeplugins { function __construct() { add_action('init', array( &$this, 'setup' ) ); } function setup() { if ( ! is_multisite() ) add_action('admin_notices', array( &$this, 'notice' ) ); else add_action('network_admin_menu', array( &$this, 'menu' ) ); } function notice() { echo '

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

'; } function menu() { add_submenu_page( 'settings.php', 'Active Plugins', 'Active Plugins', 'unfiltered_html', __FILE__, array( &$this, 'page' ) ); } function page() { echo '
'; echo '

'; _e( 'Active Plugins', 'active-plugins' ); echo '

'; echo '

'; _e( 'Network-Activated plugins not listed.', 'active-plugins' ); echo '

'; global $wpdb; $query = "SELECT * FROM {$wpdb->blogs}, {$wpdb->registration_log} WHERE site_id = '{$wpdb->siteid}' AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id"; $blog_list = $wpdb->get_results( $query, ARRAY_A ); //get blogs $all_plugins = get_plugins(); $plugins_list = array_keys( get_plugins() ); //echo '
'. print_r( get_plugins(), true) .'
'; $pi = array(); //add main site to beginning $blog_list[-1] = array( 'blog_id' => 1 ); ksort($blog_list); foreach( $blog_list as $k => $info ) { //loop through the blogs //store active plugins is 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 "
Totals (each active plugin and how many users): \n";
			$totals = $tags = array_count_values( $pi_count );
			ksort( $totals );
			foreach( $totals as $name => $tot) {

				if ( strpos( $name, '/') !== false) {
					$dir = WP_PLUGIN_DIR . '/' . dirname( $name );
					$dottags = ( glob( $dir . '/*.tag') );
					if ( ! empty( $dottags ) )
						$tags[ $name ] = str_replace( $dir . '/', '', str_replace( '.tag', '', $dottags['0'] ) );
				}

				if ( in_array( $name, $plugins_list ) ) {
				 	$plugins_list = array_flip( $plugins_list );
				 	unset( $plugins_list[ $name ] );
				 	$plugins_list = array_flip( $plugins_list );
				}

				$realname = $all_plugins[$name]['Name'] . ' v' . $all_plugins[$name]['Version'];
				//$realname = $all_plugins[$name]['Name'];
				echo "\t" . $realname . (!is_numeric($tags[ $name ]) ? ' (tagged: '.$tags[ $name ].')' : '') . ' is used by ' . $tot . ' site' . (($tot == '1') ? '' : 's') . "\n";

			}

			//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
			echo "\nInactive (plugins with zero (0) users): \n";
			foreach( $remove_network as $k => $inactive ) {
				$realname = $all_plugins[$inactive]['Name'] . ' v' . $all_plugins[$inactive]['Version'];
				echo "\t{$realname}\n";
			}

		echo '
'; echo '
'; echo "
\n";
			foreach( $pi as $siteid => $list ) {
				$details = get_blog_details( $siteid );

				$plugins = "$details->siteurl/wp-admin/plugins.php";
				$dash = "$details->siteurl/wp-admin/";
				$view = "$details->siteurl";
				$edit = network_admin_url( "site-info.php?id=$siteid" );

				echo "$details->blogname ($siteid) Edit [View] [Dashboard] [Plugins page] \n";

				$tagged = array();
				$nottagged = '';
				foreach( $list as $name ) {
					//$realname = $all_plugins[$name]['Name'] . ' v' . $all_plugins[$name]['Version'];
					$realname = $all_plugins[$name]['Name'];
					if ( is_numeric( $tags[ $name ] ) )
						$nottagged .= "\t{$realname}\n";
					else
						$tagged["\t({$tags[ $name ]}) $realname\n"] = $tags[ $name ];
				}
				asort( $tagged );
				$tagged = array_keys( $tagged );
				echo implode( $tagged ) . $nottagged . "\n";

				unset( $tagged );
				unset( $nottagged );
			}

		echo '
'; echo '
'; }// end page() } new activeplugins();