. */ $activeplugins = new activeplugins(); class activeplugins { function activeplugins() { add_action('admin_menu', array(&$this, 'menu')); } function menu() { add_submenu_page('ms-admin.php', 'Active Plugins', 'Active Plugins', 'unfiltered_html', __FILE__, array(&$this, 'page')); } function page() { global $wpdb; echo '
'; echo '

'.__('Active Plugins').'

'; echo '

'.__('Does not include network activated plugins and in some cases the primary blog/site (depends on whether or not this network was upgraded from WPmu).').'

'; $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 $plugins_list = get_plugins(); $plugins_list = array_keys($plugins_list); $pi = array(); foreach($blog_list as $id=>$info) { $theid = $info['blog_id']; $query = "SELECT option_value, option_name FROM ".$wpdb->base_prefix.$theid."_options WHERE option_name='active_plugins'"; //get active plugin info for each blog from above $active = $wpdb->get_results( $query, ARRAY_A ); $pi[$theid] = unserialize($active['0']['option_value']); //store active plugin array as value to $pi['blog_id'] unset($query); } $pi = array_filter($pi); //remove empties $pi_count = array(); foreach($pi as $k=>$v_array) { $pi_count = array_merge($pi_count, $v_array); //put all active plugins into one array, we can then count duplicate values } echo '
Totals (each active plugin and how many users):'."\n";
			$totals = array_count_values($pi_count);
			$tags = $totals;
			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);
				 	
				}
				
				echo "\t" . $name . (!is_numeric($tags[ $name ]) ? ' (tagged: '.$tags[ $name ].')' : '') . ' is used by ' . $tot . ' site' . (($tot == '1') ? '' : 's') . "\n";
				
			}

			$network_plugins = array_flip(get_site_option('active_sitewide_plugins'));
			$remove_network = array_diff($plugins_list,$network_plugins);

			echo "\n".'Inactive (plugins with zero (0) users):';
			foreach($remove_network as $k=>$inactive) {
				echo "\t".$inactive . "\n";
			}

		echo '
'; echo '
'; echo '
Blog (ID, URL) -> plugins:'."\n";
			foreach($pi as $siteid=>$list) {
				$details = get_blog_details($siteid);
				echo $details->blogname . ' (' . $siteid . ', ' . $details->siteurl . ' Go to plugins page →)' . "\n";
				$tagged = array(); $nottagged = '';
				foreach($list as $name) {
					if ( is_numeric( $tags[ $name ] ) )
						$nottagged .= "\t".$name . "\n";
					else
						$tagged["\t(" . $tags[ $name ] . ') ' . $name . "\n"] = $tags[$name];
				}
				asort($tagged);
				$tagged = array_keys($tagged);
				echo implode($tagged) . $nottagged . "\n";
				unset( $tagged ); unset( $nottagged );
			}

		echo '
'; echo '
'; }// end page() }//end class ?>