0

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.

1
  • Have you tried include? – 5ervant Aug 4 '15 at 15:26
0

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).

0

Have you tried require-once function?

3
  • that can still cause problems if there are conflicting usages of hooks. – Mark Kaplun Aug 4 '15 at 4:15
  • yes, how do you think it would help in this case? it will not override the already defined constants / functions. – user2867106 Aug 4 '15 at 15:12
  • Are you dealing with a multi-sites WordPress or number of separate websites? In the first instance all plugins are in one folder, in the latter instance the require "function" should not be conflicting as it loads a new URL every time for each website. – Kalimah Aug 4 '15 at 23:44

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.