| @@ -27,8 +27,15 @@ | ||
| 27 | 27 | */ |
| 28 | 28 | protected $filepath = null; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | + * Critical CSS base object | |
| 32 | + * | |
| 33 | + * @var object | |
| 34 | + */ | |
| 35 | + protected $_criticalcss = null; | |
| 36 | + | |
| 37 | + /** | |
| 31 | 38 | * Constructor. |
| 32 | 39 | * |
| 33 | 40 | * @param string $version Version. |
| 34 | 41 | * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks. |
| @@ -58,14 +65,15 @@ | ||
| 58 | 65 | add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) ); |
| 59 | 66 | |
| 60 | 67 | add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) ); |
| 61 | 68 | add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) ); |
| 62 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) ); | |
| 63 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) ); | |
| 64 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss_tab' ) ); | |
| 69 | + add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_compat' ), 10 ); | |
| 70 | + add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ), 15 ); | |
| 71 | + add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_admin_only_trinkets' ), 20 ); | |
| 72 | + add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss' ), 11 ); | |
| 73 | + add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_notfound_fallback' ), 10 ); | |
| 65 | 74 | |
| 66 | 75 | add_action( 'init', array( $this, 'load_textdomain' ) ); |
| 67 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); | |
| 68 | 76 | |
| 69 | 77 | if ( is_multisite() && is_admin() ) { |
| 70 | 78 | // Only if multisite and if in admin we want to check if we need to save options on network level. |
| 71 | 79 | add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' ); |
| @@ -70,14 +78,11 @@ | ||
| 70 | 78 | // Only if multisite and if in admin we want to check if we need to save options on network level. |
| 71 | 79 | add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' ); |
| 72 | 80 | } |
| 73 | 81 | |
| 74 | - register_activation_hook( $this->filepath, array( $this, 'on_activate' ) ); | |
| 75 | - } | |
| 76 | - | |
| 77 | - public function on_activate() | |
| 78 | - { | |
| 82 | + // register uninstall & deactivation hooks. | |
| 79 | 83 | register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' ); |
| 84 | + register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' ); | |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | public function load_textdomain() |
| 83 | 88 | { |
| @@ -188,8 +193,12 @@ | ||
| 188 | 193 | // And disable Jetpack's site accelerator if JS or CSS opt. are active. |
| 189 | 194 | if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) { |
| 190 | 195 | add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' ); |
| 191 | 196 | } |
| 197 | + | |
| 198 | + // Add "no cache found" notice. | |
| 199 | + add_action( 'admin_notices', 'autoptimizeMain::notice_nopagecache', 99 ); | |
| 200 | + add_action( 'admin_notices', 'autoptimizeMain::notice_potential_conflict', 99 ); | |
| 192 | 201 | } |
| 193 | 202 | } else { |
| 194 | 203 | add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' ); |
| 195 | 204 | } |
| @@ -207,24 +216,60 @@ | ||
| 207 | 216 | add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' ); |
| 208 | 217 | } |
| 209 | 218 | } |
| 210 | 219 | |
| 211 | - public function maybe_run_partners_tab() | |
| 220 | + public function maybe_run_admin_only_trinkets() | |
| 212 | 221 | { |
| 213 | - // Loads partners tab code if in admin (and not in admin-ajax.php)! | |
| 222 | + // Loads partners tab and exit survey code if in admin (and not in admin-ajax.php)! | |
| 214 | 223 | if ( autoptimizeConfig::is_admin_and_not_ajax() ) { |
| 215 | 224 | new autoptimizePartners(); |
| 225 | + new autoptimizeExitSurvey(); | |
| 216 | 226 | } |
| 217 | 227 | } |
| 218 | 228 | |
| 219 | - public function maybe_run_criticalcss_tab() | |
| 229 | + public function criticalcss() | |
| 220 | 230 | { |
| 221 | - // Loads criticalcss tab code if in admin (and not in admin-ajax.php)! | |
| 222 | - if ( autoptimizeConfig::is_admin_and_not_ajax() && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { | |
| 223 | - new autoptimizeCriticalCSSSettings(); | |
| 231 | + if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { | |
| 232 | + return $this->_criticalcss; | |
| 233 | + } else { | |
| 234 | + return false; | |
| 224 | 235 | } |
| 225 | 236 | } |
| 226 | 237 | |
| 238 | + public function maybe_run_criticalcss() | |
| 239 | + { | |
| 240 | + // Loads criticalcss if the filter returns true & old power-up is not active. | |
| 241 | + if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { | |
| 242 | + $this->_criticalcss = new autoptimizeCriticalCSSBase(); | |
| 243 | + $this->_criticalcss->setup(); | |
| 244 | + $this->_criticalcss->load_requires(); | |
| 245 | + } | |
| 246 | + } | |
| 247 | + | |
| 248 | + public function maybe_run_notfound_fallback() | |
| 249 | + { | |
| 250 | + if ( autoptimizeCache::do_fallback() ) { | |
| 251 | + add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) ); | |
| 252 | + } | |
| 253 | + } | |
| 254 | + | |
| 255 | + public function maybe_run_ao_compat() | |
| 256 | + { | |
| 257 | + // Condtionally loads the compatibility-class to ensure more out-of-the-box compatibility with big players. | |
| 258 | + $_run_compat = true; | |
| 259 | + | |
| 260 | + if ( autoptimizeOptionWrapper::get_option( 'autoptimize_installed_before_compatibility', false ) ) { | |
| 261 | + // If AO was already running before Compatibility logic was added, don't run compat by default | |
| 262 | + // because it can be assumed everything works and we want to avoid (perf) regressions that | |
| 263 | + // could occur due to compatibility code. | |
| 264 | + $_run_compat = false; | |
| 265 | + } | |
| 266 | + | |
| 267 | + if ( apply_filters( 'autoptimize_filter_init_compatibility', $_run_compat ) ) { | |
| 268 | + new autoptimizeCompatibility(); | |
| 269 | + } | |
| 270 | + } | |
| 271 | + | |
| 227 | 272 | public function hook_page_cache_purge() |
| 228 | 273 | { |
| 229 | 274 | // hook into a collection of page cache purge actions if filter allows. |
| 230 | 275 | if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) { |
| @@ -328,19 +373,8 @@ | ||
| 328 | 373 | } |
| 329 | 374 | } |
| 330 | 375 | } |
| 331 | 376 | |
| 332 | - // also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders, | |
| 333 | - // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that. | |
| 334 | - if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) { | |
| 335 | - $ao_noptimize = true; | |
| 336 | - } | |
| 337 | - | |
| 338 | - // and make sure Thrive editor doesn't get optimized HTML. | |
| 339 | - if ( false === $ao_noptimize && array_key_exists( 'tve', $_GET ) && 'true' === $_GET['tve'] ) { | |
| 340 | - $ao_noptimize = true; | |
| 341 | - } | |
| 342 | - | |
| 343 | 377 | // If setting says not to optimize logged in user and user is logged in... |
| 344 | 378 | if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { |
| 345 | 379 | $ao_noptimize = true; |
| 346 | 380 | } |
| @@ -347,9 +381,9 @@ | ||
| 347 | 381 | |
| 348 | 382 | // If setting says not to optimize cart/checkout. |
| 349 | 383 | if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) { |
| 350 | 384 | // Checking for woocommerce, easy digital downloads and wp ecommerce... |
| 351 | - foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { | |
| 385 | + foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { | |
| 352 | 386 | if ( function_exists( $func ) && $func() ) { |
| 353 | 387 | $ao_noptimize = true; |
| 354 | 388 | break; |
| 355 | 389 | } |
| @@ -355,9 +389,32 @@ | ||
| 355 | 389 | } |
| 356 | 390 | } |
| 357 | 391 | } |
| 358 | 392 | |
| 359 | - // Allows blocking of autoptimization on your own terms regardless of above decisions. | |
| 393 | + // Misc. querystring paramaters that will stop AO from doing optimizations (pagebuilders + | |
| 394 | + // 2 generic parameters that could/ should become standard between optimization plugins?) | |
| 395 | + if ( false === $ao_noptimize ) { | |
| 396 | + $_qs_showstoppers = array( 'no_cache', 'no_optimize', 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor', 'preview' ); | |
| 397 | + foreach ( $_qs_showstoppers as $_showstopper ) { | |
| 398 | + if ( array_key_exists( $_showstopper, $_GET ) ) { | |
| 399 | + $ao_noptimize = true; | |
| 400 | + break; | |
| 401 | + } | |
| 402 | + } | |
| 403 | + } | |
| 404 | + | |
| 405 | + // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders, | |
| 406 | + // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that. | |
| 407 | + if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) { | |
| 408 | + $ao_noptimize = true; | |
| 409 | + } | |
| 410 | + | |
| 411 | + // If page/ post check post_meta to see if optimize is off. | |
| 412 | + if ( false === autoptimizeConfig::get_post_meta_ao_settings( 'ao_post_optimize' ) ) { | |
| 413 | + $ao_noptimize = true; | |
| 414 | + } | |
| 415 | + | |
| 416 | + // And finally allows blocking of autoptimization on your own terms regardless of above decisions. | |
| 360 | 417 | $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
| 361 | 418 | |
| 362 | 419 | // Check for site being previewed in the Customizer (available since WP 4.0). |
| 363 | 420 | $is_customize_preview = false; |
| @@ -419,16 +476,31 @@ | ||
| 419 | 476 | * @return bool |
| 420 | 477 | */ |
| 421 | 478 | public static function is_amp_markup( $content ) |
| 422 | 479 | { |
| 423 | - // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page. | |
| 424 | - if ( function_exists( 'is_amp_endpoint' ) ) { | |
| 425 | - return is_amp_endpoint(); | |
| 480 | + // Short-circuit if the page is already AMP from the start. | |
| 481 | + if ( | |
| 482 | + preg_match( | |
| 483 | + sprintf( | |
| 484 | + '#^(?:<!.*?>|\s+)*+<html(?=\s)[^>]*?\s(%1$s|%2$s|%3$s)(\s|=|>)#is', | |
| 485 | + 'amp', | |
| 486 | + "\xE2\x9A\xA1", // From \AmpProject\Attribute::AMP_EMOJI. | |
| 487 | + "\xE2\x9A\xA1\xEF\xB8\x8F" // From \AmpProject\Attribute::AMP_EMOJI_ALT, per https://github.com/ampproject/amphtml/issues/25990. | |
| 488 | + ), | |
| 489 | + $content | |
| 490 | + ) | |
| 491 | + ) { | |
| 492 | + return true; | |
| 426 | 493 | } |
| 427 | 494 | |
| 428 | - $is_amp_markup = preg_match( '/<html[^>]*(?:amp|âš¡)/i', $content ); | |
| 495 | + // Or else short-circuit if the AMP plugin will be processing the output to be an AMP page. | |
| 496 | + if ( function_exists( 'amp_is_request' ) ) { | |
| 497 | + return amp_is_request(); // For AMP plugin v2.0+. | |
| 498 | + } elseif ( function_exists( 'is_amp_endpoint' ) ) { | |
| 499 | + return is_amp_endpoint(); // For older/other AMP plugins (still supported in 2.0 as an alias). | |
| 500 | + } | |
| 429 | 501 | |
| 430 | - return (bool) $is_amp_markup; | |
| 502 | + return false; | |
| 431 | 503 | } |
| 432 | 504 | |
| 433 | 505 | /** |
| 434 | 506 | * Processes/optimizes the output-buffered content and returns it. |
| @@ -460,16 +532,18 @@ | ||
| 460 | 532 | } |
| 461 | 533 | |
| 462 | 534 | $classoptions = array( |
| 463 | 535 | 'autoptimizeScripts' => array( |
| 464 | - 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), | |
| 465 | - 'justhead' => $conf->get( 'autoptimize_js_justhead' ), | |
| 466 | - 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), | |
| 467 | - 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), | |
| 468 | - 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), | |
| 469 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), | |
| 470 | - 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), | |
| 471 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), | |
| 536 | + 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), | |
| 537 | + 'defer_not_aggregate' => $conf->get( 'autoptimize_js_defer_not_aggregate' ), | |
| 538 | + 'defer_inline' => $conf->get( 'autoptimize_js_defer_inline' ), | |
| 539 | + 'justhead' => $conf->get( 'autoptimize_js_justhead' ), | |
| 540 | + 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), | |
| 541 | + 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), | |
| 542 | + 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), | |
| 543 | + 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), | |
| 544 | + 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), | |
| 545 | + 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), | |
| 472 | 546 | ), |
| 473 | 547 | 'autoptimizeStyles' => array( |
| 474 | 548 | 'aggregate' => $conf->get( 'autoptimize_css_aggregate' ), |
| 475 | 549 | 'justhead' => $conf->get( 'autoptimize_css_justhead' ), |
| @@ -521,10 +595,17 @@ | ||
| 521 | 595 | } |
| 522 | 596 | |
| 523 | 597 | public static function on_uninstall() |
| 524 | 598 | { |
| 599 | + // clear the cache. | |
| 525 | 600 | autoptimizeCache::clearall(); |
| 526 | 601 | |
| 602 | + // remove postmeta if active. | |
| 603 | + if ( autoptimizeConfig::is_ao_meta_settings_active() ) { | |
| 604 | + delete_post_meta_by_key( 'ao_post_optimize' ); | |
| 605 | + } | |
| 606 | + | |
| 607 | + // remove all options. | |
| 527 | 608 | $delete_options = array( |
| 528 | 609 | 'autoptimize_cache_clean', |
| 529 | 610 | 'autoptimize_cache_nogzip', |
| 530 | 611 | 'autoptimize_css', |
| @@ -537,10 +618,13 @@ | ||
| 537 | 618 | 'autoptimize_css_exclude', |
| 538 | 619 | 'autoptimize_html', |
| 539 | 620 | 'autoptimize_html_keepcomments', |
| 540 | 621 | 'autoptimize_enable_site_config', |
| 622 | + 'autoptimize_enable_meta_ao_settings', | |
| 541 | 623 | 'autoptimize_js', |
| 542 | 624 | 'autoptimize_js_aggregate', |
| 625 | + 'autoptimize_js_defer_not_aggregate', | |
| 626 | + 'autoptimize_js_defer_inline', | |
| 543 | 627 | 'autoptimize_js_exclude', |
| 544 | 628 | 'autoptimize_js_forcehead', |
| 545 | 629 | 'autoptimize_js_justhead', |
| 546 | 630 | 'autoptimize_js_trycatch', |
| @@ -557,8 +641,27 @@ | ||
| 557 | 641 | 'autoptimize_imgopt_provider_stat', |
| 558 | 642 | 'autoptimize_imgopt_launched', |
| 559 | 643 | 'autoptimize_imgopt_settings', |
| 560 | 644 | 'autoptimize_minify_excluded', |
| 645 | + 'autoptimize_cache_fallback', | |
| 646 | + 'autoptimize_ccss_rules', | |
| 647 | + 'autoptimize_ccss_additional', | |
| 648 | + 'autoptimize_ccss_queue', | |
| 649 | + 'autoptimize_ccss_viewport', | |
| 650 | + 'autoptimize_ccss_finclude', | |
| 651 | + 'autoptimize_ccss_rlimit', | |
| 652 | + 'autoptimize_ccss_rtimelimit', | |
| 653 | + 'autoptimize_ccss_noptimize', | |
| 654 | + 'autoptimize_ccss_debug', | |
| 655 | + 'autoptimize_ccss_key', | |
| 656 | + 'autoptimize_ccss_keyst', | |
| 657 | + 'autoptimize_ccss_version', | |
| 658 | + 'autoptimize_ccss_loggedin', | |
| 659 | + 'autoptimize_ccss_forcepath', | |
| 660 | + 'autoptimize_ccss_deferjquery', | |
| 661 | + 'autoptimize_ccss_domain', | |
| 662 | + 'autoptimize_ccss_unloadccss', | |
| 663 | + 'autoptimize_installed_before_compatibility', | |
| 561 | 664 | ); |
| 562 | 665 | |
| 563 | 666 | if ( ! is_multisite() ) { |
| 564 | 667 | foreach ( $delete_options as $del_opt ) { |
| @@ -563,8 +666,9 @@ | ||
| 563 | 666 | if ( ! is_multisite() ) { |
| 564 | 667 | foreach ( $delete_options as $del_opt ) { |
| 565 | 668 | delete_option( $del_opt ); |
| 566 | 669 | } |
| 670 | + autoptimizeMain::remove_cronjobs(); | |
| 567 | 671 | } else { |
| 568 | 672 | global $wpdb; |
| 569 | 673 | $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 570 | 674 | $original_blog_id = get_current_blog_id(); |
| @@ -572,17 +676,54 @@ | ||
| 572 | 676 | switch_to_blog( $blog_id ); |
| 573 | 677 | foreach ( $delete_options as $del_opt ) { |
| 574 | 678 | delete_option( $del_opt ); |
| 575 | 679 | } |
| 680 | + autoptimizeMain::remove_cronjobs(); | |
| 576 | 681 | } |
| 577 | 682 | switch_to_blog( $original_blog_id ); |
| 578 | 683 | } |
| 579 | 684 | |
| 580 | - if ( wp_get_schedule( 'ao_cachechecker' ) ) { | |
| 581 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); | |
| 685 | + // Remove AO CCSS cached files and directory. | |
| 686 | + $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/'; | |
| 687 | + if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) { | |
| 688 | + // fixme: should check for subdirs when in multisite and remove contents of those as well. | |
| 689 | + array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) ); | |
| 690 | + rmdir( $ao_ccss_dir ); | |
| 582 | 691 | } |
| 692 | + | |
| 693 | + // Remove 404-handler (although that should have been removed in clearall already). | |
| 694 | + $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php'; | |
| 695 | + if ( file_exists( $_fallback_php ) ) { | |
| 696 | + unlink( $_fallback_php ); | |
| 697 | + } | |
| 583 | 698 | } |
| 584 | 699 | |
| 700 | + public static function on_deactivation() | |
| 701 | + { | |
| 702 | + if ( is_multisite() && is_network_admin() ) { | |
| 703 | + global $wpdb; | |
| 704 | + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 705 | + $original_blog_id = get_current_blog_id(); | |
| 706 | + foreach ( $blog_ids as $blog_id ) { | |
| 707 | + switch_to_blog( $blog_id ); | |
| 708 | + autoptimizeMain::remove_cronjobs(); | |
| 709 | + } | |
| 710 | + switch_to_blog( $original_blog_id ); | |
| 711 | + } else { | |
| 712 | + autoptimizeMain::remove_cronjobs(); | |
| 713 | + } | |
| 714 | + autoptimizeCache::clearall(); | |
| 715 | + } | |
| 716 | + | |
| 717 | + public static function remove_cronjobs() { | |
| 718 | + // Remove scheduled events. | |
| 719 | + foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance', 'ao_ccss_keychecker' ) as $_event ) { | |
| 720 | + if ( wp_get_schedule( $_event ) ) { | |
| 721 | + wp_clear_scheduled_hook( $_event ); | |
| 722 | + } | |
| 723 | + } | |
| 724 | + } | |
| 725 | + | |
| 585 | 726 | public static function notice_cache_unavailable() |
| 586 | 727 | { |
| 587 | 728 | echo '<div class="error"><p>'; |
| 588 | 729 | // Translators: %s is the cache directory location. |
| @@ -592,9 +733,9 @@ | ||
| 592 | 733 | |
| 593 | 734 | public static function notice_installed() |
| 594 | 735 | { |
| 595 | 736 | echo '<div class="updated"><p>'; |
| 596 | - _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); | |
| 737 | + printf( __( 'Thank you for installing and activating Autoptimize. Please configure it under %sSettings -> Autoptimize%s to start improving your site\'s performance.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize">', '</a>' ); | |
| 597 | 738 | echo '</p></div>'; |
| 598 | 739 | } |
| 599 | 740 | |
| 600 | 741 | public static function notice_updated() |
| @@ -606,17 +747,61 @@ | ||
| 606 | 747 | |
| 607 | 748 | public static function notice_plug_imgopt() |
| 608 | 749 | { |
| 609 | 750 | // Translators: the URL added points to the Autopmize Extra settings. |
| 610 | - $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' ); | |
| 751 | + $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP and AVIF) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' ); | |
| 611 | 752 | $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); |
| 612 | 753 | $_ao_imgopt_launch_ok = autoptimizeImages::launch_ok_wrapper(); |
| 613 | 754 | $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; |
| 614 | 755 | $_ao_imgopt_active = autoptimizeImages::imgopt_active(); |
| 756 | + $_is_ao_settings_page = autoptimizeUtils::is_ao_settings(); | |
| 615 | 757 | |
| 616 | - if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { | |
| 758 | + if ( current_user_can( 'manage_options' ) && $_is_ao_settings_page && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { | |
| 617 | 759 | echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>'; |
| 618 | 760 | echo $_ao_imgopt_plug_notice; |
| 619 | 761 | echo '</p></div>'; |
| 762 | + } | |
| 763 | + } | |
| 764 | + | |
| 765 | + public static function notice_nopagecache() | |
| 766 | + { | |
| 767 | + /* | |
| 768 | + * Autoptimize does not do page caching (yet) but not everyone knows, so below logic tries to find out if page caching is available and if not show a notice on the AO Settings pages. | |
| 769 | + * | |
| 770 | + * uses helper function in autoptimizeUtils.php | |
| 771 | + */ | |
| 772 | + $_ao_nopagecache_notice = __( 'It looks like your site might not have <strong>page caching</strong> which is a <strong>must-have for performance</strong>. If you are sure you have a page cache, you can close this notice, but when in doubt check with your host if they offer this or install a page caching plugin like for example', 'autoptimize' ); | |
| 773 | + $_ao_pagecache_install_url = network_admin_url() . 'plugin-install.php?tab=search&type=term&s='; | |
| 774 | + $_ao_nopagecache_notice .= ' <a href="' . $_ao_pagecache_install_url . 'wp+super+cache' . '">WP Super Cache</a>, <a href="' . $_ao_pagecache_install_url . 'keycdn+cache+enabler' . '">KeyCDN Cache Enabler</a>, ...'; | |
| 775 | + $_ao_nopagecache_dismissible = 'ao-nopagecache-forever'; // the notice is only shown once and will not re-appear when dismissed. | |
| 776 | + $_is_ao_settings_page = autoptimizeUtils::is_ao_settings(); | |
| 777 | + | |
| 778 | + if ( current_user_can( 'manage_options' ) && $_is_ao_settings_page && PAnD::is_admin_notice_active( $_ao_nopagecache_dismissible ) && true === apply_filters( 'autoptimize_filter_main_show_pagecache_notice', true ) ) { | |
| 779 | + if ( false === autoptimizeUtils::find_pagecache() ) { | |
| 780 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_nopagecache_dismissible . '"><p>'; | |
| 781 | + echo $_ao_nopagecache_notice; | |
| 782 | + echo '</p></div>'; | |
| 783 | + } | |
| 784 | + } | |
| 785 | + } | |
| 786 | + | |
| 787 | + public static function notice_potential_conflict() | |
| 788 | + { | |
| 789 | + /* | |
| 790 | + * Using other plugins to do CSS/ JS optimization can cause unexpected and hard to troubleshoot issues, warn users who seem to be in that situation. | |
| 791 | + */ | |
| 792 | + // Translators: the sentence will be finished with the name of the offending plugin and a final stop. | |
| 793 | + $_ao_potential_conflict_notice = __( 'It looks like you have <strong>another plugin also doing CSS and/ or JS optimization</strong>, which can result in hard to troubleshoot <strong>conflicts</strong>. For this reason it is recommended to disable this functionality in', 'autoptimize' ) . ' '; | |
| 794 | + $_ao_potential_conflict_dismissible = 'ao-potential-conflict-forever'; // the notice is only shown once and will not re-appear when dismissed. | |
| 795 | + $_is_ao_settings_page = autoptimizeUtils::is_ao_settings(); | |
| 796 | + | |
| 797 | + if ( current_user_can( 'manage_options' ) && $_is_ao_settings_page && PAnD::is_admin_notice_active( $_ao_potential_conflict_dismissible ) && true === apply_filters( 'autoptimize_filter_main_show_potential_conclict_notice', true ) ) { | |
| 798 | + $_potential_conflicts = autoptimizeUtils::find_potential_conflicts(); | |
| 799 | + if ( false !== $_potential_conflicts ) { | |
| 800 | + $_ao_potential_conflict_notice .= '<strong>' . $_potential_conflicts . '</strong>.'; | |
| 801 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_potential_conflict_dismissible . '"><p>'; | |
| 802 | + echo $_ao_potential_conflict_notice; | |
| 803 | + echo '</p></div>'; | |
| 804 | + } | |
| 620 | 805 | } |
| 621 | 806 | } |
| 622 | 807 | } |