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 +302 -15 4.6.1 → 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;
@@ -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;
@@ -1412,8 +1505,160 @@
1412 1505 );
1413 1506 }
1414 1507
1415 1508 /**
1509 + * [For UpdraftCentral] Returns selected WP-Optimize toggleable settings optimized for quick access
1510 + *
1511 + * @return WP_Error|array
1512 + */
1513 + private function get_quick_settings_data() {
1514 + if (!WP_Optimize()->current_user_can()) {
1515 + return $this->request_error('insufficient_privilege');
1516 + }
1517 +
1518 + $options = WP_Optimize()->get_options();
1519 + $default_lazyload_settings = array(
1520 + 'images' => false,
1521 + 'backgrounds' => false,
1522 + 'iframes' => false,
1523 + 'youtube_preview' => false,
1524 + 'skip_classes' => '',
1525 + );
1526 +
1527 + $lazyload = wp_parse_args($options->get_option('lazyload', array()), $default_lazyload_settings);
1528 + foreach ($lazyload as $key => $value) {
1529 + if ('skip_classes' !== $key) {
1530 + $lazyload[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
1531 + }
1532 + }
1533 +
1534 + $trackbacks = $options->get_option('trackbacks_action', array());
1535 + $comments = $options->get_option('comments_action', array());
1536 +
1537 + $gzip_compression_enabled = WP_Optimize()->get_gzip_compression()->is_gzip_compression_enabled(false);
1538 +
1539 + $settings = array(
1540 + 'scheduled_cleanup' => 'true' === $options->get_option('schedule'),
1541 + 'backup_enabled' => 'true' === $options->get_option('enable-auto-backup', 'false'),
1542 + 'comments' => (!empty($comments) && $comments['action']) ? true : false,
1543 + 'trackbacks' => (!empty($trackbacks) && $trackbacks['action']) ? true : false,
1544 + 'autosmush' => $options->get_option('autosmush'),
1545 + 'page_caching' => WP_Optimize()->get_page_cache()->is_enabled(),
1546 + 'minify' => wp_optimize_minify_config()->get('enabled'),
1547 + 'image_dimensions' => $options->get_option('image_dimensions'),
1548 + '404_detector' => $options->get_option('404_detector'),
1549 + 'webp_conversion' => $options->get_option('webp_conversion'),
1550 + 'gzip_compression' => (!is_wp_error($gzip_compression_enabled) && $gzip_compression_enabled) ? true : false,
1551 + );
1552 +
1553 + $settings = array_map(function($value) {
1554 + return filter_var($value, FILTER_VALIDATE_BOOLEAN);
1555 + }, $settings);
1556 +
1557 + return array_merge($settings, array('lazyload' => $lazyload));
1558 + }
1559 +
1560 + /**
1561 + * [For UpdraftCentral] Saves the selected WP-Optimize toggleable settings
1562 + *
1563 + * @param array $settings Parameters required for the requested action
1564 + *
1565 + * @return WP_Error|array
1566 + */
1567 + public function save_quick_settings($settings) {
1568 + if (!WP_Optimize()->current_user_can()) {
1569 + return $this->request_error('insufficient_privilege');
1570 + }
1571 +
1572 + if (!empty($settings) && is_array($settings)) {
1573 + $settings = array_map(function($value) {
1574 + return filter_var($value, FILTER_VALIDATE_BOOLEAN);
1575 + }, $settings);
1576 + }
1577 +
1578 + try {
1579 +
1580 + if (isset($settings['enable-404-detector'])) {
1581 + WP_Optimize()->get_options()->update_option('404_detector', (int) $settings['enable-404-detector']);
1582 + }
1583 +
1584 + if (isset($settings['enable-auto-backup'])) {
1585 + WP_Optimize()->get_options()->update_option('enable-auto-backup', $settings['enable-auto-backup'] ? 'true' : 'false');
1586 +
1587 + WP_Optimize()->get_options()->update_option('enable-auto-backup-scheduled', $settings['enable-auto-backup'] ? 'true' : 'false');
1588 + }
1589 +
1590 + if (isset($settings['enable-auto-compression'])) {
1591 + Updraft_Smush_Manager()->update_smush_options(array('autosmush' => (int) $settings['enable-auto-compression']));
1592 + }
1593 +
1594 + if (isset($settings['enable-comments'])) {
1595 + $this->enable_or_disable_feature(array(
1596 + 'type' => 'comments',
1597 + 'enable' => $settings['enable-comments'],
1598 + ));
1599 + }
1600 +
1601 + if (isset($settings['enable-trackbacks'])) {
1602 + $this->enable_or_disable_feature(array(
1603 + 'type' => 'trackbacks',
1604 + 'enable' => $settings['enable-trackbacks'],
1605 + ));
1606 + }
1607 +
1608 + if (isset($settings['enable-minify'])) {
1609 + wp_optimize_minify_config()->update(array('enabled' => $settings['enable-minify']));
1610 + }
1611 +
1612 + if (isset($settings['enable-page-caching'])) {
1613 + $wpo_page_cache = WP_Optimize()->get_page_cache();
1614 +
1615 + if ($settings['enable-page-caching']) {
1616 + $wpo_page_cache->enable(true);
1617 + } else {
1618 + $wpo_page_cache->disable();
1619 + }
1620 + }
1621 +
1622 + if (isset($settings['enable-scheduled-cleanup'])) {
1623 + WP_Optimize()->get_options()->update_option('schedule', $settings['enable-scheduled-cleanup'] ? 'true' : 'false');
1624 + }
1625 +
1626 + if (isset($settings['enable-webp-conversion'])) {
1627 + WP_Optimize()->get_webp_instance()->save_webp_settings(array('webp_conversion' => $settings['enable-webp-conversion']));
1628 + }
1629 +
1630 + if (isset($settings['enable-images-dimensions'])) {
1631 + WP_Optimize()->get_options()->update_option('image_dimensions', (int) $settings['enable-images-dimensions']);
1632 + }
1633 +
1634 + if (isset($settings['enable-lazy-loading'])) {
1635 + $value = (int) $settings['enable-lazy-loading'];
1636 + $options = WP_Optimize()->get_options();
1637 +
1638 + $lazyload = $options->get_option('lazyload');
1639 + $lazy_settings = array(
1640 + 'images' => $value,
1641 + 'iframes' => $value,
1642 + 'backgrounds' => $value,
1643 + 'youtube_preview' => $value,
1644 + 'skip_classes' => !empty($lazyload['skip_classes']) ? $lazyload['skip_classes'] : '',
1645 + );
1646 + $options->save_lazy_load_settings(array('lazyload' => $lazy_settings));
1647 + }
1648 +
1649 + if (isset($settings['enable-gzip-compression'])) {
1650 + $this->enable_gzip_compression(array('enable' => $settings['enable-gzip-compression']));
1651 + }
1652 +
1653 + } catch (Throwable $e) {
1654 + return $this->request_error('quick_settings_save_error', null, array('message' => $e->getMessage(), 'settings' => $this->get_quick_settings_data()));
1655 + }
1656 +
1657 + return array('settings' => $this->get_quick_settings_data());
1658 + }
1659 +
1660 + /**
1416 1661 * Get the data of wp-optimize widget.
1417 1662 *
1418 1663 * @return array
1419 1664 */
@@ -1440,14 +1685,21 @@
1440 1685 $optimization_data['run_sort_order'] = $optimization->get_run_sort_order();
1441 1686
1442 1687 // Check if the DOM is optimize-db to generate a list of tables.
1443 1688 if ('optimize-db' == $optimization_data['dom_id']) {
1444 - $table_list = $this->optimizer->get_table_information();
1445 -
1446 - // Make sure that optimization_table_inno_db is set.
1447 - 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()) {
1448 1692 $optimization_data['disable_optimization_button'] = true;
1449 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 + }
1450 1702 }
1451 1703 }
1452 1704
1453 1705 $optimization_data['id'] = $id;
@@ -1526,9 +1778,9 @@
1526 1778 * Get all status data.
1527 1779 *
1528 1780 * @return array
1529 1781 */
1530 - private function get_all_status_data() {
1782 + public function get_all_status_data() {
1531 1783 $wp_optimize = WP_Optimize();
1532 1784
1533 1785 $retention_enabled = $this->options->get_option('retention-enabled', 'false') === 'true';
1534 1786 $retention_period = $this->options->get_option('retention-period', '2');
@@ -1537,8 +1789,9 @@
1537 1789 $revisions_retention_enabled = $this->options->get_option('revisions-retention-enabled', 'false') === 'true';
1538 1790 $revisions_retention_count = $this->options->get_option('revisions-retention-count', '2');
1539 1791
1540 1792 $last_optimized = $this->options->get_option('last-optimized', 'Never');
1793 + $last_optimized_ts = $last_optimized;
1541 1794
1542 1795 if (!empty($last_optimized) && is_numeric($last_optimized)) {
1543 1796 $last_optimized = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_optimized + (get_option('gmt_offset') * HOUR_IN_SECONDS));
1544 1797 }
@@ -1543,8 +1796,9 @@
1543 1796 $last_optimized = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_optimized + (get_option('gmt_offset') * HOUR_IN_SECONDS));
1544 1797 }
1545 1798
1546 1799 $scheduled_optimizations_enabled = false;
1800 + $scheduled_optimizations = array();
1547 1801
1548 1802 if (WP_Optimize::is_premium()) {
1549 1803 $wp_optimize_premium = WP_Optimize_Premium();
1550 1804 $scheduled_optimizations = $wp_optimize_premium->get_scheduled_optimizations();
@@ -1590,8 +1844,9 @@
1590 1844 }
1591 1845
1592 1846 return array(
1593 1847 'last_optimized' => $last_optimized,
1848 + 'last_optimized_ts' => $last_optimized_ts,
1594 1849 'total_cleaned' => $total_cleaned,
1595 1850 'total_cleanup_size' => $total_cleanup_size,
1596 1851 'corrupted_tables_count' => $corrupted_tables_count,
1597 1852 'admin_page_url' => $admin_page_url,
@@ -1600,8 +1855,9 @@
1600 1855 'revisions_retention_enabled' => $revisions_retention_enabled,
1601 1856 'revisions_retention_count' => $revisions_retention_count,
1602 1857 'scheduled_optimizations_enabled' => $scheduled_optimizations_enabled,
1603 1858 'next_optimization_timestamp' => $next_optimization_timestamp,
1859 + 'scheduled_optimizations' => $scheduled_optimizations
1604 1860 );
1605 1861 }
1606 1862
1607 1863 /**
@@ -1976,9 +2232,9 @@
1976 2232 foreach ($optimizations as $id => $optimization) {
1977 2233 if (empty($optimization->available_for_auto)) continue;
1978 2234
1979 2235 if ('optimizetables' == $id && false === $does_server_allow_table_optimization) continue;
1980 -
2236 +
1981 2237 $auto_id = $optimization->get_auto_id();
1982 2238
1983 2239 $auto_dom_id = 'wp-optimize-auto-'.$auto_id;
1984 2240
@@ -1987,9 +2243,9 @@
1987 2243 $optimizations_data[] = array(
1988 2244 'id' => $auto_id,
1989 2245 'dom_id' => $auto_dom_id,
1990 2246 'activated' => $setting_activated,
1991 - 'label' => $optimization->get_auto_option_description(),
2247 + 'label' => $optimization->settings_label(),
1992 2248 );
1993 2249 }
1994 2250
1995 2251 $return_data['data'] = array(
@@ -2089,9 +2345,22 @@
2089 2345 $optimization['status'] = '1' === $value;
2090 2346 break;
2091 2347 }
2092 2348 }
2093 - $optimizations[] = $optimization;
2349 +
2350 + // Add the optimization only if it has at least one selected optimization.
2351 + $has_selected_optimization = false;
2352 +
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 + }
2360 + }
2361 +
2362 + if ($has_selected_optimization) $optimizations[] = $optimization;
2094 2363 }
2095 2364
2096 2365 $return_data['data'] = array(
2097 2366 'optimizations' => $optimizations,
@@ -2216,7 +2485,25 @@
2216 2485 'variables' => array(
2217 2486 /* translators: %s is the cleaned up memory size. */
2218 2487 'performance_highlights' => sprintf(__('%s saved', 'wp-optimize'), $total_cleanup_size),
2219 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,
2220 2507 );
2221 2508 }
2222 2509 }