WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is some code that is the result of four days of studying Wordpress and PHP. Unfortunately, it's not working the way it's supposed to. Nothing displays at the admin_notices bar.

Originally, I thought it was the $filename = is_plugin_active($filename) ? "$filename: Active" : "$filename: Disabled"; line, but that was not the problem. What say you?

function show_names()
  $paths = array();

  foreach (glob("*/plugins/*") as $filename) {                                                                                                          
    $filename = is_plugin_active($filename) ? "$filename: Active" : "$filename: Disabled";
    $filename = str_replace('wp-content/plugins/', '', $filename);
    $paths[] = $filename;   

  $paths = implode("---", $paths);
  echo $paths;

add_action("admin_notices", "show_names");
share|improve this question

var_dump($paths); shows that the your $paths variable is an empty string. It's not showing anything because there is nothing to show.

Since you seem like you're trying to find all the plugins, you should have a look at get_plugins. glob is going to be relative to the current working directory (with will vary depending on your server setup) and is_plugin_active active takes a plugin_basename.

get_plugins will return an associative array with the plugin basenames as keys as the file header data as the values (in an array).

A few other notes:

admin_notices does not automagically format your notices to look pretty. You can wrap it your notice with <div class="error"> or <div class="updated"> to do that.

Always give your functions a unique prefix or put them in a namespace (PHP 5.3+ only).

Revised code:

add_action('admin_notices', 'wpse72637_show_names');
function wpse72637_show_names()
    $paths = array();

    foreach(get_plugins() as $p_basename => $plugin)
        $paths[] = "{$plugin['Name']}: " .
            (is_plugin_active($p_basename) ? 'Active' : 'Disabled');

    echo '<div class="updated"><p>', implode(' --- ', $paths), '<p></div>';
share|improve this answer
Great fix, sir. Didn't even know that get_plugins existed - that'll be handy for my next project. Out of curiosity, is there a way to print the output of functions (like var_dump) to a blank page? I'd like to do that so debugging is a little cleaner. – user1787531 Nov 15 '12 at 4:13
You can do something like this: var_dump(some_func()); die; or use var_export (die(var_export(some_func()));). Either works and will kill execution so you can study what's going on. Alternatively you could use something error_log. – chrisguitarguy Nov 15 '12 at 4:17
Sir, this is a +1 from me. – kaiser Nov 15 '12 at 9:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.