我想运行一个PHP脚本,迭代在特定文件夹中找到的WordPress站点,并使用get\\u plugin函数读取每个站点的插件信息
在下面的代码中,我尝试在WP文件夹中要求API函数,并使用它来检索数据。然而,问题是多重“需求”。
示例代码:
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();
我如何做到这一点?
Note 运行的PHP脚本位于同一主机服务器上。