PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | includes/class-updraft-smush-manager.php +39 -67 4.5.4 → 4.7.0 View file →
@@ -82,10 +82,8 @@
82 82
83 83 add_filter('manage_media_columns', array($this, 'manage_media_columns'));
84 84 add_action('manage_media_custom_column', array($this, 'manage_media_custom_column'), 10, 2);
85 85
86 - add_filter('is_protected_meta', array($this, 'is_protected_meta'), 10, 3);
87 -
88 86 // clean backup images cron action.
89 87 add_action('wpo_smush_clear_backup_images', array($this, 'clear_backup_images'));
90 88
91 89 // add filter for already compressed images by EWWW Image Optimizer.
@@ -162,14 +160,14 @@
162 160 }
163 161 $ext = WPO_Image_Utils::get_extension($file);
164 162 $allowed_extensions = WPO_Image_Utils::get_allowed_extensions();
165 163
166 - $compressed = get_post_meta($attachment_id, 'smush-complete', true) ? true : false;
167 - $has_backup = get_post_meta($attachment_id, 'original-file', true) ? true : false;
164 + $compressed = get_post_meta($attachment_id, '_wpo-smush-complete', true) ? true : false;
165 + $has_backup = get_post_meta($attachment_id, '_wpo-original-file', true) ? true : false;
168 166
169 - $smush_info = get_post_meta($attachment_id, 'smush-info', true);
170 - $smush_stats = get_post_meta($attachment_id, 'smush-stats', true);
171 - $marked = get_post_meta($attachment_id, 'smush-marked');
167 + $smush_info = get_post_meta($attachment_id, '_wpo-smush-info', true);
168 + $smush_stats = get_post_meta($attachment_id, '_wpo-smush-stats', true);
169 + $marked = get_post_meta($attachment_id, '_wpo-smush-marked');
172 170
173 171 $extract = array(
174 172 'blog_id' => get_current_blog_id(),
175 173 'post_id' => $attachment_id,
@@ -224,9 +222,9 @@
224 222 if (empty($nonce) || empty($subaction)) {
225 223 die('Security check failed');
226 224 }
227 225
228 - if (!current_user_can(WP_Optimize()->capability_required())) {
226 + if (!WP_Optimize()->current_user_can()) {
229 227 die('You are not allowed to run this command.');
230 228 }
231 229
232 230 $allowed_commands = Updraft_Smush_Manager_Commands::get_allowed_ajax_commands();
@@ -369,9 +367,9 @@
369 367 */
370 368 public function restore_single_image($image_id, $blog_id) {
371 369
372 370 $switched_blog = false;
373 - if (is_multisite() && current_user_can('manage_network_options')) {
371 + if (is_multisite() && WP_Optimize()->current_user_can('manage_network_options')) {
374 372 switch_to_blog($blog_id);
375 373 $switched_blog = true;
376 374 } elseif (is_multisite() && get_current_blog_id() != $blog_id) {
377 375 return new WP_Error('restore_backup_wrong_blog_id', __('The blog ID provided does not match the current blog.', 'wp-optimize'));
@@ -379,9 +377,9 @@
379 377
380 378 $error = false;
381 379
382 380 $image_path = get_attached_file($image_id);
383 - $backup_path = get_post_meta($image_id, 'original-file', true);
381 + $backup_path = get_post_meta($image_id, '_wpo-original-file', true);
384 382 $uploads_dir = wp_upload_dir();
385 383 $uploads_basedir = realpath($uploads_dir['basedir']);
386 384
387 385 if (false === $uploads_basedir) {
@@ -425,24 +423,24 @@
425 423 }
426 424 }
427 425
428 426 $backup_path = realpath($backup_path);
429 -
430 - if (!$backup_path || 0 !== strpos($backup_path, $uploads_basedir)) {
427 + if (!$backup_path || 0 !== strpos(trailingslashit(dirname($backup_path)), $uploads_basedir)) {
431 428 if ($switched_blog) {
432 429 restore_current_blog();
433 430 }
434 - return new WP_Error('restore_backup_issue', __('The backup file path is not correct.', 'wp-optimize'));
431 + return new WP_Error('restore_failed', __('The backup file path seems suspicious, and could not be deleted.', 'wp-optimize'));
435 432 }
436 433
434 +
437 435 if (!is_file($backup_path)) {
438 436 // Delete information about backup.
439 - delete_post_meta($image_id, 'original-file');
437 + delete_post_meta($image_id, '_wpo-original-file');
440 438 $error = new WP_Error('restore_backup_not_found', __('The backup was not found; it may have been deleted or was already restored', 'wp-optimize'));
441 439 } elseif (!wp_is_writable($image_path)) {
442 - $error = new WP_Error('restore_failed', __('The destination could not be written to.', 'wp-optimize').' '.__("Please check your folder's permissions", 'wp-optimize'));
440 + $error = new WP_Error('restore_failed', __('The destination could not be written to.', 'wp-optimize').' '.__("Please check your folder's permissions", 'wp-optimize'));
443 441 } elseif (!copy($backup_path, $image_path)) {
444 - $error = new WP_Error('restore_failed', __('The file could not be copied; check your PHP error logs for details', 'wp-optimize'));
442 + $error = new WP_Error('restore_failed', __('The file could not be copied; check your PHP error logs for details', 'wp-optimize'));
445 443 } elseif (!WP_Optimize_Utils::wp_delete_file($backup_path)) {
446 444 // translators: %s is the backup file path
447 445 $error = new WP_Error('restore_failed', sprintf(__('The backup file %s could not be deleted.', 'wp-optimize'), $backup_path));
448 446 }
@@ -449,12 +447,12 @@
449 447
450 448 if (!$error) {
451 449 // if backup image deleted successfully
452 450 // then delete from attachment meta associated smush data
453 - delete_post_meta($image_id, 'smush-complete');
454 - delete_post_meta($image_id, 'smush-stats');
455 - delete_post_meta($image_id, 'original-file');
456 - delete_post_meta($image_id, 'smush-info');
451 + delete_post_meta($image_id, '_wpo-smush-complete');
452 + delete_post_meta($image_id, '_wpo-smush-stats');
453 + delete_post_meta($image_id, '_wpo-original-file');
454 + delete_post_meta($image_id, '_wpo-smush-info');
457 455 }
458 456
459 457 if ($switched_blog) {
460 458 restore_current_blog();
@@ -497,9 +495,9 @@
497 495 $processed = 0;
498 496
499 497 if ($restore_backup) {
500 498 // get post ids those have backup meta field.
501 - $image_ids = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM `{$wpdb->postmeta}` WHERE meta_key = 'original-file' LIMIT %d;", $images_limit), ARRAY_A);
499 + $image_ids = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM `{$wpdb->postmeta}` WHERE meta_key = '_wpo-original-file' LIMIT %d;", $images_limit), ARRAY_A);
502 500
503 501 if (!empty($image_ids)) {
504 502 // run restore function for each found image.
505 503 foreach ($image_ids as $image) {
@@ -543,9 +541,9 @@
543 541 }
544 542
545 543 if ($result['completed']) {
546 544
547 - $smushed_images_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->postmeta}` WHERE meta_key='smush-complete' AND meta_value=1");
545 + $smushed_images_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->postmeta}` WHERE meta_key='_wpo-smush-complete' AND meta_value=1");
548 546 $result['smushed_images_count'] = $smushed_images_count;
549 547
550 548 if ($delete_only_backups_meta) {
551 549 if (is_multisite()) {
@@ -579,9 +577,9 @@
579 577 // clear all metas for smushed images after work completed.
580 578 // if $delete_only_backup_meta set to true then all meta fields was deleted in restore_single_image()
581 579 // and we don't need to delete metas for other images.
582 580 if (!$delete_only_backups_meta) {
583 - $wpdb->query("DELETE FROM `{$wpdb->postmeta}` WHERE meta_key IN ('smush-complete', 'smush-stats', 'original-file', 'smush-info');");
581 + $wpdb->query("DELETE FROM `{$wpdb->postmeta}` WHERE meta_key IN ('_wpo-smush-complete', '_wpo-smush-stats', '_wpo-original-file', '_wpo-smush-info');");
584 582 }
585 583 }
586 584
587 585 if (is_multisite()) {
@@ -698,12 +696,12 @@
698 696 }
699 697
700 698 if (is_multisite()) {
701 699 switch_to_blog($task->get_option('blog_id', 1));
702 - $stats = get_post_meta($attachment_id, 'smush-stats', true);
700 + $stats = get_post_meta($attachment_id, '_wpo-smush-stats', true);
703 701 restore_current_blog();
704 702 } else {
705 - $stats = get_post_meta($attachment_id, 'smush-stats', true);
703 + $stats = get_post_meta($attachment_id, '_wpo-smush-stats', true);
706 704 }
707 705
708 706 if (isset($stats['sizes-info'])) {
709 707
@@ -859,14 +857,14 @@
859 857 * @param WP_Post $post - a post object
860 858 */
861 859 public function render_smush_metabox($post) {
862 860
863 - $compressed = (bool) get_post_meta($post->ID, 'smush-complete', true);
864 - $has_backup = (bool) get_post_meta($post->ID, 'original-file', true);
861 + $compressed = (bool) get_post_meta($post->ID, '_wpo-smush-complete', true);
862 + $has_backup = (bool) get_post_meta($post->ID, '_wpo-original-file', true);
865 863
866 - $smush_info = get_post_meta($post->ID, 'smush-info', true);
867 - $smush_stats = get_post_meta($post->ID, 'smush-stats', true);
868 - $marked = get_post_meta($post->ID, 'smush-marked');
864 + $smush_info = get_post_meta($post->ID, '_wpo-smush-info', true);
865 + $smush_stats = get_post_meta($post->ID, '_wpo-smush-stats', true);
866 + $marked = get_post_meta($post->ID, '_wpo-smush-marked');
869 867
870 868 $options = Updraft_Smush_Manager()->get_smush_options();
871 869
872 870 $file = get_attached_file($post->ID);
@@ -1135,12 +1133,12 @@
1135 1133
1136 1134 foreach ($images as $image) {
1137 1135 if (is_multisite()) {
1138 1136 switch_to_blog($image['blog_id']);
1139 - $stats[] = get_post_meta($image['attachment_id'], 'smush-complete', true) ? 'success' : 'fail';
1137 + $stats[] = get_post_meta($image['attachment_id'], '_wpo-smush-complete', true) ? 'success' : 'fail';
1140 1138 restore_current_blog();
1141 1139 } else {
1142 - $stats[] = get_post_meta($image['attachment_id'], 'smush-complete', true) ? 'success' : 'fail';
1140 + $stats[] = get_post_meta($image['attachment_id'], '_wpo-smush-complete', true) ? 'success' : 'fail';
1143 1141 }
1144 1142 }
1145 1143
1146 1144 return array_count_values($stats);
@@ -1208,9 +1206,9 @@
1208 1206 $js_variables['cancel'] = esc_html__('Cancel', 'wp-optimize');
1209 1207 $js_variables['cancelling'] = esc_html__('Cancelling...', 'wp-optimize');
1210 1208 $js_variables['images_restored_successfully'] = esc_html__('The images were restored successfully', 'wp-optimize');
1211 1209 $js_variables['logo_src'] = esc_url(WPO_PLUGIN_URL.'images/notices/wp_optimize_logo.png');
1212 -
1210 +
1213 1211 wp_enqueue_script('block-ui-js', WPO_PLUGIN_URL.'includes/blockui/jquery.blockUI'.$min_or_not.'.js', array('jquery'), $enqueue_version);
1214 1212 wp_enqueue_script('wp-optimize-heartbeat-js', WPO_PLUGIN_URL.'js/heartbeat'.$min_or_not_internal.'.js', array('jquery'), $enqueue_version);
1215 1213 wp_localize_script('wp-optimize-heartbeat-js', 'wpo_heartbeat_ajax', array(
1216 1214 'ajaxurl' => admin_url('admin-ajax.php'),
@@ -1645,9 +1643,9 @@
1645 1643 *
1646 1644 * @return bool
1647 1645 */
1648 1646 public function is_compressed($attachment_id) {
1649 - return (true === (bool) get_post_meta($attachment_id, 'smush-complete', true));
1647 + return (true === (bool) get_post_meta($attachment_id, '_wpo-smush-complete', true));
1650 1648 }
1651 1649
1652 1650 /**
1653 1651 * Returns true if multisite
@@ -1663,9 +1661,13 @@
1663 1661 *
1664 1662 * @param int $post_id - WordPress Post ID
1665 1663 */
1666 1664 public function unscheduled_original_file_deletion($post_id) {
1667 - $the_original_file = get_post_meta($post_id, 'original-file', true);
1665 + $the_original_file = get_post_meta($post_id, '_wpo-original-file', true);
1666 + // If no original file meta exists, there is nothing to delete.
1667 + if (empty($the_original_file)) {
1668 + return;
1669 + }
1668 1670 $uploads_dir = wp_get_upload_dir();
1669 1671 $uploads_basedir = realpath($uploads_dir['basedir']);
1670 1672 if (!$uploads_basedir) return;
1671 1673 $uploads_basedir = trailingslashit($uploads_basedir);
@@ -1711,14 +1713,14 @@
1711 1713 'relation' => 'AND',
1712 1714 array(
1713 1715 'relation' => 'OR',
1714 1716 array(
1715 - 'key' => 'smush-complete',
1717 + 'key' => '_wpo-smush-complete',
1716 1718 'compare' => '!=',
1717 1719 'value' => '1',
1718 1720 ),
1719 1721 array(
1720 - 'key' => 'smush-complete',
1722 + 'key' => '_wpo-smush-complete',
1721 1723 'compare' => 'NOT EXISTS',
1722 1724 'value' => '',
1723 1725 ),
1724 1726 ),
@@ -1759,38 +1761,8 @@
1759 1761 'compare' => 'NOT EXISTS',
1760 1762 'value' => '',
1761 1763 ),
1762 1764 );
1763 - }
1764 -
1765 - /**
1766 - * Protects smush meta keys
1767 - *
1768 - * @param bool $protected Whether the key is considered protected
1769 - * @param string $meta_key Metadata key
1770 - * @param string $meta_type Type of metadata object
1771 - *
1772 - * @return bool
1773 - */
1774 - public function is_protected_meta($protected, $meta_key, $meta_type) {
1775 - if ('post' !== $meta_type) {
1776 - return $protected;
1777 - }
1778 -
1779 - $keys = array(
1780 - 'smush-complete',
1781 - 'smush-marked',
1782 - 'smush-info',
1783 - 'smush-stats',
1784 - 'original-file',
1785 - 'wpo-webp-conversion-complete',
1786 - );
1787 -
1788 - if (in_array($meta_key, $keys, true)) {
1789 - return true;
1790 - }
1791 -
1792 - return $protected;
1793 1765 }
1794 1766 }
1795 1767
1796 1768 /**