5

After seeing thousands of useful API functions in the WordPress core, I'm surprised to discover today that there ain't a function that would list the active plug-ins. I don't know you but I'm quite surprised at that.

I was wondering if there is a reason for missing that? If so, I'd like to know about it.

And, if there is a quick PHP snippet you know of that could give you a list of active plugins, ( the same way that a get_post_types('','names'); does for CPT's or get_taxonomies('','names'); does for CTs ), I'd appreciate it if you provide the code.

6

wp_get_active_and_valid_plugins()

get_plugins()

and get_option('active_plugins')

1
8

There multiple WordPress Apis for getting a list of plugins like OTP listed in his answer.

get_plugins() :Check the plugins directory and retrieve all plugin files with plugin data. Returns an array. Note: Only works on the admin side

Example:

function list_the_plugins() {
    $plugins = get_plugins();
        foreach ( $plugins as $plugin ) {
        var_dump( $plugin );
    }

Returns:

array
  'Name' => string 'WP Coda Slider' (length=14)
  'PluginURI' => string 'http://c3mdigital.com/wp-coda-slider/' (length=37)
  'Version' => string '0.3.2' (length=5)
  'Description' => string 'Add a jQuery Coda slider to any WordPress post or page' (length=54)
  'Author' => string 'c3mdigital' (length=10)
  'AuthorURI' => string 'http://c3mdigital.com/' (length=22)
  'TextDomain' => string '' (length=0)
  'DomainPath' => string '' (length=0)
  'Network' => boolean false
  'Title' => string 'WP Coda Slider' (length=14)
  'AuthorName' => string 'c3mdigital' (length=10)

get_option( 'active_plugins' ) Returns the path relative to wp-content/plugins of the plugin file:

Example:

function list_the_plugins() {
    $plugins = get_option ( 'active_plugins', array () );
    foreach ( $plugins as $plugin ) {
        echo "<li>$plugin</li>";
    }
}

Returns:

  • debug-bar-extender/debug-bar-extender.php
  • debug-bar/debug-bar.php
  • log-deprecated-notices/log-deprecated-notices.php
  • manage-post-schedule/manage-post-schedule.php
  • wp-coda-slider/wpcodaslider.php

Other API functions related to plugin status:

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.