Created
September 11, 2014 09:08
-
-
Save tjhole/205630e73a76f826733f to your computer and use it in GitHub Desktop.
WORDPRESS: Zip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zip_gallery() | |
{ | |
global $post; | |
$images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', )); | |
if ($images) { | |
$save = $post->post_title; | |
$zip = new ZipArchive; | |
if ($zip->open($save . '.zip', ZIPARCHIVE::CREATE) === true) { | |
foreach ($images as $image) { | |
$file = wp_get_attachment_url($image->ID, 'full', false, false); | |
$filename = pathinfo($file); | |
$zip->addFile($file, $filename); | |
} | |
$zip->close(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment