我点击更新按钮后尝试解压缩我的zip文件,但它没有正常工作吗?
function check_values($post_ID, $post_after, $post_before)
{
if ( !function_exists( 'unzip_file' ) )
{
require_once ABSPATH . '/wp-admin/includes/file.php';
}
$file = '/wp-content/themes/xyz/XML.zip';
$to = '/wp-content/themes/xyz/';
$result = unzip_file($file, $to);
}
add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function
您需要文件和目的地的完整路径。根据您正在构建的内容,可以使用内置函数来获取所需的路径。这是一个列出所有内容的链接:https://codex.wordpress.org/Determining_Plugin_and_Content_Directories
出于测试目的,您可以尝试使用ABSPATH。
$file = ABSPATH . '/wp-content/themes/xyz/XML.zip';
$to = ABSPATH . '/wp-content/themes/xyz/';
请记住,WordPress允许用户更改其主题文件夹的位置,因此使用正确的功能比硬编码路径更好。没有更多信息,我最好的猜测是你应该使用get_stylesheet_directory();
。
如果您没有启用调试,请重新创建问题:https://codex.wordpress.org/Debugging_in_WordPress
检查您的文件夹权限:https://codex.wordpress.org/Changing_File_Permissions
重试解压缩您的文件。是否显示任何错误?