| @@ -27,10 +27,9 @@ | ||
| 27 | 27 | $_instance = new self(); |
| 28 | 28 | } |
| 29 | 29 | return $_instance; |
| 30 | 30 | } |
| 31 | - | |
| 32 | - | |
| 31 | + | |
| 33 | 32 | /** |
| 34 | 33 | * Builds the Tabs that should be displayed |
| 35 | 34 | * |
| 36 | 35 | * @param string $page |
| @@ -40,8 +39,11 @@ | ||
| 40 | 39 | public function get_tabs($page) { |
| 41 | 40 | // define tabs for pages. |
| 42 | 41 | $pages_tabs = array( |
| 43 | 42 | 'WP-Optimize' => array( |
| 43 | + 'dashboard' => __('Overview', 'wp-optimize'), | |
| 44 | + ), | |
| 45 | + 'wpo_database' => array( | |
| 44 | 46 | 'optimize' => __('Optimizations', 'wp-optimize'), |
| 45 | 47 | 'tables' => __('Tables', 'wp-optimize'), |
| 46 | 48 | 'settings' => __('Settings', 'wp-optimize'), |
| 47 | 49 | 'table_analysis' => __('Table usage', 'wp-optimize').'<span class="menu-pill premium-only">Premium</span>' |
| @@ -105,13 +107,13 @@ | ||
| 105 | 107 | return; |
| 106 | 108 | } |
| 107 | 109 | |
| 108 | 110 | $this->register_admin_content(); |
| 109 | - | |
| 111 | + | |
| 110 | 112 | global $wp_version; |
| 111 | 113 | |
| 112 | 114 | echo '<div id="wp-optimize-wrap" class="'.(version_compare($wp_version, '7.0', '>=') ? 'wp-version-7' : '').'">'; |
| 113 | - | |
| 115 | + | |
| 114 | 116 | WP_Optimize()->include_template('admin-page-header.php', false, array('show_notices' => !(WP_Optimize()->get_install_or_update_notice()->show_current_notice()))); |
| 115 | 117 | |
| 116 | 118 | do_action('wpo_admin_after_header'); |
| 117 | 119 | |
| @@ -208,16 +210,22 @@ | ||
| 208 | 210 | /** |
| 209 | 211 | * Premium / other plugins |
| 210 | 212 | */ |
| 211 | 213 | add_action('wp_optimize_admin_page_wpo_mayalso_may_also', array($this, 'output_dashboard_other_plugins_tab'), 20); |
| 212 | - | |
| 214 | + | |
| 213 | 215 | /** |
| 216 | + * Dashboard | |
| 217 | + */ | |
| 218 | + add_action('wp_optimize_admin_page_WP-Optimize_dashboard', array($this, 'output_dashboard'), 20); | |
| 219 | + | |
| 220 | + /** | |
| 214 | 221 | * DATABASE |
| 215 | 222 | */ |
| 216 | - add_action('wp_optimize_admin_page_WP-Optimize_optimize', array($this, 'output_database_optimize_tab'), 20); | |
| 217 | - add_action('wp_optimize_admin_page_WP-Optimize_tables', array($this, 'output_database_tables_tab'), 20); | |
| 218 | - add_action('wp_optimize_admin_page_WP-Optimize_settings', array($this, 'output_database_settings_tab'), 20); | |
| 219 | - add_action('wp_optimize_admin_page_WP-Optimize_table_analysis', array($this, 'output_table_usage_tab'), 20); | |
| 223 | + add_action('wp_optimize_admin_page_wpo_database_optimize', array($this, 'output_database_optimize_tab'), 20); | |
| 224 | + add_action('wp_optimize_admin_page_wpo_database_tables', array($this, 'output_database_tables_tab'), 20); | |
| 225 | + add_action('wp_optimize_admin_page_wpo_database_settings', array($this, 'output_database_settings_tab'), 20); | |
| 226 | + add_action('wp_optimize_admin_page_wpo_database_table_analysis', array($this, 'output_table_usage_tab'), 20); | |
| 227 | + | |
| 220 | 228 | /** |
| 221 | 229 | * PERFORMANCE |
| 222 | 230 | */ |
| 223 | 231 | add_action('wp_optimize_admin_page_wpo_performance_404_detector', array($this, 'output_performance_404_requests'), 20); |
| @@ -267,9 +275,9 @@ | ||
| 267 | 275 | /** |
| 268 | 276 | * Database settings |
| 269 | 277 | */ |
| 270 | 278 | public function output_database_settings_tab() { |
| 271 | - | |
| 279 | + | |
| 272 | 280 | if (WP_Optimize()->can_run_optimizations()) { |
| 273 | 281 | $wp_optimize_commands = new WP_Optimize_Commands(); |
| 274 | 282 | $settings_general_data = $wp_optimize_commands->get_widgets_data(array('widgets' => array('wp_optimize_general_settings'))); |
| 275 | 283 | $settings_cleanup_data = $wp_optimize_commands->get_widgets_data(array('widgets' => array('wp_optimize_schedule_cleanup_settings'))); |
| @@ -398,9 +406,9 @@ | ||
| 398 | 406 | 'wpo_use_cache_lifespan' => __('Same as cache lifespan', 'wp-optimize') |
| 399 | 407 | ), |
| 400 | 408 | $scheduled_types |
| 401 | 409 | ); |
| 402 | - | |
| 410 | + | |
| 403 | 411 | WP_Optimize()->include_template('cache/page-cache-preload.php', false, array( |
| 404 | 412 | 'wpo_cache_options' => $wpo_cache_options, |
| 405 | 413 | 'is_running' => $is_running, |
| 406 | 414 | 'status_message' => $status['message'] ?? '', |
| @@ -439,26 +447,49 @@ | ||
| 439 | 447 | * Gzip tab |
| 440 | 448 | */ |
| 441 | 449 | public function output_cache_gzip_tab() { |
| 442 | 450 | $wpo_gzip_compression = WP_Optimize()->get_gzip_compression(); |
| 443 | - $wpo_gzip_compression_enabled = $wpo_gzip_compression->is_gzip_compression_enabled(true); | |
| 444 | - $wpo_gzip_headers_information = $wpo_gzip_compression->get_headers_information(); | |
| 445 | - $is_cloudflare_site = $this->is_cloudflare_site(); | |
| 451 | + $wpo_gzip_compression_enabled = $wpo_gzip_compression->is_gzip_compression_enabled(); | |
| 452 | + $wpo_gzip_compression_test_results_html = $wpo_gzip_compression->get_compression_test_results_html(true); | |
| 453 | + | |
| 454 | + WP_Optimize()->include_template('cache/gzip-compression.php', false, array( | |
| 455 | + 'gzip_compression_control_panel' => $this->get_gzip_compression_control_panel($wpo_gzip_compression_enabled, true), | |
| 456 | + 'wpo_gzip_compression_enabled' => $wpo_gzip_compression_enabled, | |
| 457 | + 'compression_test_results_html' => $wpo_gzip_compression_test_results_html, | |
| 458 | + 'info_link' => 'https://teamupdraft.com/documentation/wp-optimize/topics/caching/faqs/what-is-gzip-compression/?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=gzip-compression-guide&utm_creative_format=text', | |
| 459 | + )); | |
| 460 | + } | |
| 461 | + | |
| 462 | + /** | |
| 463 | + * Get gzip compression control panel html content. | |
| 464 | + * | |
| 465 | + * @param bool|null $wpo_gzip_compression_enabled Pass gzip compression status if already known to avoid double check. | |
| 466 | + * | |
| 467 | + * @return string | |
| 468 | + */ | |
| 469 | + public function get_gzip_compression_control_panel($wpo_gzip_compression_enabled = null, $use_cache = false) { | |
| 470 | + $wpo_gzip_compression = WP_Optimize()->get_gzip_compression(); | |
| 471 | + $wpo_gzip_compression_enabled = is_null($wpo_gzip_compression_enabled) ? $wpo_gzip_compression->is_gzip_compression_enabled() : $wpo_gzip_compression_enabled; | |
| 472 | + $wpo_gzip_headers_information = $wpo_gzip_compression->get_headers_information($wpo_gzip_compression->css_resource_url()); | |
| 473 | + $is_cloudflare_site = $this->is_cloudflare_site($use_cache); | |
| 446 | 474 | $is_gzip_compression_section_exists = $wpo_gzip_compression->is_gzip_compression_section_exists(); |
| 447 | - $wpo_gzip_compression_enabled_by_wpo = $is_gzip_compression_section_exists && $wpo_gzip_compression_enabled && !$is_cloudflare_site && !(is_array($wpo_gzip_headers_information) && 'brotli' === $wpo_gzip_headers_information['compression']); | |
| 448 | - | |
| 449 | - WP_Optimize()->include_template('cache/gzip-compression.php', false, array( | |
| 475 | + $wpo_gzip_compression_enabled_by_wpo = $is_gzip_compression_section_exists && true === $wpo_gzip_compression_enabled && !$is_cloudflare_site && !(is_array($wpo_gzip_headers_information) && 'brotli' === $wpo_gzip_headers_information['compression']); | |
| 476 | + $wpo_gzip_compression_content_types = $wpo_gzip_compression->get_enabled_disabled_compression_content_types($use_cache); | |
| 477 | + $wpo_gzip_compression_partially_enabled = count($wpo_gzip_compression_content_types['enabled']) > 0 && count($wpo_gzip_compression_content_types['disabled']) > 0; | |
| 478 | + | |
| 479 | + return WP_Optimize()->include_template('cache/gzip-compression-control-panel.php', true, array( | |
| 450 | 480 | 'wpo_gzip_headers_information' => $wpo_gzip_headers_information, |
| 451 | 481 | 'wpo_gzip_compression_enabled' => $wpo_gzip_compression_enabled, |
| 452 | 482 | 'is_cloudflare_site' => $is_cloudflare_site, |
| 453 | 483 | 'wpo_gzip_compression_enabled_by_wpo' => $wpo_gzip_compression_enabled_by_wpo, |
| 454 | 484 | 'wpo_gzip_compression_settings_added' => $is_gzip_compression_section_exists, |
| 455 | - 'info_link' => 'https://teamupdraft.com/documentation/wp-optimize/topics/caching/faqs/what-is-gzip-compression/?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=lossy-compression-guide&utm_creative_format=text', | |
| 456 | 485 | 'faq_link' => 'https://getwpo.com/gzip-faq-link/', |
| 457 | - 'class_name' => (!is_wp_error($wpo_gzip_compression_enabled) && $wpo_gzip_compression_enabled ? 'wpo-enabled' : 'wpo-disabled') | |
| 486 | + 'class_name' => $is_gzip_compression_section_exists ? 'wpo-enabled' : 'wpo-disabled', | |
| 487 | + 'wpo_gzip_compression_content_types' => $wpo_gzip_compression_content_types, | |
| 488 | + 'wpo_gzip_compression_partially_enabled' => $wpo_gzip_compression_partially_enabled, | |
| 458 | 489 | )); |
| 459 | 490 | } |
| 460 | - | |
| 491 | + | |
| 461 | 492 | /** |
| 462 | 493 | * Cache tab |
| 463 | 494 | */ |
| 464 | 495 | public function output_cache_settings_tab() { |
| @@ -464,8 +495,9 @@ | ||
| 464 | 495 | public function output_cache_settings_tab() { |
| 465 | 496 | |
| 466 | 497 | $wpo_browser_cache = WP_Optimize()->get_browser_cache(); |
| 467 | 498 | $wpo_browser_cache_enabled = $wpo_browser_cache->is_enabled(); |
| 499 | + $wpo_browser_cache->maybe_reset_error_message_output(); | |
| 468 | 500 | |
| 469 | 501 | WP_Optimize()->include_template('cache/browser-cache.php', false, array( |
| 470 | 502 | 'wpo_browser_cache_enabled' => $wpo_browser_cache_enabled, |
| 471 | 503 | 'is_cloudflare_handling_browser_cache' => $this->is_cloudflare_handling_browser_cache(), |
| @@ -472,8 +504,10 @@ | ||
| 472 | 504 | 'wpo_browser_cache_settings_added' => $wpo_browser_cache->is_browser_cache_section_exists(), |
| 473 | 505 | 'class_name' => (true === $wpo_browser_cache_enabled ? 'wpo-enabled' : 'wpo-disabled'), |
| 474 | 506 | 'wpo_browser_cache_expire_days' => WP_Optimize()->get_options()->get_option('browser_cache_expire_days', '28'), |
| 475 | 507 | 'wpo_browser_cache_expire_hours' => WP_Optimize()->get_options()->get_option('browser_cache_expire_hours', '0'), |
| 508 | + 'wpo_browser_cache_error_message' => WP_Optimize()->get_options()->get_option('browser_cache_error_message', ''), | |
| 509 | + 'wpo_browser_cache_output' => WP_Optimize()->get_options()->get_option('browser_cache_output', ''), | |
| 476 | 510 | 'info_link' => 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching', |
| 477 | 511 | 'faq_link' => 'https://www.digitalocean.com/community/tutorials/how-to-implement-browser-caching-with-nginx-s-header-module-on-ubuntu-16-04', |
| 478 | 512 | )); |
| 479 | 513 | } |
| @@ -493,14 +527,22 @@ | ||
| 493 | 527 | * Check if is the current site handled with Cloudflare. |
| 494 | 528 | * |
| 495 | 529 | * @return bool |
| 496 | 530 | */ |
| 497 | - public function is_cloudflare_site(): bool { | |
| 531 | + public function is_cloudflare_site($use_cache = false): bool { | |
| 532 | + | |
| 533 | + if ($use_cache) { | |
| 534 | + $cached_value = get_transient('wpo_is_cloudflare_site'); | |
| 535 | + if (false !== $cached_value) return $cached_value; | |
| 536 | + } | |
| 537 | + | |
| 498 | 538 | $response = wp_remote_get(home_url()); |
| 499 | 539 | if (is_wp_error($response)) return false; |
| 500 | 540 | |
| 501 | 541 | $cloudflare_status = wp_remote_retrieve_header($response, 'cf-cache-status'); |
| 502 | 542 | |
| 543 | + set_transient('wpo_is_cloudflare_site', $cloudflare_status, HOUR_IN_SECONDS); | |
| 544 | + | |
| 503 | 545 | return !empty($cloudflare_status); |
| 504 | 546 | } |
| 505 | 547 | |
| 506 | 548 | /** |
| @@ -543,21 +585,35 @@ | ||
| 543 | 585 | $optimize_db = $nonce_passed && TeamUpdraft\WP_Optimize\Includes\Fragments\fetch_superglobal('post', 'optimize-db'); |
| 544 | 586 | |
| 545 | 587 | $optimization_results = (($nonce_passed) ? $optimizer->do_optimizations($_POST) : false); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only isset is used to check, and compared again literal string |
| 546 | 588 | |
| 547 | - // display optimizations table or restricted access message. | |
| 589 | + // display optimization table or restricted access message. | |
| 548 | 590 | if (WP_Optimize()->can_run_optimizations()) { |
| 591 | + | |
| 592 | + $total_table_count = 0; | |
| 593 | + $too_many_tables = $optimizer->is_table_count_too_high($total_table_count); | |
| 594 | + $server_allows_table_optimization = WP_Optimize()->get_server_compatibility_instance()->does_server_allow_table_optimization(); | |
| 595 | + | |
| 549 | 596 | $wp_optimize_commands = new WP_Optimize_Commands(); |
| 550 | 597 | $status_data = $wp_optimize_commands->get_widgets_data(array('widgets' => array('all_status'))); |
| 551 | 598 | $optimizations_table_data = $wp_optimize_commands->get_widgets_data(array('widgets' => array('wp_optimize'))); |
| 552 | - WP_Optimize()->include_template('database/optimize-table.php', false, array( | |
| 599 | + | |
| 600 | + // Merge both sets of parameters | |
| 601 | + $template_params = array( | |
| 553 | 602 | 'optimize_db' => $optimize_db, |
| 554 | 603 | 'optimization_results' => $optimization_results, |
| 604 | + 'too_many_tables' => $too_many_tables && !$optimizer->is_large_table_count_scan_complete(), | |
| 605 | + 'done_table_count' => $optimizer->get_table_status_count(), | |
| 606 | + 'total_table_count' => $total_table_count, | |
| 607 | + 'should_show_load_in_batches_button' => $server_allows_table_optimization && $too_many_tables && (0 < $total_table_count), | |
| 555 | 608 | 'load_data' => false, |
| 556 | - 'does_server_allow_table_optimization' => WP_Optimize()->get_server_compatibility_instance()->does_server_allow_table_optimization(), | |
| 609 | + 'onboarding_active' => WP_Optimize()->get_onboarding()->is_active(), | |
| 557 | 610 | 'optimizations_table_data' => $optimizations_table_data['data']['wp_optimize'], |
| 558 | - 'status_data' => $status_data['data']['all_status'] | |
| 559 | - )); | |
| 611 | + 'status_data' => $status_data['data']['all_status'], | |
| 612 | + ); | |
| 613 | + | |
| 614 | + WP_Optimize()->include_template('database/optimize-table.php', false, $template_params); | |
| 615 | + | |
| 560 | 616 | } else { |
| 561 | 617 | $this->prevent_run_optimizations_message(); |
| 562 | 618 | } |
| 563 | 619 | } |
| @@ -578,8 +634,16 @@ | ||
| 578 | 634 | } else { |
| 579 | 635 | $this->prevent_run_optimizations_message(); |
| 580 | 636 | } |
| 581 | 637 | } |
| 638 | + | |
| 639 | + /** | |
| 640 | + * Outputs Dashboard Tab | |
| 641 | + */ | |
| 642 | + public function output_dashboard() { | |
| 643 | + $data = WP_Optimize_Dashboard::instance()->get_dashboard_data(); | |
| 644 | + WP_Optimize()->include_template('dashboard/dashboard.php', false, $data); | |
| 645 | + } | |
| 582 | 646 | |
| 583 | 647 | /** |
| 584 | 648 | * Outputs Performance 404 requests Tab |
| 585 | 649 | */ |
| @@ -585,9 +649,9 @@ | ||
| 585 | 649 | */ |
| 586 | 650 | public function output_performance_404_requests() { |
| 587 | 651 | $wp_optimize = WP_Optimize(); |
| 588 | 652 | $is_enabled = $wp_optimize->get_options()->get_option('404_detector', 0); |
| 589 | - | |
| 653 | + | |
| 590 | 654 | $detector = $wp_optimize->get_404_detector(); |
| 591 | 655 | $suspicious_threshold = $detector->get_suspicious_request_count_threshold(); |
| 592 | 656 | |
| 593 | 657 | $report_has_data = false; |
| @@ -721,9 +785,9 @@ | ||
| 721 | 785 | */ |
| 722 | 786 | public function cache_admin_bar($wp_admin_bar) { |
| 723 | 787 | $options = WP_Optimize()->get_options(); |
| 724 | 788 | if (!$options->get_option('enable_cache_in_admin_bar', true)) return; |
| 725 | - | |
| 789 | + | |
| 726 | 790 | /** |
| 727 | 791 | * The "purge cache" menu items |
| 728 | 792 | * |
| 729 | 793 | * @param array $menu_items - The menu items, in the format required by $wp_admin_bar->add_menu() |
| @@ -786,11 +850,20 @@ | ||
| 786 | 850 | */ |
| 787 | 851 | public function get_submenu_items() { |
| 788 | 852 | $sub_menu_items = array( |
| 789 | 853 | array( |
| 854 | + 'page_title' => __('Overview', 'wp-optimize'), | |
| 855 | + 'menu_title' => __('Overview', 'wp-optimize'), | |
| 856 | + 'menu_slug' => 'WP-Optimize', | |
| 857 | + 'function' => array($this, 'display_admin'), | |
| 858 | + 'icon' => 'chart-bar', | |
| 859 | + 'create_submenu' => true, | |
| 860 | + 'order' => 10, | |
| 861 | + ), | |
| 862 | + array( | |
| 790 | 863 | 'page_title' => __('Database', 'wp-optimize'), |
| 791 | 864 | 'menu_title' => __('Database', 'wp-optimize'), |
| 792 | - 'menu_slug' => 'WP-Optimize', | |
| 865 | + 'menu_slug' => 'wpo_database', | |
| 793 | 866 | 'function' => array($this, 'display_admin'), |
| 794 | 867 | 'icon' => 'cloud', |
| 795 | 868 | 'create_submenu' => true, |
| 796 | 869 | 'order' => 20, |