I want to run a PHP script that iterates over WordPress sites found in a certain folder and read the plugins info per each site using get_plugin function
In the code below, I try to require API functions inside the WP folder and use it to retrieve data. However, the problem is the multiple "require".
Sample code:
function get_sites_plugins() {
foreach($this->all_sites as $site_folder) {
$plugins = get_site_plugins($site_folder);
echo "Info for site $site_folder";
var_dump($plugins);
}
}
function get_site_plugins($site_folder) {
// define site path
$site_path = $CONST_SITES_DIR . $site_folder;
// defines ABSPATH
require("$site_path/wp-load.php");
// define get_plugins()
require ABSPATH . 'wp-admin/includes/plugin.php';
// PROBLEM: only first require works, need to "unrequire" but that's not possible.
// get plugins
$all_plugins = get_plugins();
return $all_plugins;
}
get_sites_plugins();
How do I achieve this?
Note that the PHP script running is on the same host server.
include
?