通过在内部使用它,我使它能够正常工作add_attachment
钩子下面,但现在的问题是它运行在每一个媒体上传。
function unzip_icon_fonts( $post_ID ){
$file_path = get_attached_file( $post_ID );
require_once(ABSPATH . \'wp-admin/includes/file.php\');
WP_Filesystem();
$destination = wp_upload_dir();
$destination_path = $destination[\'path\'];
$unzipfile = unzip_file($file_path, $destination_path);
}
add_action( \'add_attachment\', \'unzip_icon_fonts\' );
我尝试将其限制在下面的特定自定义程序文件上载中,但它根本不起作用。
function unzip_icon_fonts( $post_ID ){
// If attachment ID equals Customizer file upload ID added with WP_Customize_Media_Control
if ( $post_ID == get_theme_mod(\'icon_fonts\', \'\') ) {
$file_path = get_attached_file( $post_ID );
require_once(ABSPATH . \'wp-admin/includes/file.php\');
WP_Filesystem();
$destination = wp_upload_dir();
$destination_path = $destination[\'path\'];
$unzipfile = unzip_file($file_path, $destination_path);
}
}
add_action( \'add_attachment\', \'unzip_icon_fonts\' );
我错过什么了吗?