function ewww_image_optimizer_scan_other() { global $wpdb; // initialize the $attachments variable for auxiliary images $attachments = null; // check if there is a previous bulk operation to resume if (get_option('ewww_image_optimizer_aux_resume')) { // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option $attachments = get_option('ewww_image_optimizer_aux_attachments'); } else { // collect a list of images from the current theme $child_path = get_stylesheet_directory(); $parent_path = get_template_directory(); $attachments = ewww_image_optimizer_image_scan($child_path); if ($child_path !== $parent_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path)); } // collect a list of images for buddypress if (!function_exists('is_plugin_active')) { // need to include the plugin library for the is_plugin_active function require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars')); } if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb')); } if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) { // scan the grand media folder for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media')); } if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path'))); } if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) { $slide_paths = array(); $sliders = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'ml-slider'"); $slides = $wpdb->get_col("\n\t\t\t\tSELECT wpposts.ID \n\t\t\t\tFROM {$wpdb->posts} wpposts \n\t\t\t\tINNER JOIN {$wpdb->term_relationships} term_relationships\n\t\t\t\t\t\tON wpposts.ID = term_relationships.object_id\n\t\t\t\tINNER JOIN {$wpdb->terms} wpterms \n\t\t\t\t\t\tON term_relationships.term_taxonomy_id = wpterms.term_id\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} term_taxonomy\n\t\t\t\t\t\tON wpterms.term_id = term_taxonomy.term_id\n\t\t\t\tWHERE \tterm_taxonomy.taxonomy = 'ml-slider'\n\t\t\t\t\tAND wpposts.post_type = 'attachment'\n\t\t\t\t"); foreach ($slides as $slide) { $type = get_post_meta($slide, 'ml-slider_type', true); $type = $type ? $type : 'image'; // backwards compatibility, fall back to 'image' if ($type != 'image') { continue; } $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true); if (ewww_image_optimizer_iterable($backup_sizes)) { foreach ($backup_sizes as $backup_size => $meta) { if (preg_match('/resized-/', $backup_size)) { $path = $meta['path']; $image_size = ewww_image_optimizer_filesize($path); if (!$image_size) { continue; } $already_optimized = ewww_image_optimizer_find_already_optimized($path); $mimetype = ewww_image_optimizer_mimetype($path, 'i'); if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) { $slide_paths[] = $path; } } } } } $attachments = array_merge($attachments, $slide_paths); } // collect a list of images in auxiliary folders provided by user if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) { if (ewww_image_optimizer_iterable($aux_paths)) { foreach ($aux_paths as $aux_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path)); } } } // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database update_option('ewww_image_optimizer_aux_attachments', $attachments, false); } return $attachments; }
function ewww_image_optimizer_scan_other() { global $wpdb; // $aux_resume = get_option('ewww_image_optimizer_aux_resume'); // initialize the $attachments variable for auxiliary images $attachments = null; // check the 'bulk resume' option // $resume = get_option('ewww_image_optimizer_aux_resume'); // check if there is a previous bulk operation to resume if (get_option('ewww_image_optimizer_aux_resume')) { // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option $attachments = get_option('ewww_image_optimizer_aux_attachments'); } else { // collect a list of images from the current theme $child_path = get_stylesheet_directory(); $parent_path = get_template_directory(); $attachments = ewww_image_optimizer_image_scan($child_path); if ($child_path !== $parent_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path)); } // collect a list of images for buddypress if (!function_exists('is_plugin_active')) { // need to include the plugin library for the is_plugin_active function require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars')); } if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb')); } if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) { // scan the grand media folder for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media')); } if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path'))); } if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) { $slide_paths = array(); $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids')); foreach ($sliders as $slider) { $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider)))); foreach ($slides as $slide) { $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true); $type = get_post_meta($slide, 'ml-slider_type', true); $type = $type ? $type : 'image'; // backwards compatibility, fall back to 'image' if ($type === 'image') { foreach ($backup_sizes as $backup_size => $meta) { if (preg_match('/resized-/', $backup_size)) { $path = $meta['path']; $image_size = filesize($path); $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE path LIKE %s AND image_size LIKE '{$image_size}'", $path); $optimized_query = $wpdb->get_results($query, ARRAY_A); if (!empty($optimized_query)) { foreach ($optimized_query as $image) { if ($image['path'] == $path) { // $ewww_debug .= "{$image['path']} does not match $path, continuing our search<br>"; $already_optimized = $image; } } } $mimetype = ewww_image_optimizer_mimetype($path, 'i'); if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) { $slide_paths[] = $path; } } } } } } $attachments = array_merge($attachments, $slide_paths); } // collect a list of images in auxiliary folders provided by user if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) { foreach ($aux_paths as $aux_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path)); } } // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database update_option('ewww_image_optimizer_aux_attachments', $attachments); } return $attachments; }
function ewww_image_optimizer_aux_images_script($hook) { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); // make sure we are being called from the proper page if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) { return; } session_write_close(); global $wpdb; if (!empty($_REQUEST['ewww_force'])) { ewwwio_debug_message('forcing re-optimize: true'); } // initialize the $attachments variable for auxiliary images $attachments = null; // check the 'bulk resume' option $resume = get_option('ewww_image_optimizer_aux_resume'); // check if there is a previous bulk operation to resume if (!empty($resume)) { ewwwio_debug_message('resuming from where we left off, no scanning needed'); // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option $attachments = get_option('ewww_image_optimizer_aux_attachments'); } else { ewwwio_debug_message('getting fresh list of files to optimize'); $attachments = array(); // collect a list of images from the current theme $child_path = get_stylesheet_directory(); $parent_path = get_template_directory(); $attachments = ewww_image_optimizer_image_scan($child_path); if ($child_path !== $parent_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path)); } if (!function_exists('is_plugin_active')) { // need to include the plugin library for the is_plugin_active function require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // collect a list of images for buddypress if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars')); } if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb')); } if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) { // scan the grand media folder for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media')); } if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path'))); } if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) { $slide_paths = array(); $slides = $wpdb->get_col("\n\t\t\t\tSELECT wpposts.ID \n\t\t\t\tFROM {$wpdb->posts} wpposts \n\t\t\t\tINNER JOIN {$wpdb->term_relationships} term_relationships\n\t\t\t\t\t\tON wpposts.ID = term_relationships.object_id\n\t\t\t\tINNER JOIN {$wpdb->terms} wpterms \n\t\t\t\t\t\tON term_relationships.term_taxonomy_id = wpterms.term_id\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} term_taxonomy\n\t\t\t\t\t\tON wpterms.term_id = term_taxonomy.term_id\n\t\t\t\tWHERE \tterm_taxonomy.taxonomy = 'ml-slider'\n\t\t\t\t\tAND wpposts.post_type = 'attachment'\n\t\t\t\t"); foreach ($slides as $slide) { $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true); $type = get_post_meta($slide, 'ml-slider_type', true); $type = $type ? $type : 'image'; // backwards compatibility, fall back to 'image' if ($type === 'image') { foreach ($backup_sizes as $backup_size => $meta) { if (preg_match('/resized-/', $backup_size)) { $path = $meta['path']; $image_size = ewww_image_optimizer_filesize($path); if (!$image_size) { continue; } $already_optimized = ewww_image_optimizer_find_already_optimized($path); $mimetype = ewww_image_optimizer_mimetype($path, 'i'); if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) { $slide_paths[] = $path; } } } } } $attachments = array_merge($attachments, $slide_paths); } // collect a list of images in auxiliary folders provided by user if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) { foreach ($aux_paths as $aux_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path)); } } // scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) { // retrieve the location of the wordpress upload folder $upload_dir = wp_upload_dir(); // retrieve the path of the upload folder $upload_path = $upload_dir['basedir']; $this_month = date('m'); $this_year = date('Y'); $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/")); if (class_exists('DateTime')) { $date = new DateTime(); $date->sub(new DateInterval('P1M')); $last_year = $date->format('Y'); $last_month = $date->format('m'); $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$last_year}/{$last_month}/")); } } // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database update_option('ewww_image_optimizer_aux_attachments', $attachments); ewwwio_debug_message('found ' . count($attachments) . ' images to optimize while scanning'); } ewww_image_optimizer_debug_log(); if (!empty($_REQUEST['ewww_scan'])) { echo count($attachments); ewwwio_memory(__FUNCTION__); die; } else { ewwwio_memory(__FUNCTION__); return; } }
function ewww_image_optimizer_aux_images_script($hook) { // make sure we are being called from the proper page if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['scan'])) { return; } global $ewww_debug; global $wpdb; $ewww_debug .= "<b>ewww_image_optimizer_aux_images_script()</b><br>"; // initialize the $attachments variable for auxiliary images $attachments = null; // check the 'bulk resume' option $resume = get_option('ewww_image_optimizer_aux_resume'); // check if there is a previous bulk operation to resume if (!empty($resume)) { // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option $attachments = get_option('ewww_image_optimizer_aux_attachments'); } else { // collect a list of images from the current theme $child_path = get_stylesheet_directory(); $parent_path = get_template_directory(); $attachments = ewww_image_optimizer_image_scan($child_path); if ($child_path !== $parent_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path)); } // collect a list of images in auxiliary folders provided by user if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) { foreach ($aux_paths as $aux_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path)); } } // collect a list of images for buddypress if (is_plugin_active('buddypress/bp-loader.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress/bp-loader.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars')); } if (is_plugin_active('buddypress-activity-plus/bpfb.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb')); } if (is_plugin_active('wp-symposium/wp-symposium.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('wp-symposium/wp-symposium.php')) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path'))); } if (is_plugin_active('ml-slider/ml-slider.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ml-slider/ml-slider.php')) { $slide_paths = array(); $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids')); foreach ($sliders as $slider) { $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider)))); foreach ($slides as $slide) { $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true); $type = get_post_meta($slide, 'ml-slider_type', true); $type = $type ? $type : 'image'; // backwards compatibility, fall back to 'image' if ($type === 'image') { foreach ($backup_sizes as $backup_size => $meta) { if (preg_match('/resized-/', $backup_size)) { $path = $meta['path']; $image_size = filesize($path); $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE BINARY path LIKE %s AND image_size LIKE '{$image_size}'", $path); $already_optimized = $wpdb->get_results($query); $mimetype = ewww_image_optimizer_mimetype($path, 'i'); if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) { $slide_paths[] = $path; } } } } } } $attachments = array_merge($attachments, $slide_paths); } // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database update_option('ewww_image_optimizer_aux_attachments', $attachments); } ewww_image_optimizer_debug_log(); // submit a couple variables to the javascript to work with $attachments = json_encode($attachments); if (!empty($_REQUEST['scan'])) { if (empty($attachments)) { _e('Nothing to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { echo $attachments; } die; } else { return; } }
function ewww_image_optimizer_aux_images_script($hook) { // make sure we are being called from the proper page if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) { return; } global $ewww_debug; global $wpdb; $ewww_debug .= "<b>ewww_image_optimizer_aux_images_script()</b><br>"; if (!empty($_REQUEST['ewww_force'])) { $ewww_debug .= "forcing re-optimize: true<br>"; } // initialize the $attachments variable for auxiliary images $attachments = null; // check the 'bulk resume' option $resume = get_option('ewww_image_optimizer_aux_resume'); // check if there is a previous bulk operation to resume if (!empty($resume)) { // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option $attachments = get_option('ewww_image_optimizer_aux_attachments'); } else { $attachments = array(); // collect a list of images from the current theme $child_path = get_stylesheet_directory(); $parent_path = get_template_directory(); $attachments = ewww_image_optimizer_image_scan($child_path); if ($child_path !== $parent_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path)); } if (!function_exists('is_plugin_active')) { // need to include the plugin library for the is_plugin_active function require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // collect a list of images for buddypress if (is_plugin_active('buddypress/bp-loader.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress/bp-loader.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars')); } if (is_plugin_active('buddypress-activity-plus/bpfb.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) { // get the value of the wordpress upload directory $upload_dir = wp_upload_dir(); // scan the 'avatars' and 'group-avatars' folders for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb')); } if (is_plugin_active('grand-media/grand-media.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('grand-media/grand-media.php')) { // scan the grand media folder for images $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media')); } if (is_plugin_active('wp-symposium/wp-symposium.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('wp-symposium/wp-symposium.php')) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path'))); } if (is_plugin_active('ml-slider/ml-slider.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ml-slider/ml-slider.php')) { $slide_paths = array(); $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids')); foreach ($sliders as $slider) { $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider)))); foreach ($slides as $slide) { $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true); $type = get_post_meta($slide, 'ml-slider_type', true); $type = $type ? $type : 'image'; // backwards compatibility, fall back to 'image' if ($type === 'image') { foreach ($backup_sizes as $backup_size => $meta) { if (preg_match('/resized-/', $backup_size)) { $path = $meta['path']; $image_size = filesize($path); $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE path LIKE %s AND image_size LIKE '{$image_size}'", $path); $optimized_query = $wpdb->get_results($query, ARRAY_A); if (!empty($optimized_query)) { foreach ($optimized_query as $image) { if ($image['path'] != $path) { $ewww_debug .= "{$image['path']} does not match {$path}, continuing our search<br>"; } else { $already_optimized = $image; } } } $mimetype = ewww_image_optimizer_mimetype($path, 'i'); if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) { $slide_paths[] = $path; } } } } } } $attachments = array_merge($attachments, $slide_paths); } // collect a list of images in auxiliary folders provided by user if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) { foreach ($aux_paths as $aux_path) { $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path)); } } // scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) { // retrieve the location of the wordpress upload folder $upload_dir = wp_upload_dir(); // retrieve the path of the upload folder $upload_path = $upload_dir['basedir']; $this_month = date('m'); $this_year = date('Y'); $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/")); if (class_exists('DateTime')) { $date = new DateTime(); $date->sub(new DateInterval('P1M')); $last_year = $date->format('Y'); $last_month = $date->format('m'); $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$last_year}/{$last_month}/")); } } // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database update_option('ewww_image_optimizer_aux_attachments', $attachments); } ewww_image_optimizer_debug_log(); // submit a couple variables to the javascript to work with $attachments = json_encode($attachments); if (!empty($_REQUEST['ewww_scan'])) { if (empty($attachments)) { _e('Nothing to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { echo $attachments; } ewwwio_memory(__FUNCTION__); die; } else { ewwwio_memory(__FUNCTION__); return; } }