我需要获取对$wp\\u filesystem对象的引用。在下面的测试中,var\\u dump($wp\\u filesystem)返回NULL。要正确设置$wp\\U文件系统,还需要哪些其他文件?
我一直在期待,因为它在文件中调用。php,加载该文件就足以加载该对象。
<?php
require(\'../../../wp-blog-header.php\');
require(\'../../../wp-admin/includes/file.php\');
$mytest = somefunction();
function somefunction() {
global $wp_filesystem;
var_dump($wp_filesystem);
return;
}
?>
更新:我发现我可以直接调用WP\\u Filesystem()来创建它,所以我可以很好地提取zip,现在的问题是,zip文件被复制到目标文件夹,而不是像我的ZipArchive方法那样被删除。
require(\'../../../wp-blog-header.php\');
require(\'../../../wp-admin/includes/file.php\');
function openZip($file_to_open) {
global $target;
global $wp_filesystem;
if(class_exists(\'ZipArchive\'))
{
$zip = new ZipArchive();
$x = $zip->open($file_to_open);
if($x === true)
{
$zip->extractTo($target);
$zip->close();
unlink($file_to_open);
} else {
die("There was a problem. Please try again!");
}
}
else
{
WP_Filesystem();
$my_dirs = \'\'; //What should this be? I\'m already passing he $target directory
_unzip_file_pclzip($file_to_open, $target, $my_dirs);
}
}