/** * Manually process an image from the Media Library */ function ewww_image_optimizer_manual() { global $ewww_debug; $ewww_debug .= "<b>ewww_image_optimizer_manual()</b><br>"; // check permissions of current user $permissions = apply_filters('ewww_image_optimizer_manual_permissions', ''); if (FALSE === current_user_can($permissions)) { // display error message if insufficient permissions wp_die(__('You don\'t have permission to optimize images.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } // make sure we didn't accidentally get to this page without an attachment to work on if (FALSE === isset($_GET['ewww_attachment_ID'])) { // display an error message since we don't have anything to work on wp_die(__('No attachment ID was provided.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } // store the attachment ID value $attachment_ID = intval($_GET['ewww_attachment_ID']); // retrieve the existing attachment metadata $original_meta = wp_get_attachment_metadata($attachment_ID); // if the call was to optimize... if ($_REQUEST['action'] === 'ewww_image_optimizer_manual_optimize') { // call the optimize from metadata function and store the resulting new metadata $new_meta = ewww_image_optimizer_resize_from_meta_data($original_meta, $attachment_ID); } elseif ($_REQUEST['action'] === 'ewww_image_optimizer_manual_restore') { $new_meta = ewww_image_optimizer_restore_from_meta_data($original_meta, $attachment_ID); } // update the attachment metadata in the database wp_update_attachment_metadata($attachment_ID, $new_meta); // store the referring webpage location $sendback = wp_get_referer(); // sanitize the referring webpage location $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); // send the user back where they came from wp_redirect($sendback); // we are done, nothing to see here ewwwio_memory(__FUNCTION__); exit(0); }
/** * Manually process an image from the Media Library */ function ewww_image_optimizer_manual() { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); global $ewww_defer; $ewww_defer = false; // check permissions of current user $permissions = apply_filters('ewww_image_optimizer_manual_permissions', ''); if (FALSE === current_user_can($permissions)) { // display error message if insufficient permissions wp_die(esc_html__('You do not have permission to optimize images.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } // make sure we didn't accidentally get to this page without an attachment to work on if (FALSE === isset($_GET['ewww_attachment_ID'])) { // display an error message since we don't have anything to work on wp_die(esc_html__('No attachment ID was provided.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } session_write_close(); // store the attachment ID value $attachment_ID = intval($_GET['ewww_attachment_ID']); if (empty($_REQUEST['ewww_manual_nonce']) || !wp_verify_nonce($_REQUEST['ewww_manual_nonce'], "ewww-manual-{$attachment_ID}")) { wp_die(esc_html__('Access denied.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } // retrieve the existing attachment metadata $original_meta = wp_get_attachment_metadata($attachment_ID); // if the call was to optimize... if ($_REQUEST['action'] === 'ewww_image_optimizer_manual_optimize') { // call the optimize from metadata function and store the resulting new metadata $new_meta = ewww_image_optimizer_resize_from_meta_data($original_meta, $attachment_ID); } elseif ($_REQUEST['action'] === 'ewww_image_optimizer_manual_restore') { $new_meta = ewww_image_optimizer_restore_from_meta_data($original_meta, $attachment_ID); } global $ewww_attachment; $ewww_attachment['id'] = $attachment_ID; $ewww_attachment['meta'] = $new_meta; add_filter('w3tc_cdn_update_attachment_metadata', 'ewww_image_optimizer_w3tc_update_files'); // update the attachment metadata in the database wp_update_attachment_metadata($attachment_ID, $new_meta); ewww_image_optimizer_debug_log(); // store the referring webpage location $sendback = wp_get_referer(); // sanitize the referring webpage location $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); // send the user back where they came from wp_redirect($sendback); // we are done, nothing to see here ewwwio_memory(__FUNCTION__); exit(0); }