Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Craig Ralston on "Using get_plugins() to pass plugin file path to is_active_plugin()"

$
0
0

A rundown of my issue:
I am working with a file that lives in the root along with wp-config.php and such. I am requiring wp-admin/includes/plugin.php and wp-load.php and my goal is to retrieve plugin data quickly and easily from a site. I have been mostly successful in my attempts, so far but have hit a small bump that I am hoping someone can assist with. My initial function uses the array get_plugins() and I am using data from that but I also need to check which plugins are active/inactive. Looking at the Codex, is_active_plugin($plugin) seems to do exactly what I want - Check if the plugin is active. I don't want to specify a file path, obviously, because I am checking all plugins, so I've been trying to use the data from get_plugins() to pass the file path to is_active_plugin but nothing has been working. If I do a var_dump(get_plugins();), the path I need is the key but if I try to use the key, the first plugin is just repeated every time. I suspect this is due to that fact that the get_plugins() array has another array for each plugin. Every plugin appears as inactive.

function ws_plugin_list() {
    $all_plugins = get_plugins();
    echo '<ul style="list-style-type: none;">';
    foreach ($all_plugins as $plugin_item) { ?>
        <li>
            <a href="<?php echo $plugin_item['PluginURI']; ?>">
                     <?php echo $plugin_item['Title']; ?>
            </a>
        </li>
        <li>
            Version: <?php echo $plugin_item['Version']; ?><br />
            This plugin is currently <?php if (is_plugin_active(key($plugin_item))) { echo 'active'; } else { echo 'inactive'; } ?>
        </li>
        <br />
<?php }
    echo '</ul>';
}

Here is the var_dump(get_plugins()); - As you can see, something like the akismet/akismet.php is what I am trying to collect and pass to is_plugin_active().

array(3) { ["akismet/akismet.php"]=> array(11) { ["Name"]=> string(7) "Akismet" ["PluginURI"]=> string(31) "http://akismet.com/?return=true" ["Version"]=> string(5) "2.5.9" ["Description"]=> string(433) "Used by millions, Akismet is quite possibly the best way in the world to protect your blog from comment and trackback spam. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) Sign up for an Akismet API key, and 3) Go to your Akismet configuration page, and save your API key." ["Author"]=> string(10) "Automattic" ["AuthorURI"]=> string(40) "http://automattic.com/wordpress-plugins/" ["TextDomain"]=> string(0) "" ["DomainPath"]=> string(0) "" ["Network"]=> bool(false) ["Title"]=> string(7) "Akismet" ["AuthorName"]=> string(10) "Automattic" }

I apologize if this is not the correct place to ask my question.


Viewing all articles
Browse latest Browse all 8245

Trending Articles