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-wp-optimize-commands.php +175 -47 4.6.0 → 4.7.0 View file →
@@ -372,13 +372,18 @@
372 372 private function load_action_hooks_for_content($section_id) {
373 373 $wpo = WP_Optimize();
374 374 $wpo_admin = $wpo->get_admin_instance();
375 375
376 + // dashboard
377 + if ('dashboard' === $section_id) {
378 + add_action('wp_optimize_admin_page_WP-Optimize_dashboard', array($wpo_admin, 'output_dashboard'), 20);
379 + }
380 +
376 381 // Database
377 382 if ('database' === $section_id) {
378 - add_action('wp_optimize_admin_page_WP-Optimize_optimize', array($wpo_admin, 'output_database_optimize_tab'), 20);
379 - add_action('wp_optimize_admin_page_WP-Optimize_tables', array($wpo_admin, 'output_database_tables_tab'), 20);
380 - add_action('wp_optimize_admin_page_WP-Optimize_settings', array($wpo_admin, 'output_database_settings_tab'), 20);
383 + add_action('wp_optimize_admin_page_wpo_database_optimize', array($wpo_admin, 'output_database_optimize_tab'), 20);
384 + add_action('wp_optimize_admin_page_wpo_database_tables', array($wpo_admin, 'output_database_tables_tab'), 20);
385 + add_action('wp_optimize_admin_page_wpo_database_settings', array($wpo_admin, 'output_database_settings_tab'), 20);
381 386 }
382 387
383 388 // Images
384 389 if ('images' === $section_id) {
@@ -453,9 +458,9 @@
453 458 */
454 459 private function get_section_to_tab_name($section_id) {
455 460 $tab = '';
456 461 switch ($section_id) {
457 - case 'database':
462 + case 'dashboard':
458 463 $tab = 'WP-Optimize';
459 464 break;
460 465 default:
461 466 $tab = 'wpo_'.$section_id;
@@ -505,9 +510,9 @@
505 510 * @param ?string $message_key The key to use to query any translatable message if applicable
506 511 * @param array $additional_data Any additional data to return
507 512 * @return WP_Error
508 513 */
509 - private function request_error($code, $message_key = null, $additional_data = array()) {
514 + public function request_error($code, $message_key = null, $additional_data = array()) {
510 515 global $updraftcentral_host_plugin;
511 516
512 517 $error_message = $updraftcentral_host_plugin->retrieve_show_message($code);
513 518 if (!is_null($message_key) && $code !== $message_key) {
@@ -726,8 +731,12 @@
726 731 $optimization = $this->optimizer->get_optimization($optimization_id, $data);
727 732
728 733 $result = is_a($optimization, 'WP_Optimization') ? $optimization->do_optimization() : null;
729 734
735 + if (null !== $result) {
736 + WP_Optimize()->get_options()->update_option('last-optimized', time());
737 + }
738 +
730 739 $results = array(
731 740 'result' => $result,
732 741 'messages' => array(),
733 742 'errors' => array(),
@@ -862,9 +871,22 @@
862 871 *
863 872 * @return array
864 873 */
865 874 public function get_database_tabs() {
866 - return array_merge(array('optimizations' => $this->get_optimizations_table(), 'does_server_allow_table_optimization' => WP_Optimize()->get_server_compatibility_instance()->does_server_allow_table_optimization()), $this->get_table_list());
875 + $optimizer = $this->optimizer;
876 + $scan_pending = $optimizer->is_table_count_too_high() && !$optimizer->is_large_table_count_scan_complete();
877 +
878 + $result = array(
879 + 'optimizations' => $this->get_optimizations_table(),
880 + 'does_server_allow_table_optimization' => WP_Optimize()->get_server_compatibility_instance()->does_server_allow_table_optimization(),
881 + 'scan_pending' => $scan_pending,
882 + );
883 +
884 + if (!$scan_pending) {
885 + $result = array_merge($result, $this->get_table_list());
886 + }
887 +
888 + return $result;
867 889 }
868 890
869 891 /**
870 892 * Do action wp_optimize_after_optimizations
@@ -955,13 +977,28 @@
955 977 *
956 978 * @return array
957 979 */
958 980 public function get_gzip_compression_status() {
959 - $status = WP_Optimize()->get_gzip_compression()->is_gzip_compression_enabled(true);
981 + $status = WP_Optimize()->get_gzip_compression()->is_gzip_compression_enabled(false);
960 982 return is_wp_error($status) ? array('error' => __('We could not determine if Gzip compression is enabled.', 'wp-optimize'), 'code' => $status->get_error_code(), 'message' => $status->get_error_message()) : array('status' => $status);
961 983 }
962 984
963 985 /**
986 + * Get compression test results html formatted
987 + *
988 + * @return array
989 + */
990 + public function get_compression_test_results_html() {
991 + $results_html = WP_Optimize()->get_gzip_compression()->get_compression_test_results_html();
992 + $gzip_compression_control_panel = WP_Optimize_Admin::instance()->get_gzip_compression_control_panel();
993 +
994 + return array(
995 + 'results_html' => $results_html,
996 + 'gzip_compression_control_panel' => $gzip_compression_control_panel,
997 + );
998 + }
999 +
1000 + /**
964 1001 * Import WP-Optimize settings.
965 1002 *
966 1003 * @param array $params array with 'settings' item where 'settings' json-encoded string.
967 1004 *
@@ -1175,8 +1212,64 @@
1175 1212 );
1176 1213 }
1177 1214
1178 1215 /**
1216 + * Create background tasks and execute it in sequenced AJAX calls
1217 + *
1218 + * @return array
1219 + */
1220 + public function load_tables_in_batches() {
1221 + $optimizer = WP_Optimizer::instance();
1222 + $options = WP_Optimize()->get_options();
1223 +
1224 + $start_clean = $optimizer->maybe_restart_scan_job();
1225 +
1226 + if (true == (bool) $start_clean) {
1227 +
1228 + $tables = array();
1229 +
1230 + $tables_count = $optimizer->scan_job_init();
1231 +
1232 + $offset = 0;
1233 + while ($offset < $tables_count) {
1234 + $optimizer->add_load_tables_task($offset);
1235 +
1236 + $offset += WP_Optimizer::HIGH_TABLE_COUNT_THRESHOLD;
1237 + }
1238 + $optimizer->flush_tasks();
1239 + } else {
1240 + $tables = $options->get_option(WP_Optimizer::TABLES_LIST_OPTION_NAME);
1241 + $tables = is_array($tables) ? $tables : array();
1242 + $tables_count = $options->get_option(WP_Optimizer::TABLES_LIST_COUNT_OPTION_NAME);
1243 + $tables_count = false !== $tables_count ? $tables_count : 0;
1244 + }
1245 +
1246 + $optimizer->do_next_load_table_task();
1247 +
1248 + if (!$optimizer->is_task_queue_empty() || $start_clean) {
1249 + $continue = true;
1250 + } else {
1251 + $continue = false;
1252 + }
1253 +
1254 + $done = 0;
1255 + if (false !== $tables) {
1256 + $done = count($tables);
1257 + }
1258 +
1259 + if (false === $tables_count) {
1260 + $tables_count = 0;
1261 + }
1262 +
1263 + return array(
1264 + 'success' => true,
1265 + 'continue' => $continue,
1266 + 'total' => $tables_count,
1267 + 'done' => $done
1268 + );
1269 + }
1270 +
1271 + /**
1179 1272 * Build the HTML for the status report tab
1180 1273 *
1181 1274 * @return array
1182 1275 */
@@ -1359,9 +1452,9 @@
1359 1452 $table_info['Formatted_Data_free'] = $wp_optimize->format_size($tablestatus->Data_free);
1360 1453 $table_info['Data_should_be_cleared'] = intval($tablestatus->Data_free) > $small_overhead_size ? 1 : 0;
1361 1454 $table_info['wp_core_table'] = $tablestatus->wp_core_table;
1362 1455
1363 - $table_list[] = $table_info;
1456 + $table_list[$tablestatus->Name] = $table_info;
1364 1457
1365 1458 $row_usage += $tablestatus->Rows;
1366 1459 $data_usage += $tablestatus->Data_length;
1367 1460 $index_usage += $tablestatus->Index_length;
@@ -1440,9 +1533,9 @@
1440 1533
1441 1534 $trackbacks = $options->get_option('trackbacks_action', array());
1442 1535 $comments = $options->get_option('comments_action', array());
1443 1536
1444 - $gzip_compression_enabled = WP_Optimize()->get_gzip_compression()->is_gzip_compression_enabled(true);
1537 + $gzip_compression_enabled = WP_Optimize()->get_gzip_compression()->is_gzip_compression_enabled(false);
1445 1538
1446 1539 $settings = array(
1447 1540 'scheduled_cleanup' => 'true' === $options->get_option('schedule'),
1448 1541 'backup_enabled' => 'true' === $options->get_option('enable-auto-backup', 'false'),
@@ -1592,14 +1685,21 @@
1592 1685 $optimization_data['run_sort_order'] = $optimization->get_run_sort_order();
1593 1686
1594 1687 // Check if the DOM is optimize-db to generate a list of tables.
1595 1688 if ('optimize-db' == $optimization_data['dom_id']) {
1596 - $table_list = $this->optimizer->get_table_information();
1597 -
1598 - // Make sure that optimization_table_inno_db is set.
1599 - if ($table_list['inno_db_tables'] > 0 && 0 === $table_list['is_optimizable'] && 0 === $table_list['non_inno_db_tables']) {
1689 + // Disable optimization when too many tables exist but the batch scan hasn't run yet.
1690 + // Running it now would silently optimize 0 tables because get_tables() returns empty.
1691 + if ($this->optimizer->is_table_count_too_high() && !$this->optimizer->is_large_table_count_scan_complete()) {
1600 1692 $optimization_data['disable_optimization_button'] = true;
1601 1693 $optimization_data['activated'] = '';
1694 + } else {
1695 + $table_list = $this->optimizer->get_table_information();
1696 +
1697 + // Make sure that optimization_table_inno_db is set.
1698 + if ($table_list['inno_db_tables'] > 0 && 0 === $table_list['is_optimizable'] && 0 === $table_list['non_inno_db_tables']) {
1699 + $optimization_data['disable_optimization_button'] = true;
1700 + $optimization_data['activated'] = '';
1701 + }
1602 1702 }
1603 1703 }
1604 1704
1605 1705 $optimization_data['id'] = $id;
@@ -1678,9 +1778,9 @@
1678 1778 * Get all status data.
1679 1779 *
1680 1780 * @return array
1681 1781 */
1682 - private function get_all_status_data() {
1782 + public function get_all_status_data() {
1683 1783 $wp_optimize = WP_Optimize();
1684 1784
1685 1785 $retention_enabled = $this->options->get_option('retention-enabled', 'false') === 'true';
1686 1786 $retention_period = $this->options->get_option('retention-period', '2');
@@ -1689,8 +1789,9 @@
1689 1789 $revisions_retention_enabled = $this->options->get_option('revisions-retention-enabled', 'false') === 'true';
1690 1790 $revisions_retention_count = $this->options->get_option('revisions-retention-count', '2');
1691 1791
1692 1792 $last_optimized = $this->options->get_option('last-optimized', 'Never');
1793 + $last_optimized_ts = $last_optimized;
1693 1794
1694 1795 if (!empty($last_optimized) && is_numeric($last_optimized)) {
1695 1796 $last_optimized = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_optimized + (get_option('gmt_offset') * HOUR_IN_SECONDS));
1696 1797 }
@@ -1695,8 +1796,9 @@
1695 1796 $last_optimized = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_optimized + (get_option('gmt_offset') * HOUR_IN_SECONDS));
1696 1797 }
1697 1798
1698 1799 $scheduled_optimizations_enabled = false;
1800 + $scheduled_optimizations = array();
1699 1801
1700 1802 if (WP_Optimize::is_premium()) {
1701 1803 $wp_optimize_premium = WP_Optimize_Premium();
1702 1804 $scheduled_optimizations = $wp_optimize_premium->get_scheduled_optimizations();
@@ -1742,8 +1844,9 @@
1742 1844 }
1743 1845
1744 1846 return array(
1745 1847 'last_optimized' => $last_optimized,
1848 + 'last_optimized_ts' => $last_optimized_ts,
1746 1849 'total_cleaned' => $total_cleaned,
1747 1850 'total_cleanup_size' => $total_cleanup_size,
1748 1851 'corrupted_tables_count' => $corrupted_tables_count,
1749 1852 'admin_page_url' => $admin_page_url,
@@ -1752,8 +1855,9 @@
1752 1855 'revisions_retention_enabled' => $revisions_retention_enabled,
1753 1856 'revisions_retention_count' => $revisions_retention_count,
1754 1857 'scheduled_optimizations_enabled' => $scheduled_optimizations_enabled,
1755 1858 'next_optimization_timestamp' => $next_optimization_timestamp,
1859 + 'scheduled_optimizations' => $scheduled_optimizations
1756 1860 );
1757 1861 }
1758 1862
1759 1863 /**
@@ -2088,12 +2192,16 @@
2088 2192 'is_premium' => $is_premium,
2089 2193 'data' => array(),
2090 2194 );
2091 2195 $scheduled_optimizations_enabled = false;
2196 + $last_optimized_timestamp = (int) $this->options->get_option('last-optimized', 0);
2197 + $next_optimization_timestamp = 0;
2092 2198 $wp_optimize = WP_Optimize();
2199 + $is_udc_request = $wp_optimize->is_updraft_central_request();
2093 2200
2094 2201 if (!$is_premium) {
2095 - $enabled = 'true' === $this->options->get_option('schedule');
2202 + $schedule_enabled = $this->options->get_option('schedule');
2203 + $scheduled_optimizations_enabled = 'true' === $schedule_enabled;
2096 2204
2097 2205 $schedule_type_saved_id = $this->options->get_option('schedule-type', 'wpo_weekly');
2098 2206
2099 2207 // Backwards compatibility:
@@ -2118,15 +2226,15 @@
2118 2226 $optimizations = $this->optimizer->sort_optimizations($this->optimizer->get_optimizations());
2119 2227
2120 2228 $optimizations_data = array();
2121 2229
2122 - $does_server_allow_table_optimization = WP_Optimize()->get_server_compatibility_instance()->does_server_allow_table_optimization();
2230 + $does_server_allow_table_optimization = $wp_optimize->get_server_compatibility_instance()->does_server_allow_table_optimization();
2123 2231
2124 2232 foreach ($optimizations as $id => $optimization) {
2125 2233 if (empty($optimization->available_for_auto)) continue;
2126 2234
2127 2235 if ('optimizetables' == $id && false === $does_server_allow_table_optimization) continue;
2128 -
2236 +
2129 2237 $auto_id = $optimization->get_auto_id();
2130 2238
2131 2239 $auto_dom_id = 'wp-optimize-auto-'.$auto_id;
2132 2240
@@ -2135,33 +2243,18 @@
2135 2243 $optimizations_data[] = array(
2136 2244 'id' => $auto_id,
2137 2245 'dom_id' => $auto_dom_id,
2138 2246 'activated' => $setting_activated,
2139 - 'label' => $optimization->get_auto_option_description(),
2247 + 'label' => $optimization->settings_label(),
2140 2248 );
2141 2249 }
2142 2250
2143 - $next_optimization_timestamp = 0;
2144 -
2145 - $scheduled_optimizations_enabled = $this->options->get_option('schedule', 'false') == 'true';
2146 -
2147 - if ($scheduled_optimizations_enabled) {
2148 - $next_optimization_timestamp = apply_filters('wpo_cron_next_event', wp_next_scheduled('wpo_cron_event2'));
2149 -
2150 - if ($next_optimization_timestamp) {
2151 -
2152 - $next_optimization_timestamp = $next_optimization_timestamp + 60 * 60 * get_option('gmt_offset');
2153 - }
2154 - }
2155 -
2156 2251 $return_data['data'] = array(
2157 - 'enabled' => $enabled,
2158 2252 'schedule_options' => $schedule_options,
2159 2253 'schedule_type_saved_id' => $schedule_type_saved_id,
2160 2254 'optimizations' => $optimizations_data,
2161 - 'next_optimization' => $next_optimization_timestamp ? esc_html(gmdate(get_option('date_format') . ' ' . get_option('time_format'), $next_optimization_timestamp)) : '',
2162 2255 'premium_version_link' => $wp_optimize->premium_version_link,
2163 - 'enable_schedule' => $this->options->get_option('schedule'),
2256 + 'enable_schedule' => $schedule_enabled,
2164 2257 );
2165 2258 } else {
2166 2259 $wp_optimize_premium = WP_Optimize_Premium();
2167 2260 $auto_options = $wp_optimize_premium->get_scheduled_optimizations();
@@ -2166,10 +2259,8 @@
2166 2259 $wp_optimize_premium = WP_Optimize_Premium();
2167 2260 $auto_options = $wp_optimize_premium->get_scheduled_optimizations();
2168 2261 $auto_optimizations = $wp_optimize_premium->get_auto_optimizations();
2169 2262
2170 - $next_optimization_timestamp = 0;
2171 -
2172 2263 if (!empty($auto_options)) {
2173 2264 foreach ($auto_options as $optimization) {
2174 2265 if (isset($optimization['status']) && 1 == $optimization['status']) {
2175 2266 $scheduled_optimizations_enabled = true;
@@ -2192,10 +2283,10 @@
2192 2283 );
2193 2284 if (!isset($event['optimization'])) {
2194 2285 $event['optimization'] = array();
2195 2286 }
2196 - foreach ($event as $key => $value) {
2197 - switch ($key) {
2287 + foreach ($event as $event_key => $value) {
2288 + switch ($event_key) {
2198 2289 case 'optimization':
2199 2290 $optimization['optimization'] = array();
2200 2291 foreach ($all_provided_optimizations as $this_optimization) {
2201 2292 if (in_array($this_optimization['id'], $value)) {
@@ -2224,9 +2315,9 @@
2224 2315 $optimization['weeks'] = array();
2225 2316 foreach ($weeks as $key => $this_week_value) {
2226 2317 $this_week = array();
2227 2318 $this_week['label'] = $this_week_value;
2228 - $this_week['selected'] = $key === $value;
2319 + $this_week['selected'] = absint($key) === absint($value);
2229 2320 $this_week['value'] = $key;
2230 2321 $optimization['weeks'][] = $this_week;
2231 2322 }
2232 2323 break;
@@ -2234,9 +2325,9 @@
2234 2325 $optimization['days'] = array();
2235 2326 foreach ($week_days as $key => $this_week_day_value) {
2236 2327 $this_week_day = array();
2237 2328 $this_week_day['label'] = $this_week_day_value;
2238 - $this_week_day['selected'] = $key === $value;
2329 + $this_week_day['selected'] = absint($key) === absint($value);
2239 2330 $this_week_day['value'] = $key;
2240 2331 $optimization['days'][] = $this_week_day;
2241 2332 }
2242 2333 break;
@@ -2254,17 +2345,22 @@
2254 2345 $optimization['status'] = '1' === $value;
2255 2346 break;
2256 2347 }
2257 2348 }
2258 - $optimizations[] = $optimization;
2259 - }
2260 2349
2261 - if ($scheduled_optimizations_enabled) {
2262 - $next_optimization_timestamp = apply_filters('wpo_cron_next_event', wp_next_scheduled('wpo_cron_event2'));
2350 + // Add the optimization only if it has at least one selected optimization.
2351 + $has_selected_optimization = false;
2263 2352
2264 - if ($next_optimization_timestamp) {
2265 - $next_optimization_timestamp = $next_optimization_timestamp + 60 * 60 * get_option('gmt_offset');
2353 + if (!empty($optimization['optimization'])) {
2354 + foreach ($optimization['optimization'] as $optimization_data) {
2355 + if (true === $optimization_data['selected']) {
2356 + $has_selected_optimization = true;
2357 + break;
2358 + }
2359 + }
2266 2360 }
2361 +
2362 + if ($has_selected_optimization) $optimizations[] = $optimization;
2267 2363 }
2268 2364
2269 2365 $return_data['data'] = array(
2270 2366 'optimizations' => $optimizations,
@@ -2273,9 +2369,8 @@
2273 2369 'today_date' => gmdate("Y-m-d"),
2274 2370 'weeks' => $weeks,
2275 2371 'week_days' => $week_days,
2276 2372 'days' => $days,
2277 - 'next_optimization' => $next_optimization_timestamp ? esc_html(gmdate(get_option('date_format') . ' ' . get_option('time_format'), $next_optimization_timestamp)) : '',
2278 2373 'is_auto_innodb' => $this->options->get_option('auto-innodb'),
2279 2374 'scheduled_optimizations' => $auto_options,
2280 2375 'auto_optimizations' => $auto_optimizations,
2281 2376 'warning_url' => $wp_optimize->wp_optimize_url('https://teamupdraft.com/documentation/wp-optimize/topics/database-optimization/faqs/', __('Warning: you should read the FAQ about the risks of this operation first.', 'wp-optimize'), '', '', true)
@@ -2281,8 +2376,23 @@
2281 2376 'warning_url' => $wp_optimize->wp_optimize_url('https://teamupdraft.com/documentation/wp-optimize/topics/database-optimization/faqs/', __('Warning: you should read the FAQ about the risks of this operation first.', 'wp-optimize'), '', '', true)
2282 2377 );
2283 2378 }
2284 2379
2380 + $return_data['data']['enabled'] = $scheduled_optimizations_enabled;
2381 + $return_data['data']['next_optimization'] = '';
2382 +
2383 + if ($scheduled_optimizations_enabled) {
2384 + $next_optimization_timestamp = apply_filters('wpo_cron_next_event', wp_next_scheduled('wpo_cron_event2'));
2385 +
2386 + if ($next_optimization_timestamp) {
2387 + $return_data['data']['next_optimization'] = $is_udc_request ? (int) $next_optimization_timestamp : esc_html(gmdate(get_option('date_format') . ' ' . get_option('time_format'), $next_optimization_timestamp + 60 * 60 * get_option('gmt_offset')));
2388 + }
2389 + }
2390 +
2391 + if ($is_udc_request && $last_optimized_timestamp) {
2392 + $return_data['data']['last_optimized'] = (int) $last_optimized_timestamp;
2393 + }
2394 +
2285 2395 // Add the translations.
2286 2396 $return_data['data']['translations'] = array(
2287 2397 'scheduled_optimization' => __('Scheduled Optimization', 'wp-optimize'),
2288 2398 'next_schedule_run' => __('Next scheduled run', 'wp-optimize'),
@@ -2375,7 +2485,25 @@
2375 2485 'variables' => array(
2376 2486 /* translators: %s is the cleaned up memory size. */
2377 2487 'performance_highlights' => sprintf(__('%s saved', 'wp-optimize'), $total_cleanup_size),
2378 2488 ),
2489 + );
2490 + }
2491 +
2492 + /**
2493 + * Returns freshly rendered HTML for the dashboard data sections (top row + module grid).
2494 + *
2495 + * @return array{success: bool, top_row: string, mod_grid: string}
2496 + */
2497 + public function refresh_dashboard() {
2498 + $data = WP_Optimize_Dashboard::instance()->get_dashboard_data();
2499 +
2500 + $top_row = WP_Optimize()->include_template('dashboard/partials/top-row.php', true, $data);
2501 + $mod_grid = WP_Optimize()->include_template('dashboard/partials/mod-grid.php', true, $data);
2502 +
2503 + return array(
2504 + 'success' => true,
2505 + 'top_row' => $top_row,
2506 + 'mod_grid' => $mod_grid,
2379 2507 );
2380 2508 }
2381 2509 }