function ewww_image_optimizer_bulk_flag($delay = 0) { $ids = null; // if there is an operation to resume, get those IDs from the db if (get_option('ewww_image_optimizer_bulk_flag_resume')) { $ids = get_option('ewww_image_optimizer_bulk_flag_attachments'); // otherwise, if we are on the main bulk optimize page, just get all the IDs available } else { global $wpdb; $ids = $wpdb->get_col("SELECT pid FROM {$wpdb->flagpictures} ORDER BY sortorder ASC"); // store the IDs to optimize in the options table of the db update_option('ewww_image_optimizer_bulk_flag_attachments', $ids, false); } // set the resume flag to indicate the bulk operation is in progress update_option('ewww_image_optimizer_bulk_flag_resume', 'true'); // need this file to work with flag meta require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php'; if (!ewww_image_optimizer_iterable($ids)) { WP_CLI::line(__('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); return; } foreach ($ids as $id) { sleep($delay); // record the starting time for the current image (in microseconds) $started = microtime(true); // retrieve the meta for the current ID $meta = new flagMeta($id); $file_path = $meta->image->imagePath; // optimize the full-size version $fres = ewww_image_optimizer($file_path, 3, false, false, true); $meta->image->meta_data['ewww_image_optimizer'] = $fres[1]; // let the user know what happened WP_CLI::line(__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " " . esc_html($meta->image->filename)); WP_CLI::line(sprintf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($fres[1]))); if (!empty($meta->image->meta_data['webview'])) { // determine path of the webview $web_path = $meta->image->webimagePath; $wres = ewww_image_optimizer($web_path, 3, false, true); $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1]; WP_CLI::line(sprintf(__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($wres[1]))); } $thumb_path = $meta->image->thumbPath; // optimize the thumbnail $tres = ewww_image_optimizer($thumb_path, 3, false, true); $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1]; // and let the user know the results WP_CLI::line(sprintf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($tres[1]))); flagdb::update_image_meta($id, $meta->image->meta_data); // determine how much time the image took to process $elapsed = microtime(true) - $started; // and output it to the user WP_CLI::line(sprintf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN), $elapsed)); // retrieve the list of attachments left to work on $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments'); // take the first image off the list if (!empty($attachments)) { array_shift($attachments); } // and send the list back to the db update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments, false); } // reset the bulk flags in the db update_option('ewww_image_optimizer_bulk_flag_resume', ''); update_option('ewww_image_optimizer_bulk_flag_attachments', '', false); // and let the user know we are done WP_CLI::success(__('Finished Optimization!', EWWW_IMAGE_OPTIMIZER_DOMAIN)); }
function ewww_flag_bulk_loop() { if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) { wp_die(__('Cheatin’ eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } if (!empty($_REQUEST['sleep'])) { sleep($_REQUEST['sleep']); } // need this file to work with flag meta require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php'; // record the starting time for the current image (in microseconds) $started = microtime(true); $id = $_POST['attachment']; // get the image meta for the current ID $meta = new flagMeta($id); $file_path = $meta->image->imagePath; // optimize the full-size version $fres = ewww_image_optimizer($file_path, 3, false, false, ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full')); $meta->image->meta_data['ewww_image_optimizer'] = $fres[1]; // let the user know what happened printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename)); printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]); $thumb_path = $meta->image->thumbPath; // optimize the thumbnail $tres = ewww_image_optimizer($thumb_path, 3, false, true); $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1]; // and let the user know the results printf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]); flagdb::update_image_meta($id, $meta->image->meta_data); // determine how much time the image took to process $elapsed = microtime(true) - $started; // and output it to the user printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed); // retrieve the list of attachments left to work on $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments'); // take the first image off the list if (!empty($attachments)) { array_shift($attachments); } // and send the list back to the db update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments); die; }
function flagCreateNewThumb() { global $wpdb; // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct FlAG capability if (!current_user_can('FlAG Manage gallery')) { die('-1'); } require_once dirname(dirname(__FILE__)) . '/flag-config.php'; include_once flagGallery::graphic_library(); $flag_options = get_option('flag_options'); $id = (int) $_POST['id']; $picture = flagdb::find_image($id); $x = round($_POST['x'] * $_POST['rr'], 0); $y = round($_POST['y'] * $_POST['rr'], 0); $w = round($_POST['w'] * $_POST['rr'], 0); $h = round($_POST['h'] * $_POST['rr'], 0); $thumb = new flag_Thumbnail($picture->imagePath, TRUE); $thumb->crop($x, $y, $w, $h); if ($flag_options['thumbFix']) { if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) { $thumb->resize($flag_options['thumbWidth'], 0); } else { $thumb->resize(0, $flag_options['thumbHeight']); } } else { $thumb->resize($flag_options['thumbWidth'], $flag_options['thumbHeight']); } if ($thumb->save($picture->thumbPath, 100)) { //read the new sizes $new_size = @getimagesize($picture->thumbPath); $size['width'] = $new_size[0]; $size['height'] = $new_size[1]; // add them to the database flagdb::update_image_meta($picture->pid, array('thumbnail' => $size)); echo "OK"; } else { header('HTTP/1.1 500 Internal Server Error'); echo "KO"; } exit; }
function ewww_flag_bulk_loop() { global $ewww_defer; $ewww_defer = false; $output = array(); $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', ''); if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) { $output['error'] = esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN); echo json_encode($output); die; } session_write_close(); // find out if our nonce is on it's last leg/tick $tick = wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk'); if ($tick === 2) { $output['new_nonce'] = wp_create_nonce('ewww-image-optimizer-bulk'); } else { $output['new_nonce'] = ''; } // need this file to work with flag meta require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php'; // record the starting time for the current image (in microseconds) $started = microtime(true); // retrieve the list of attachments left to work on $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments'); $id = array_shift($attachments); // get the image meta for the current ID $meta = new flagMeta($id); $file_path = $meta->image->imagePath; // optimize the full-size version $fres = ewww_image_optimizer($file_path, 3, false, false, true); $ewww_status = get_transient('ewww_image_optimizer_cloud_status'); if (!empty($ewww_status) && preg_match('/exceeded/', $ewww_status)) { $output['error'] = esc_html__('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN); echo json_encode($output); die; } $meta->image->meta_data['ewww_image_optimizer'] = $fres[1]; // let the user know what happened $output['results'] = sprintf("<p>" . esc_html__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename)); $output['results'] .= sprintf(esc_html__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($fres[1])); if (!empty($meta->image->meta_data['webview'])) { // determine path of the webview $web_path = $meta->image->webimagePath; $wres = ewww_image_optimizer($web_path, 3, false, true); $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1]; $output['results'] .= sprintf(esc_html__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($wres[1])); } $thumb_path = $meta->image->thumbPath; // optimize the thumbnail $tres = ewww_image_optimizer($thumb_path, 3, false, true); $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1]; // and let the user know the results $output['results'] .= sprintf(esc_html__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($tres[1])); flagdb::update_image_meta($id, $meta->image->meta_data); // determine how much time the image took to process $elapsed = microtime(true) - $started; // and output it to the user $output['results'] .= sprintf(esc_html__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed); // send the list back to the db update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments, false); if (!empty($attachments)) { $next_attachment = array_shift($attachments); $next_file = $this->ewww_flag_bulk_filename($next_attachment); $loading_image = plugins_url('/images/wpspin.gif', __FILE__); if ($next_file) { $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <b>{$next_file}</b> <img src='{$loading_image}' alt='loading'/></p>"; } else { $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <img src='{$loading_image}' alt='loading'/></p>"; } } echo json_encode($output); die; }
/** * Maybe import some meta data to the database. The functions checks the flag 'saved' * and if based on compat reason (pre V0.40) we save then some meta datas to the database * * @param int $id * @return mixed result */ function maybe_import_meta($id) { require_once FLAG_ABSPATH . 'lib/meta.php'; $meta_obj = new flagMeta($id); if ($meta_obj->image->meta_data['saved'] != true) { $common = $meta_obj->get_common_meta(); //this flag will inform us that the import is already one time performed $common['saved'] = true; $result = flagdb::update_image_meta($id, $common); } else { return false; } return $result; }
function ewww_image_optimizer_import_loop() { // verify that an authorized user has started the optimizer if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk')) { wp_die(__('Cheatin’ eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } global $wpdb; global $ewww_debug; // echo "starting usage: " . memory_get_usage() . "<br>"; // retrieve the time when the optimizer starts // $started = microtime(true); $import_finished = false; $import_status = get_option('ewww_image_optimizer_import_status'); $attachments = $wpdb->get_results("SELECT posts.ID,metas.meta_value FROM {$wpdb->postmeta} metas INNER JOIN {$wpdb->posts} posts ON posts.ID = metas.post_id WHERE posts.post_mime_type LIKE '%image%' AND metas.meta_key = '_wp_attachment_metadata' AND metas.meta_value LIKE '%ewww_image_optimizer%' LIMIT {$import_status['media']}, 100", ARRAY_N); // echo "after loading metadata: " . memory_get_usage() . "<br>"; if (count($attachments) === 0) { $import_finished = true; } else { $import_status['media'] += count($attachments); } $already_optimized = array(); // echo "after loading already optimized: " . memory_get_usage() . "<br>"; $ewww_debug .= "importing " . count($attachments) . " attachments<br>"; $insert_query = "INSERT INTO {$wpdb->ewwwio_images} (path, image_size, orig_size, results, temp) VALUES "; $rows = array(); foreach ($attachments as $attachment) { $record = array(); $gallery_type = 0; $id = $attachment[0]; $meta = unserialize($attachment[1]); if (empty($attachment) || empty($attachment[1])) { continue; } list($attachment, $upload_path) = ewww_image_optimizer_attachment_path($meta, $id); if ('ims_image' == get_post_type($id)) { $gallery_type = 6; } // make sure the meta actually contains data for ewww_image_optimizer if (empty($meta['ewww_image_optimizer'])) { $prev_results = ''; } else { $prev_results = $meta['ewww_image_optimizer']; } $record = ewww_image_optimizer_import_file($attachment, $prev_results, $already_optimized); if (!empty($record)) { $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)"; } // resized versions, so we can continue if (isset($meta['sizes'])) { $record = array(); $ewww_debug .= "processing resizes<br>"; // meta sizes don't contain a path, so we calculate one if ($gallery_type === 6) { $base_dir = dirname($attachment) . '/_resized/'; } else { $base_dir = dirname($attachment) . '/'; } foreach ($meta['sizes'] as $size => $data) { $resize_path = $base_dir . $data['file']; $ewww_debug .= "current resize: {$resize_path}<br>"; // make sure the meta actually contains data for ewww_image_optimizer if (empty($data['ewww_image_optimizer'])) { $prev_results = ''; } else { $prev_results = $data['ewww_image_optimizer']; } $record = ewww_image_optimizer_import_file($resize_path, $prev_results, $already_optimized); if (!empty($record)) { $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)"; } } } ewww_image_optimizer_debug_log(); } $import_count = $import_status['media']; //nextgen import if ($import_finished && isset($import_status['nextgen'])) { $import_finished = false; $images = $wpdb->get_results("SELECT pid,meta_data,filename,galleryid FROM {$wpdb->nggpictures} WHERE meta_data LIKE '%ewww_image_optimizer%' LIMIT {$import_status['nextgen']}, 100", ARRAY_N); if (count($images) === 0) { $import_finished = true; } else { $import_status['nextgen'] += count($images); } $galleries = $wpdb->get_results("SELECT gid,path FROM {$wpdb->nggallery}", ARRAY_N); // creating the 'registry' object for working with nextgen $registry = C_Component_Registry::get_instance(); // creating a database storage object from the 'registry' object $storage = $registry->get_utility('I_Gallery_Storage'); $sizes = $storage->get_image_sizes(); foreach ($images as $image) { $record = array(); $gallery_path = ''; foreach ($galleries as $gallery) { if ($gallery[0] == $image[3]) { $gallery_path = trailingslashit($gallery[1]); } } $meta = unserialize($image[1]); // get an array of sizes available for the $image foreach ($sizes as $size) { // get the absolute path if ($size === 'full' || $size === 'original' || $size === 'image') { if (!empty($meta['ewww_image_optimizer'])) { $file_path = ABSPATH . $gallery_path . $image[2]; $ewww_debug .= "nextgen path generated: {$file_path}<br>"; $record = ewww_image_optimizer_import_file($file_path, $meta['ewww_image_optimizer'], $already_optimized); } } elseif (!empty($meta[$size]['ewww_image_optimizer'])) { if (isset($meta[$size]['filename'])) { $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . $meta[$size]['filename']; } else { $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . 'thumbs_' . $image[2]; } $ewww_debug .= "nextgen path generated: {$file_path}<br>"; $record = ewww_image_optimizer_import_file($file_path, $meta[$size]['ewww_image_optimizer'], $already_optimized); } elseif (!empty($meta['ewww_image_optimizer'])) { if (isset($meta[$size]['filename'])) { $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . $meta[$size]['filename']; } else { $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . 'thumbs_' . $image[2]; } $ewww_debug .= "nextgen path generated: {$file_path}<br>"; $meta[$size]['ewww_image_optimizer'] = __('Unknown Savings', EWWW_IMAGE_OPTIMIZER_DOMAIN); nggdb::update_image_meta($image[0], $meta); $record = ewww_image_optimizer_import_file($file_path, $meta[$size]['ewww_image_optimizer'], $already_optimized); } if (!empty($record)) { $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)"; } } ewww_image_optimizer_debug_log(); } $import_count += $import_status['nextgen']; } // fla gallery import if ($import_finished && isset($import_status['flag'])) { $import_finished = false; $images = $wpdb->get_results("SELECT pid,meta_data,filename,galleryid FROM {$wpdb->flagpictures} WHERE meta_data LIKE '%ewww_image_optimizer%' LIMIT {$import_status['flag']}, 100", ARRAY_N); $galleries = $wpdb->get_results("SELECT gid,path FROM {$wpdb->flaggallery}", ARRAY_N); if (count($images) === 0) { $import_finished = true; } else { $import_status['flag'] += count($images); } // need this file to work with flag meta foreach ($images as $image) { $record = array(); $gallery_path = ''; foreach ($galleries as $gallery) { if ($gallery[0] == $image[3]) { $gallery_path = trailingslashit($gallery[1]); } } // get the image meta for the current ID $meta = unserialize($image[1]); $file_path = ABSPATH . $gallery_path . $image[2]; $ewww_debug .= "flagallery path generated: {$file_path}<br>"; if (!empty($meta['ewww_image_optimizer'])) { $record = ewww_image_optimizer_import_file($file_path, $meta['ewww_image_optimizer']); if (!empty($record)) { $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)"; } $thumb_path = ABSPATH . $gallery_path . 'thumbs/thumbs_' . $image[2]; if (empty($meta['thumbnail']['ewww_image_optimizer'])) { $meta['thumbnail']['ewww_image_optimizer'] = __('Unknown Savings', EWWW_IMAGE_OPTIMIZER_DOMAIN); // update the image metadata in the db flagdb::update_image_meta($id, $meta); $record = ewww_image_optimizer_import_file($thumb_path, __('Unknown Savings', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } else { $record = ewww_image_optimizer_import_file($thumb_path, $meta['thumbnail']['ewww_image_optimizer']); } if (!empty($record)) { $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)"; } } ewww_image_optimizer_debug_log(); } $import_count += $import_status['flag']; } if (!empty($rows)) { $wpdb->query($insert_query . implode(', ', $rows)); $rows = array(); } // echo "after we are done: " . memory_get_usage() . "<br>"; if ($import_finished) { update_option('ewww_image_optimizer_imported', true); update_option('ewww_image_optimizer_import_status', ''); $wpdb->query("ALTER TABLE {$wpdb->ewwwio_images} DROP temp"); echo "<b>" . __('Finished importing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b>"; } else { update_option('ewww_image_optimizer_import_status', $import_status); echo $import_count; } // $elapsed = microtime(true) - $started; // echo "<br>importing images took $elapsed seconds<br>"; die; }
function ewww_flag_bulk_loop() { global $ewww_defer; $ewww_defer = false; $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', ''); if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) { wp_die(__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } if (!empty($_REQUEST['ewww_sleep'])) { sleep($_REQUEST['ewww_sleep']); } // need this file to work with flag meta require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php'; // record the starting time for the current image (in microseconds) $started = microtime(true); $id = $_POST['ewww_attachment']; // get the image meta for the current ID $meta = new flagMeta($id); $file_path = $meta->image->imagePath; // optimize the full-size version $fres = ewww_image_optimizer($file_path, 3, false, false, true); global $ewww_exceed; if (!empty($ewww_exceed)) { echo '-9exceeded'; die; } $meta->image->meta_data['ewww_image_optimizer'] = $fres[1]; // let the user know what happened printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename)); printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]); if (!empty($meta->image->meta_data['webview'])) { // determine path of the webview $web_path = $meta->image->webimagePath; $wres = ewww_image_optimizer($web_path, 3, false, true); $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1]; printf(__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $wres[1]); } $thumb_path = $meta->image->thumbPath; // optimize the thumbnail $tres = ewww_image_optimizer($thumb_path, 3, false, true); $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1]; // and let the user know the results printf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]); flagdb::update_image_meta($id, $meta->image->meta_data); // determine how much time the image took to process $elapsed = microtime(true) - $started; // and output it to the user printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed); // retrieve the list of attachments left to work on $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments'); // take the first image off the list if (!empty($attachments)) { array_shift($attachments); } // and send the list back to the db update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments); die; }
function ewww_flag_bulk_loop() { if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) { wp_die(__('Cheatin’ eh?')); } // need this file to work with flag meta require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php'; // record the starting time for the current image (in microseconds) $started = microtime(true); $id = $_POST['attachment']; // get the image meta for the current ID $meta = new flagMeta($id); $file_path = $meta->image->imagePath; // optimize the full-size version $fres = ewww_image_optimizer($file_path, 3, false, false); // and store the results in the metadata flagdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1])); // let the user know what happened printf("<p>Optimized image: <strong>%s</strong><br>", esc_html($meta->image->filename)); printf("Full size – %s<br>", $fres[1]); $thumb_path = $meta->image->thumbPath; // optimize the thumbnail $tres = ewww_image_optimizer($thumb_path, 3, false, true); // and let the user know the results printf("Thumbnail – %s<br>", $tres[1]); // determine how much time the image took to process $elapsed = microtime(true) - $started; // and output it to the user echo "Elapsed: " . round($elapsed, 3) . " seconds</p>"; // retrieve the list of attachments left to work on $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments'); // take the first image off the list array_shift($attachments); // and send the list back to the db update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments); die; }