点击更新按钮在WordPress中解压缩zip文件



我尝试在单击更新按钮后解压缩我的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

重试以解压缩文件。是否显示任何错误?

最新更新