.
*/
class activeplugins {
function __construct() {
add_action( 'init', array( &$this, 'init' ) );
}
function init() {
if ( ! is_multisite() )
add_action( 'admin_notices', array( &$this, 'admin_notices' ) );
else
add_action( 'network_admin_menu', array( &$this, 'network_admin_menu' ) );
}
function admin_notices() {
echo '
';
echo '
'. __( 'Active Plugins', 'active-plugins' ) .'
';
echo '
'. __( 'Network-Activated plugins not listed.', 'active-plugins' ) .'
';
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() );
$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 '
';
_e( 'Totals (each active plugin and how many users)', 'active-plugins' );
$totals = $tags = array_count_values( $pi_count );
ksort( $totals );
echo '
';
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 );
}
$version = isset( $all_plugins[$name]['Version'] ) ? $all_plugins[$name]['Version'] : '';
$version = sprintf( __( 'v%s', 'active-plugins' ), $version );
if ( isset( $all_plugins[ $name ] ) ) {
$label = sprintf( __( '%1$s %2$s', 'active-plugins' ), $all_plugins[$name]['Name'], $version );
} else {
$label = sprintf( __( '%s (Uninstalled)', 'active-plugins' ), $name );
}
$label .= is_numeric( $tags[ $name ] ) ? '' : sprintf( __( ' (tagged: %s)', 'active-plugins' ), $tags[ $name ] );
$fulllabel = sprintf( _n( '%s is used by %d site', '%s is used by %d sites', $tot, 'active-plugins' ), $label, $tot );
echo "- $fulllabel
";
}
echo '
';
//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 '
';
foreach( $remove_network as $k => $inactive ) {
// $realname = $all_plugins[$inactive]['Name'] . ' v' . $all_plugins[ $inactive ]['Version'];
$version = isset( $all_plugins[$name]['Version'] ) ? $all_plugins[$name]['Version'] : '';
$version = sprintf( __( 'v%s', 'active-plugins' ), $version );
$realname = sprintf( __( '%1$s %2$s', 'active-plugins' ), $all_plugins[ $inactive ]['Name'], $version );
$unused[] = "- {$realname}
";
}
echo empty( $unused ) ? '- '. __( 'none', 'active-plugins' ) .'
' : implode( $unused );
echo '
';
echo '
';
echo '
';
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' );
echo "
";
echo '
';
$tagged = array();
$nottagged = array();
foreach( $list as $name ) {
$realname = isset( $all_plugins[ $name ] ) ? $all_plugins[ $name ]['Name'] : $name;
if ( is_numeric( $tags[ $name ] ) )
$nottagged[] .= "- {$realname}
";
else
$tagged["- ({$tags[ $name ]}) $realname
"] = $tags[ $name ];
}
asort( $tagged );
$tagged = array_keys( $tagged );
echo implode( $tagged );
sort( $nottagged );
echo implode( $nottagged );
echo '
';
restore_current_blog();
}
echo '
';
echo '
';
}// end page()
}
new activeplugins();