Skip to content
Advertisement

Function get_plugins() cannot be execute

I’m trying to code simple php script which will return all plugins of WordPress.

My code:

<?php 
ini_set('display_errors', 'On');

include('../../../wp-admin/includes/plugin.php');

$all_plugins = get_plugins();

error_log( print_r( $all_plugins, true ) );

And my output is:

 Uncaught Error: Call to undefined function wp_cache_get() in /home/user/domains/mydomain.com/public_html/wp-admin/includes/plugin.php:273 Stack trace: #0 /home/user/domains/mydomain.com/public_html/wp-content/plugins/myplugin/versions.php(6): get_plugins() #1 {main} thrown in /home/user/domains/mydomain.com/public_html/wp-admin/includes/plugin.php on line 273

I used official example from: https://codex.wordpress.org/Function_Reference/get_plugins

I did:

  • change of PHP version from 7.2 to 5.6
  • set right permission of files
  • install WordPres once again

So my wordpress is totally fresh and I still have the same error. Somebody knows how to solve it?

Advertisement

Answer

To load all the WordPress functions you need to include the file wp-load.php:

require_once("../../../../wp-load.php");

and not the plugins one.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement