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 | wp-optimize.php +96 -22 4.5.4 → 4.7.0 View file →
@@ -2,9 +2,9 @@
2 2 /**
3 3 Plugin Name: WP-Optimize - Clean, Compress, Cache
4 4 Plugin URI: https://teamupdraft.com/wp-optimize
5 5 Description: WP-Optimize makes your site fast and efficient. It cleans the database, compresses images and caches pages. Fast sites attract more traffic and users.
6 -Version: 4.5.4
6 +Version: 4.7.0
7 7 Requires at least: 4.9
8 8 Requires PHP: 7.2
9 9 Update URI: https://wordpress.org/plugins/wp-optimize/
10 10 Author: TeamUpdraft, DavidAnderson
@@ -17,9 +17,9 @@
17 17 if (!defined('ABSPATH')) die('No direct access allowed');
18 18
19 19 // Check to make sure if WP_Optimize is already call and returns.
20 20 if (!class_exists('WP_Optimize')) :
21 -define('WPO_VERSION', '4.5.4');
21 +define('WPO_VERSION', '4.7.0');
22 22 define('WPO_PLUGIN_URL', plugin_dir_url(__FILE__));
23 23 define('WPO_PLUGIN_MAIN_PATH', plugin_dir_path(__FILE__));
24 24 define('WPO_PLUGIN_SLUG', plugin_basename(__FILE__));
25 25 define('WPO_PREMIUM_NOTIFICATION', false);
@@ -120,9 +120,9 @@
120 120 * Add action for display Images > Compress images tab.
121 121 */
122 122 add_action('wp_optimize_admin_page_wpo_images_smush', array($this, 'admin_page_wpo_images_smush'));
123 123
124 - include_once(WPO_PLUGIN_MAIN_PATH.'includes/updraftcentral.php');
124 + include_once(WPO_PLUGIN_MAIN_PATH.'includes/updraftcentral/updraftcentral.php');
125 125
126 126 include_once(WPO_PLUGIN_MAIN_PATH.'includes/backward-compatibility-functions.php');
127 127
128 128 register_shutdown_function(array($this, 'log_fatal_errors'));
@@ -246,9 +246,9 @@
246 246 require_once($class_file);
247 247 return;
248 248 }
249 249 }
250 -
250 +
251 251 if ('Minify_HTML' === $class_name) {
252 252 require_once WPO_PLUGIN_MAIN_PATH.'vendor/mrclay/minify/lib/Minify/HTML.php';
253 253 }
254 254 }
@@ -264,12 +264,15 @@
264 264 'compatibility',
265 265 'includes',
266 266 'includes/tables',
267 267 'includes/list-tables',
268 + 'includes/dashboard',
268 269 'includes/gravatars',
270 + 'includes/lcp',
269 271 'minify',
270 272 'optimizations',
271 273 'webp',
274 + 'includes/updraftcentral',
272 275 );
273 276 }
274 277
275 278 /**
@@ -363,9 +366,9 @@
363 366
364 367 public function admin_page_wpo_images_smush() {
365 368 $options = Updraft_Smush_Manager()->get_smush_options();
366 369 $custom = 90 >= $options['image_quality'] && 65 <= $options['image_quality'];
367 - $sites = WP_Optimize()->get_sites();
370 + $sites = $this->get_sites();
368 371 $compression_server_hint = Updraft_Smush_Manager()->get_compression_server_hint();
369 372 $this->include_template('images/smush.php', false, array('smush_options' => $options, 'custom' => $custom, 'sites' => $sites, 'does_server_allow_local_webp_conversion' => $this->get_server_compatibility_instance()->does_server_allow_local_webp_conversion(), 'compression_server_hint' => $compression_server_hint));
370 373 $this->add_smush_popup_template();
371 374 }
@@ -384,13 +387,18 @@
384 387 /**
385 388 * Adds 3rd party plugin compatibilities.
386 389 */
387 390 public function load_compatibilities() {
391 + global $wp_version;
388 392
389 393 if (class_exists('Polylang')) {
390 394 WPO_Polylang_Compatibility::instance();
391 395 }
392 396
397 + if (version_compare($wp_version, '5.2', '<')) {
398 + WPO_WP_Kses_Compatibility::instance();
399 + }
400 +
393 401 WPO_Page_Builder_Compatibility::instance();
394 402 WPO_KD_Submissions_Compatibility::instance();
395 403
396 404 if (class_exists('Custom_Permalinks')) {
@@ -548,8 +556,17 @@
548 556 wp_enqueue_style('wp-optimize-global', WPO_PLUGIN_URL.'css/wp-optimize-global'.$min_or_not_internal.'.css', array(), $enqueue_version);
549 557
550 558 // load scripts and styles only on WP-Optimize pages.
551 559 if (!$this->is_wpo_page()) return;
560 +
561 + wp_enqueue_script( 'jquery-ui-tooltip' );
562 + // Defeat other plugins/themes which dump their jQuery UI CSS onto our settings page
563 + wp_deregister_style('jquery-ui');
564 + wp_enqueue_style('jquery-ui', WPO_PLUGIN_URL.'css/jquery-ui.custom' . $min_or_not_internal . '.css', array(), $enqueue_version);
565 +
566 +
567 + wp_enqueue_script('select2', WPO_PLUGIN_URL . 'js/select2/select2' . $min_or_not . '.js', array('jquery'), $enqueue_version);
568 + wp_enqueue_style('select2', WPO_PLUGIN_URL . 'css/select2/select2' . $min_or_not . '.css', array(), $enqueue_version);
552 569
553 570 wp_enqueue_script('jquery-serialize-json', WPO_PLUGIN_URL.'js/serialize-json/jquery.serializejson'.$min_or_not.'.js', array('jquery'), $enqueue_version);
554 571
555 572 wp_register_script('updraft-queue-js', WPO_PLUGIN_URL.'js/queue'.$min_or_not_internal.'.js', array(), $enqueue_version);
@@ -567,9 +584,9 @@
567 584
568 585 $js_variables = $this->wpo_js_translations();
569 586 $js_variables['loggers_classes_info'] = $this->get_loggers_classes_info();
570 587 wp_localize_script('wp-optimize-admin-js', 'wpoptimize', $js_variables);
571 -
588 +
572 589 do_action('wpo_premium_scripts_styles', $min_or_not_internal, $min_or_not, $enqueue_version);
573 590
574 591 $status_report_dependencies = array('wp-optimize-admin-js');
575 592
@@ -589,11 +606,11 @@
589 606 *
590 607 * @return void
591 608 */
592 609 public function frontend_enqueue_scripts() {
593 - if (!current_user_can('manage_options') || !is_admin_bar_showing()) return;
610 + if (!$this->current_user_can('manage_options') || !is_admin_bar_showing()) return;
594 611 $enqueue_version = $this->get_enqueue_version();
595 - $min_or_not_internal = WP_Optimize()->get_min_or_not_internal_string();
612 + $min_or_not_internal = $this->get_min_or_not_internal_string();
596 613
597 614 // Register or enqueue common scripts
598 615 wp_enqueue_style('wp-optimize-global', WPO_PLUGIN_URL.'css/wp-optimize-global'.$min_or_not_internal.'.css', array(), $enqueue_version);
599 616 }
@@ -690,9 +707,9 @@
690 707 WPO_Deactivation::actions();
691 708 return;
692 709 }
693 710
694 - if (is_admin() && current_user_can($this->capability_required())) {
711 + if (is_admin() && $this->current_user_can()) {
695 712 WP_Optimize_Heartbeat::get_instance();
696 713 }
697 714
698 715 if ($this->get_server_compatibility_instance()->does_server_handle_cache()) {
@@ -717,9 +734,9 @@
717 734 add_action('auto_option_settings', array($this->get_options(), 'auto_option_settings'));
718 735 }
719 736
720 737 // load defaults
721 - WP_Optimize()->get_options()->set_default_options();
738 + $this->get_options()->set_default_options();
722 739
723 740 // Initialize loggers.
724 741 add_action('init', array($this, 'setup_loggers'));
725 742
@@ -910,9 +927,9 @@
910 927 $pagenow = $GLOBALS['pagenow'];
911 928
912 929 $this->register_template_directories();
913 930
914 - if (('index.php' === $pagenow && current_user_can('update_plugins')) || ('index.php' === $pagenow && defined('WP_OPTIMIZE_FORCE_DASHNOTICE') && WP_OPTIMIZE_FORCE_DASHNOTICE)) {
931 + if (('index.php' === $pagenow && $this->current_user_can('update_plugins')) || ('index.php' === $pagenow && defined('WP_OPTIMIZE_FORCE_DASHNOTICE') && WP_OPTIMIZE_FORCE_DASHNOTICE)) {
915 932 $options = $this->get_options();
916 933
917 934 $dismissed_until = $options->get_option('dismiss_dash_notice_until', 0);
918 935
@@ -984,14 +1001,35 @@
984 1001 *
985 1002 * @return string
986 1003 */
987 1004 public function capability_required() {
988 - $capability = 'manage_options';
1005 + $capability = is_multisite() ? 'manage_network_options' : 'manage_options';
1006 +
989 1007 $filtered_capability = apply_filters('wp_optimize_capability_required', $capability);
1008 +
990 1009 return is_string($filtered_capability) ? $filtered_capability : $capability;
991 1010 }
992 1011
993 1012 /**
1013 + * Check if the current user has a given capability.
1014 + * If no capability is provided, it checks for the default capability required to access WP-Optimize.
1015 + *
1016 + * @param string|null $capability The capability to check. Null = use default.
1017 + * @return bool
1018 + */
1019 + public function current_user_can($capability = null) {
1020 + if (null === $capability) {
1021 + $capability = $this->capability_required(); // falls back to default
1022 + }
1023 +
1024 + if (current_user_can($capability)) {
1025 + return true;
1026 + }
1027 +
1028 + return false;
1029 + }
1030 +
1031 + /**
994 1032 * Returns array of translations used in javascript code.
995 1033 *
996 1034 * @return array
997 1035 */
@@ -1062,12 +1100,21 @@
1062 1100 'hide' => __('Hide', 'wp-optimize'),
1063 1101 'please_wait' => __('Please wait a moment...', 'wp-optimize'),
1064 1102 'clipboard_failed' => __('Copy to clipboard failed, please do it manually', 'wp-optimize'),
1065 1103 'clipboard_success' => __('System status has been copied to the clipboard', 'wp-optimize'),
1104 + 'high_table_count_threshold' => WP_Optimizer::HIGH_TABLE_COUNT_THRESHOLD,
1105 + // translators: 1: starting table count, 2: ending table count
1106 + 'loading_tables_in_batches' => esc_html__('Loading tables %1$s to %2$s', 'wp-optimize'),
1107 + // translators: %s time to finish
1108 + 'time_left' => esc_html__('Aproximate time to finish: %s', 'wp-optimize'),
1109 + 'done_reloading' => esc_html__('Done, reloading', 'wp-optimize'),
1066 1110 'show_information' => __('Show information', 'wp-optimize'),
1067 1111 'hide_information' => __('Hide information', 'wp-optimize'),
1068 1112 'data_not_available' => __('Not available', 'wp-optimize'),
1069 - 'something_wrong_try_again' => __('Something went wrong; please try again.', 'wp-optimize')
1113 + 'something_wrong_try_again' => __('Something went wrong; please try again.', 'wp-optimize'),
1114 + 'db_tables_scan_pending_list' => __('Your database tables need to be scanned before they can be listed.', 'wp-optimize'),
1115 + 'db_tables_scan_pending_optimize' => __('Your database tables need to be scanned before they can be optimized.', 'wp-optimize'),
1116 + 'db_tables_scan_button' => __('Scan tables', 'wp-optimize')
1070 1117 );
1071 1118 $filtered_translations = apply_filters('wpo_js_translations', $translations);
1072 1119 return is_array($filtered_translations) ? $filtered_translations : $translations;
1073 1120 }
@@ -1081,19 +1128,24 @@
1081 1128 public function plugin_settings_link($links) {
1082 1129
1083 1130 $admin_page_url = $this->get_options()->admin_page_url();
1084 1131 $settings_page_url = $this->get_options()->admin_page_url('wpo_settings');
1132 + $database_page_url = $this->get_options()->admin_page_url('wpo_database');
1085 1133
1086 1134 if (!self::is_premium()) {
1087 - $premium_link = '<a href="' . esc_url($this->premium_version_link) . '&utm_content=plugin-page' . '" target="_blank">' . __('Premium', 'wp-optimize') . '</a>';
1135 + $premium_link = '<a href="' . esc_url($this->premium_version_link) . '&utm_content=plugin-page' . '" target="_blank">' . esc_html__('Premium', 'wp-optimize') . '</a>';
1088 1136 array_unshift($links, $premium_link);
1089 1137 }
1090 1138
1091 - $settings_link = '<a href="' . esc_url($settings_page_url) . '">' . __('Settings', 'wp-optimize') . '</a>';
1139 + $settings_link = '<a href="' . esc_url($settings_page_url) . '">' . esc_html__('Settings', 'wp-optimize') . '</a>';
1092 1140 array_unshift($links, $settings_link);
1093 1141
1094 - $optimize_link = '<a href="' . esc_url($admin_page_url) . '">' . __('Optimize', 'wp-optimize') . '</a>';
1142 + $optimize_link = '<a href="' . esc_url($database_page_url) . '">' . esc_html__('Optimize', 'wp-optimize') . '</a>';
1095 1143 array_unshift($links, $optimize_link);
1144 +
1145 + $dashboard_link = '<a href="' . esc_url($admin_page_url) . '">' . esc_html__('Overview', 'wp-optimize') . '</a>';
1146 + array_unshift($links, $dashboard_link);
1147 +
1096 1148 return $links;
1097 1149 }
1098 1150
1099 1151 /**
@@ -1196,15 +1248,15 @@
1196 1248 }
1197 1249
1198 1250 add_action('wpo_cron_event2', array($this, 'cron_action'));
1199 1251 $result = wp_schedule_event((current_time("timestamp", 0) + $this_time - $gmt_offset), $schedule_type, 'wpo_cron_event2');
1200 - WP_Optimize()->log('running wp_schedule_event()');
1252 + $this->log('running wp_schedule_event()');
1201 1253 if (is_wp_error($result)) {
1202 1254 $error_msg = $result->get_error_message();
1203 - WP_Optimize()->log($error_msg);
1204 - WP_Optimize()->log(print_r($result, true)); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- Using for debugging purpose, logged into separate file
1255 + $this->log($error_msg);
1256 + $this->log(print_r($result, true)); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- Using for debugging purpose, logged into separate file
1205 1257 } else {
1206 - WP_Optimize()->log($result);
1258 + $this->log($result);
1207 1259 }
1208 1260 }
1209 1261 }
1210 1262 }
@@ -1210,13 +1262,31 @@
1210 1262 }
1211 1263 }
1212 1264
1213 1265 /**
1214 - * Clears all cron events
1266 + * Unschedules WP-Optimize cron events on deactivation.
1215 1267 *
1216 1268 * @return void
1217 1269 */
1218 1270 public function wpo_cron_deactivate() {
1271 + if (is_multisite()) {
1272 + $sites = $this->get_sites();
1273 + foreach ($sites as $site) {
1274 + switch_to_blog($site->blog_id);
1275 + $this->unschedule_wpo_cron_jobs();
1276 + restore_current_blog();
1277 + }
1278 + } else {
1279 + $this->unschedule_wpo_cron_jobs();
1280 + }
1281 + }
1282 +
1283 + /**
1284 + * Unschedules all WP-Optimize cron jobs on the current site.
1285 + *
1286 + * @return void
1287 + */
1288 + private function unschedule_wpo_cron_jobs() {
1219 1289 $cron_jobs = _get_cron_array();
1220 1290 foreach ($cron_jobs as $job) {
1221 1291 foreach (array_keys($job) as $hook) {
1222 1292 if (preg_match('/^wpo_/', $hook)) wp_unschedule_hook($hook);
@@ -1262,8 +1332,12 @@
1262 1332 /**
1263 1333 * Run updates on plugin activation.
1264 1334 */
1265 1335 public function run_updates() {
1336 +
1337 + if (!defined('WPO_CACHE_FILES_DIR')) define('WPO_CACHE_FILES_DIR', untrailingslashit(WP_CONTENT_DIR).'/cache/wpo-cache');
1338 +
1339 + require_once(WPO_PLUGIN_MAIN_PATH . 'cache/file-based-page-cache-functions.php');
1266 1340 include_once(WPO_PLUGIN_MAIN_PATH.'includes/class-wp-optimize-updates.php');
1267 1341 WP_Optimize_Updates::check_updates();
1268 1342 }
1269 1343
@@ -1985,9 +2059,9 @@
1985 2059 /**
1986 2060 * Adds compress popup template
1987 2061 */
1988 2062 public function add_smush_popup_template() {
1989 - if (current_user_can($this->capability_required())) {
2063 + if ($this->current_user_can()) {
1990 2064 $compression_server_hint = Updraft_Smush_Manager()->get_compression_server_hint();
1991 2065 $this->include_template('images/smush-popup.php', false, array('compression_server_hint' => $compression_server_hint));
1992 2066 }
1993 2067 }