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");

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>';
  • 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
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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