How Many Plugins?

plugins-in-right-now
Standard

Over in a comment thread on the Tavern, Adam mentioned that he’d like to have a plugin count in the Right Now box on the Dashboard. As it happens, I once wrote a plugin for a client that added some information to the Right Now box, so it was easy to alter it to print the number of plugins:

<?php
/*
Plugin Name: How Many Plugins
Plugin URI: http://stephanieleary.com/
Description: Counts the number of active plugins you have and prints a link in the Right Now box
Author: Stephanie Leary
Version: 0.1
Author URI: http://stephanieleary.com/
*/

function scl_get_plugin_count() {
	$all_plugins = apply_filters( 'all_plugins', get_plugins() );
	foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {
		if ( is_plugin_active($plugin_file) ) {
			$active_plugins[ $plugin_file ] = $plugin_data;
		}
	}
	$total_active_plugins = count($active_plugins);
	echo '<p class="plugins-right-now">You have <a href="plugins.php">'.$total_active_plugins.' active plugins</a>.';
}

add_action('activity_box_end', 'scl_get_plugin_count');
?>

Save this as a PHP file in your wp-content/plugins directory (I just called it count-plugins.php) and activate it.

Of course, if you have a lot of plugins, I suppose this might slow down your Dashboard a little.

ETA: There’s a much shorter solution in the comments!

7 thoughts on “How Many Plugins?

  1. I was coming here to suggest the same thing as Ozh. get_plugins() reads the entire directory of plugins, verifies files and plugin headers, and the like. It’s slow, and you probably don’t want to slow your dashboard down that much. Calling get_option(‘active_plugins’) is a cheap and easy way for the same result.

  2. In addition to what @Ohz said, if you want to make it WP network friendly

    $count = count( get_option( ‘active_plugins’ ) );
    if( is_multisite() )
    $count += count( get_site_option( ‘active_sitewide_plugins’, array() ) );

    echo $count;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>