• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

How Many Plugins?

September 15, 2010 Stephanie Leary 7 Comments

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!

WordPress Plugins

Reader Interactions

Comments

  1. Ozh says

    September 16, 2010 at 9:09 am

    You’re looping over lots of useless data here. You just need to echo count( get_option( ‘active_plugins’ ) )

    Reply
    • steph says

      September 16, 2010 at 9:26 am

      Well, I thought so too at first, but why on earth doesn’t plugins.php do it that way?

      Reply
      • Ozh says

        September 16, 2010 at 9:48 am

        Because plugins.php has to retrieve a number of info for each plugins: title, urls, version, is it active, etc…

        Reply
        • steph says

          September 16, 2010 at 4:27 pm

          Ah yes, this is much shorter if all you need is the count!

          Reply
  2. Andrew Nacin says

    September 16, 2010 at 3:19 pm

    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.

    Reply
  3. Ron says

    September 22, 2010 at 2:24 pm

    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;

    Reply
    • steph says

      September 22, 2010 at 2:28 pm

      Cool. Thanks, Ron!

      Reply

Leave a Reply Cancel reply

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

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2023 Stephanie Leary · Contact