0

Any idea why the following code

function my_plugin_load()
{
    get_plugins();
}
add_action( 'plugins_loaded', 'my_plugin_load' );

Throws this error?

Fatal error: Call to undefined function get_plugins()

Shouldn't get_plugins() be defined after the plugins_loaded hook is fired? If not, what would be the proper hook to call? (This hook should initiate the plugin's bootstrap/load process)

  • 1
    Have you looked at the examples on the get_plugins codex page? – Milo Jun 16 '14 at 22:00
  • @Milo yes, that example would be one solution, but I was wondering if there was a solution that doesn't require me to explicitly include the file. – Yoav Kadosh Jun 16 '14 at 22:06
  • 2
    There is no way to "not include the file". The codex explains that the function is, really, only designed for use in the admin side of WordPress - not for themes. If you want to use it in your theme go ahead and include the file as shown. – funwhilelost Jun 17 '14 at 1:13
3

Possibly you're trying to use that code in a non-admin page. The functon get_plugins is only available on admin side and if you ant to use it somewhere else you have to load the file "plugin.php" manually.

To solve this error add that check at the beginning of your function:

    if ( ! function_exists( 'get_plugins' ) ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }

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.