Retrieve data from multiple Wordpress sites using PHP script

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.

Topic get-plugin-data wp-load.php php plugins Wordpress

Category Web


Have you tried require-once function?


Write a bash script (or any other shell script) to loop ocer the site and in php just write the detection for a single site and output the value to standard output or a file.

Or use http://wp-cli.org/ (which essentially does for you the php code from the paragraph above).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.