我有一个插件,它将使用以下代码在wp内容/上传中创建一个文件夹:
//Generate stuff on plugin activation
function sample_plugin_activate() {
$upload_dir = wp_upload_dir();
$files = array(
array(
\'base\' => $upload_dir[\'basedir\'] . \'/sample_folder\',
\'file\' => \'index.html\',
\'content\' => \'\'
)
);
foreach ( $files as $file ) {
if ( wp_mkdir_p( $file[\'base\'] ) && ! file_exists( trailingslashit( $file[\'base\'] ) . $file[\'file\'] ) ) {
if ( $file_handle = @fopen( trailingslashit( $file[\'base\'] ) . $file[\'file\'], \'w\' ) ) {
fwrite( $file_handle, $file[\'content\'] );
fclose( $file_handle );
}
}
}
}
register_activation_hook( __FILE__, \'sample_plugin_activate\' );
稍后,在我的脚本中,我将在此文件夹中生成XML文件:
//Save XML
$UploadDir = wp_upload_dir();
$UploadURL = $UploadDir[\'basedir\'];
$location = realpath($UploadURL . "/sample_folder/");
$xmlfile = $location.\'/\'.$orderId.\'.xml\';
$test = file_put_contents($xmlfile, $xml);
这很好用。我的问题是,我正在运行多站点设置。这个
sample_folder 是在wp content/uploads/sample\\u文件夹中生成的,但一旦我在多站点上,wp\\u upload\\u dir()将返回上载文件夹,如下所示:wp content/uploads/sites/12/显然,此路径中没有sample\\u文件夹,这将导致我的插件出错。
我怎样才能解决这个问题?