diff --git a/inc/Addon/WebP/Subscriber.php b/inc/Addon/WebP/Subscriber.php index 8951d6fa7c..a245e6467e 100644 --- a/inc/Addon/WebP/Subscriber.php +++ b/inc/Addon/WebP/Subscriber.php @@ -7,6 +7,7 @@ use WP_Rocket\Admin\Options_Data; use WP_Rocket\Event_Management\Subscriber_Interface; use WP_Rocket\Engine\CDN\Subscriber as CDNSubscriber; +use WP_Rocket\Engine\Support\CommentTrait; /** * Subscriber for the WebP support. @@ -14,6 +15,8 @@ * @since 3.4 */ class Subscriber extends AbstractWebp implements Subscriber_Interface { + use CommentTrait; + /** * Options_Data instance. * @@ -158,6 +161,8 @@ public function convert_to_webp( $html ) { $has_webp = apply_filters( 'rocket_page_has_webp_files', $has_webp, $html ); if ( $has_webp ) { + $html = $this->add_meta_comment( 'cache_webp', $html ); + return $html . ''; } diff --git a/inc/Engine/CDN/CDN.php b/inc/Engine/CDN/CDN.php index 985e037328..ba864553d1 100644 --- a/inc/Engine/CDN/CDN.php +++ b/inc/Engine/CDN/CDN.php @@ -4,6 +4,7 @@ namespace WP_Rocket\Engine\CDN; use WP_Rocket\Admin\Options_Data; +use WP_Rocket\Engine\Support\CommentTrait; /** * CDN class @@ -11,6 +12,8 @@ * @since 3.4 */ class CDN { + use CommentTrait; + /** * WP Rocket Options instance * @@ -80,7 +83,7 @@ public function rewrite( $html ) { $html = str_replace( $match[0], $cdn_url, $html ); } - return $html; + return $this->add_meta_comment( 'cdn', $html ); } /** diff --git a/inc/Engine/CriticalPath/CriticalCSSSubscriber.php b/inc/Engine/CriticalPath/CriticalCSSSubscriber.php index ffba529501..8d663f8e99 100644 --- a/inc/Engine/CriticalPath/CriticalCSSSubscriber.php +++ b/inc/Engine/CriticalPath/CriticalCSSSubscriber.php @@ -8,6 +8,7 @@ use WP_Rocket\Engine\Optimization\RegexTrait; use WP_Rocket\Event_Management\Subscriber_Interface; use WP_Filesystem_Direct; +use WP_Rocket\Engine\Support\CommentTrait; /** * Critical CSS Subscriber. @@ -16,6 +17,7 @@ */ class CriticalCSSSubscriber implements Subscriber_Interface { use RegexTrait; + use CommentTrait; /** * Instance of Critical CSS. @@ -602,7 +604,9 @@ public function insert_critical_css_buffer( $buffer ) { 1 ); - return preg_replace( '##iU', $this->return_remove_cpcss_script() . '', $buffer, 1 ); + $buffer = preg_replace( '##iU', $this->return_remove_cpcss_script() . '', $buffer, 1 ); + + return $this->add_meta_comment( 'async_css', $buffer ); } /** diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php index e34481d969..530a525e48 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php @@ -9,10 +9,12 @@ use WP_Rocket\Engine\Optimization\RegexTrait; use WP_Rocket\Engine\Optimization\UrlTrait; use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface; +use WP_Rocket\Engine\Support\CommentTrait; class Controller implements ControllerInterface { use RegexTrait; use UrlTrait; + use CommentTrait; /** * Options instance @@ -61,7 +63,9 @@ public function optimize( string $html, $row ): string { return $html; } - return $this->preload_lcp( $html, $row ); + $html = $this->preload_lcp( $html, $row ); + + return $this->add_meta_comment( 'oci', $html ); } /** diff --git a/inc/Engine/Media/ImageDimensions/ImageDimensions.php b/inc/Engine/Media/ImageDimensions/ImageDimensions.php index ca2f8fc866..4f4934ad27 100644 --- a/inc/Engine/Media/ImageDimensions/ImageDimensions.php +++ b/inc/Engine/Media/ImageDimensions/ImageDimensions.php @@ -8,10 +8,12 @@ use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\Admin\Settings\Settings; use WP_Rocket\Engine\Optimization\RegexTrait; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Logger\Logger; class ImageDimensions { use RegexTrait; + use CommentTrait; /** * Options_Data instance @@ -155,7 +157,9 @@ public function specify_image_dimensions( $html ) { return $html; } - return str_replace( array_keys( $replaces ), $replaces, $html ); + $html = str_replace( array_keys( $replaces ), $replaces, $html ); + + return $this->add_meta_comment( 'image_dimensions', $html ); } /** diff --git a/inc/Engine/Media/Lazyload/CSS/Subscriber.php b/inc/Engine/Media/Lazyload/CSS/Subscriber.php index 0a33ec5350..bd3051d6a7 100644 --- a/inc/Engine/Media/Lazyload/CSS/Subscriber.php +++ b/inc/Engine/Media/Lazyload/CSS/Subscriber.php @@ -16,6 +16,7 @@ TagGenerator}; use WP_Rocket\Engine\Common\Cache\CacheInterface; use WP_Rocket\Engine\Optimization\RegexTrait; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Event_Management\Subscriber_Interface; use WP_Rocket\Logger\LoggerAware; use WP_Rocket\Logger\LoggerAwareInterface; @@ -23,6 +24,7 @@ class Subscriber implements Subscriber_Interface, LoggerAwareInterface { use LoggerAware; use RegexTrait; + use CommentTrait; /** * Extract background images from CSS. @@ -205,7 +207,9 @@ public function maybe_replace_css_images( string $html ): string { ) ); - return $output['html']; + $html = $this->add_meta_comment( 'lazyload_css_bg_img', $output['html'] ); + + return $html; } /** diff --git a/inc/Engine/Media/Lazyload/Subscriber.php b/inc/Engine/Media/Lazyload/Subscriber.php index 2b35cfe5bc..23c0a5eff4 100644 --- a/inc/Engine/Media/Lazyload/Subscriber.php +++ b/inc/Engine/Media/Lazyload/Subscriber.php @@ -8,6 +8,7 @@ use WP_Rocket\Dependencies\RocketLazyload\Iframe; use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\Optimization\RegexTrait; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Event_Management\Subscriber_Interface; /** @@ -18,6 +19,7 @@ class Subscriber implements Subscriber_Interface { use RegexTrait; use CanLazyloadTrait; + use CommentTrait; const SCRIPT_VERSION = '17.8.3'; @@ -330,6 +332,8 @@ public function lazyload( $html ) { ]; $html = $this->iframe->lazyloadIframes( $html, $buffer, $args ); + + $html = $this->add_meta_comment( 'lazyload_iframes', $html ); } if ( $this->can_lazyload_images() ) { @@ -352,6 +356,8 @@ public function lazyload( $html ) { if ( apply_filters( 'rocket_lazyload_background_images', true ) ) { $html = $this->image->lazyloadBackgroundImages( $html, $buffer ); } + + $html = $this->add_meta_comment( 'lazyload_images', $html ); } return $html; diff --git a/inc/Engine/Optimization/DeferJS/DeferJS.php b/inc/Engine/Optimization/DeferJS/DeferJS.php index 70f27fe0cc..6d73858135 100644 --- a/inc/Engine/Optimization/DeferJS/DeferJS.php +++ b/inc/Engine/Optimization/DeferJS/DeferJS.php @@ -5,8 +5,11 @@ use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\Optimization\DynamicLists\DefaultLists\DataManager; +use WP_Rocket\Engine\Support\CommentTrait; class DeferJS { + use CommentTrait; + /** * Options instance * @@ -86,7 +89,7 @@ public function defer_js( string $html ): string { $html = str_replace( $tag[0], $deferred_tag, $html ); } - return $html; + return $this->add_meta_comment( 'defer_js', $html ); } /** diff --git a/inc/Engine/Optimization/DelayJS/HTML.php b/inc/Engine/Optimization/DelayJS/HTML.php index 7acd06bc09..05cfe4971d 100644 --- a/inc/Engine/Optimization/DelayJS/HTML.php +++ b/inc/Engine/Optimization/DelayJS/HTML.php @@ -6,10 +6,12 @@ use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\Optimization\DynamicLists\DefaultLists\DataManager; use WP_Rocket\Engine\Optimization\RegexTrait; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Logger\Logger; class HTML { use RegexTrait; + use CommentTrait; /** * Plugin options instance. @@ -122,7 +124,9 @@ function ( $value ) { $this->excluded ); - return $this->parse( $html ); + $html = $this->parse( $html ); + + return $this->add_meta_comment( 'delay_js', $html ); } /** diff --git a/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php b/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php index df9a478ada..e7533f587d 100644 --- a/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php +++ b/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php @@ -6,8 +6,11 @@ use WP_Rocket\Engine\Common\Context\ContextInterface; use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface; use WP_Rocket\Engine\Optimization\LazyRenderContent\Frontend\Processor\Processor; +use WP_Rocket\Engine\Support\CommentTrait; class Controller implements ControllerInterface { + use CommentTrait; + /** * Processor instance * @@ -69,7 +72,9 @@ public function optimize( string $html, $row ): string { $html = $result; $html = $this->remove_hashes( $html ); - return $this->add_css( $html ); + $html = $this->add_css( $html ); + + return $this->add_meta_comment( 'automatic_lazy_rendering', $html ); } /** diff --git a/inc/Engine/Optimization/Minify/CSS/Minify.php b/inc/Engine/Optimization/Minify/CSS/Minify.php index 69431919e1..6e94222aa0 100644 --- a/inc/Engine/Optimization/Minify/CSS/Minify.php +++ b/inc/Engine/Optimization/Minify/CSS/Minify.php @@ -4,6 +4,7 @@ use WP_Rocket\Dependencies\Minify as Minifier; use WP_Rocket\Engine\Optimization\CSSTrait; use WP_Rocket\Engine\Optimization\Minify\ProcessorInterface; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Logger\Logger; /** @@ -13,6 +14,7 @@ */ class Minify extends AbstractCSSOptimization implements ProcessorInterface { use CSSTrait; + use CommentTrait; /** * Minifies CSS files @@ -77,7 +79,7 @@ public function optimize( $html ) { $html = $this->replace_style( $style, $minify_url, $html ); } - return $html; + return $this->add_meta_comment( 'minify_css', $html ); } /** diff --git a/inc/Engine/Optimization/Minify/JS/Combine.php b/inc/Engine/Optimization/Minify/JS/Combine.php index cf6e75a941..2658ee4c32 100644 --- a/inc/Engine/Optimization/Minify/JS/Combine.php +++ b/inc/Engine/Optimization/Minify/JS/Combine.php @@ -7,6 +7,7 @@ use WP_Rocket\Engine\Optimization\DeferJS\DeferJS; use WP_Rocket\Engine\Optimization\DynamicLists\DynamicLists; use WP_Rocket\Engine\Optimization\Minify\ProcessorInterface; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Logger\Logger; /** @@ -15,6 +16,8 @@ * @since 3.1 */ class Combine extends AbstractJSOptimization implements ProcessorInterface { + use CommentTrait; + /** * Minifier instance * @@ -155,7 +158,7 @@ public function optimize( $html ) { ] ); - return $html; + return $this->add_meta_comment( 'minify_concatenate_js', $html ); } /** diff --git a/inc/Engine/Optimization/Minify/JS/Minify.php b/inc/Engine/Optimization/Minify/JS/Minify.php index 91961cf9d6..56bc094087 100644 --- a/inc/Engine/Optimization/Minify/JS/Minify.php +++ b/inc/Engine/Optimization/Minify/JS/Minify.php @@ -3,6 +3,7 @@ use WP_Rocket\Dependencies\Minify as Minifier; use WP_Rocket\Engine\Optimization\Minify\ProcessorInterface; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Logger\Logger; /** @@ -11,6 +12,8 @@ * @since 3.1 */ class Minify extends AbstractJSOptimization implements ProcessorInterface { + use CommentTrait; + /** * Minifies JS files * @@ -111,7 +114,7 @@ public function optimize( $html ) { $html = $this->replace_script( $script, $minify_url, $html ); } - return $html; + return $this->add_meta_comment( 'minify_js', $html ); } /** diff --git a/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php b/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php index 8cbb154ffd..6c19692474 100644 --- a/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php +++ b/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php @@ -10,10 +10,12 @@ use WP_Rocket\Engine\Optimization\RegexTrait; use WP_Rocket\Engine\Optimization\RUCSS\Database\Queries\UsedCSS as UsedCSS_Query; use WP_Rocket\Engine\Optimization\RUCSS\Jobs\Manager; +use WP_Rocket\Engine\Support\CommentTrait; class UsedCSS { use RegexTrait; use CSSTrait; + use CommentTrait; /** * UsedCss Query instance. @@ -165,7 +167,7 @@ public function treeshake( string $html ): string { $this->used_css_query->update_last_accessed( (int) $used_css->id ); } - return $html; + return $this->add_meta_comment( 'remove_unused_css', $html ); } /** diff --git a/inc/Engine/Preload/Fonts.php b/inc/Engine/Preload/Fonts.php index 891d9a958e..ae190ab932 100644 --- a/inc/Engine/Preload/Fonts.php +++ b/inc/Engine/Preload/Fonts.php @@ -4,6 +4,7 @@ use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\CDN\CDN; +use WP_Rocket\Engine\Support\CommentTrait; use WP_Rocket\Event_Management\Subscriber_Interface; /** @@ -12,6 +13,7 @@ * @since 3.6 */ class Fonts implements Subscriber_Interface { + use CommentTrait; /** * WP Rocket Options instance. @@ -114,7 +116,15 @@ public function preload_fonts( $html ): string { ); } - return preg_replace( '##', $preloads, $html, 1 ); + $result = preg_replace( '##', $preloads, $html, 1 ); + + if ( null === $result ) { + return $html; + } + + $result = $this->add_meta_comment( 'preload_fonts', $result ); + + return $result; } /** diff --git a/inc/Engine/Support/CommentTrait.php b/inc/Engine/Support/CommentTrait.php new file mode 100644 index 0000000000..86a75ece08 --- /dev/null +++ b/inc/Engine/Support/CommentTrait.php @@ -0,0 +1,29 @@ +#', '', $html, 1 ); + + if ( null === $result ) { + return $html; + } + + return $result; + } +} diff --git a/inc/Engine/Support/Data.php b/inc/Engine/Support/Data.php index 59b624c112..25129429a4 100644 --- a/inc/Engine/Support/Data.php +++ b/inc/Engine/Support/Data.php @@ -1,4 +1,5 @@ to_send, array_filter( $this->options->get_options() ) ); - return [ 'Website' => home_url(), 'WordPress Version' => get_bloginfo( 'version' ), - 'WP Rocket Version' => rocket_get_constant( 'WP_ROCKET_VERSION' ), + 'WP Rocket Version' => rocket_get_constant( 'WP_ROCKET_VERSION', '' ), 'Theme' => wp_get_theme()->get( 'Name' ), 'Plugins Enabled' => implode( ' - ', rocket_get_active_plugins() ), - 'WP Rocket Active Options' => implode( ' - ', $active_options ), + 'WP Rocket Active Options' => implode( ' - ', $this->get_active_options() ), ]; } + + /** + * Returns the active options + * + * @return array + */ + public function get_active_options(): array { + $active_options = array_intersect_key( $this->to_send, array_filter( $this->options->get_options() ) ); + + // This filter is documented in inc/Engine/Media/AboveTheFold/Context/Context.php. + if ( wpm_apply_filters_typed( 'boolean', 'rocket_above_the_fold_optimization', true ) ) { + $active_options['optimize_critical_images'] = 'Optimize Critical Images'; + } + + // This filter is documented in inc/Engine/Optimization/LazyRenderContent/Context/Context.php. + if ( wpm_apply_filters_typed( 'boolean', 'rocket_lrc_optimization', true ) ) { + $active_options['automatic_lazy_rendering'] = 'Automatic Lazy Rendering'; + } + + return $active_options; + } } diff --git a/inc/Engine/Support/Meta.php b/inc/Engine/Support/Meta.php new file mode 100644 index 0000000000..54f56a658e --- /dev/null +++ b/inc/Engine/Support/Meta.php @@ -0,0 +1,160 @@ +mobile_detect = $mobile_detect; + $this->options = $options; + } + + /** + * Add the WP Rocket meta generator tag to the HTML + * + * @param string $html The HTML content. + * @return string + */ + public function add_meta_generator( $html ): string { + if ( rocket_bypass() ) { + return $html; + } + + if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ) { + return $html; + } + + /** + * Filters whether to disable the WP Rocket meta generator tag. + * + * @since 3.17.2 + * + * @param bool $disable True to disable, false otherwise. + */ + if ( wpm_apply_filters_typed( 'boolean', 'rocket_disable_meta_generator', false ) ) { + return $html; + } + + if ( rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_FOOTPRINT', false ) ) { + return $this->remove_features_comments( $html ); + } + + if ( is_user_logged_in() ) { + return $this->remove_features_comments( $html ); + } + + if ( false === preg_match_all( '//i', $html, $comments, PREG_PATTERN_ORDER ) ) { + return $html; + } + + $meta = $this->get_meta_tag( $comments['feature'] ); + + if ( empty( $meta ) ) { + return $html; + } + + $result = preg_replace( '/<\/head>/i', $meta . '', $html, 1 ); + + if ( null === $result ) { + return $html; + } + + return $this->remove_features_comments( $result ); + } + + /** + * Get the WP Rocket meta generator tag + * + * @param array $features Features to add to the meta tag. + * + * @return string + */ + private function get_meta_tag( array $features = [] ): string { + if ( $this->options->get( 'do_caching_mobile_files', 0 ) ) { + $features[] = $this->mobile_detect->isMobile() ? 'wpr_mobile' : 'wpr_desktop'; + } + + $dns_prefetch = rocket_get_dns_prefetch_domains(); + + if ( + ( + ! $this->options->get( 'cdn', 0 ) + && + ! empty( $dns_prefetch ) + ) + || + ( + $this->options->get( 'cdn', 0 ) + && + count( $dns_prefetch ) > 1 + ) + ) { + $features[] = 'wpr_dns_prefetch'; + } + + if ( (bool) $this->options->get( 'preload_links', 0 ) ) { + $features[] = 'wpr_preload_links'; + } + + if ( empty( $features ) ) { + return ''; + } + + $content = ''; + + /** + * Filters the display of the content attribute in the meta generator tag. + * + * @since 3.17.2 + * + * @param bool $display True to display, false otherwise. + */ + if ( wpm_apply_filters_typed( 'boolean', 'rocket_display_meta_generator_content', true ) ) { + $content = ' content="WP Rocket ' . rocket_get_constant( 'WP_ROCKET_VERSION', '' ) . '"'; + } + + $meta = ''; + + return $meta; + } + + /** + * Remove WP Rocket features comments from the HTML + * + * @param string $html The HTML content. + * + * @return string + */ + private function remove_features_comments( $html ): string { + $result = preg_replace( '//i', '', $html ); + + if ( null === $result ) { + return $html; + } + + return $result; + } +} diff --git a/inc/Engine/Support/ServiceProvider.php b/inc/Engine/Support/ServiceProvider.php index 3dea74891b..e16d26a386 100644 --- a/inc/Engine/Support/ServiceProvider.php +++ b/inc/Engine/Support/ServiceProvider.php @@ -1,11 +1,10 @@ getContainer()->get( 'options' ); + $this->getContainer()->add( 'mobile_detect', WP_Rocket_Mobile_Detect::class ); + $this->getContainer()->add( 'support_data', Data::class ) ->addArgument( $options ); - $this->getContainer()->add( 'rest_support', Rest::class ) + $this->getContainer()->add( 'support_rest', Rest::class ) ->addArgument( $this->getContainer()->get( 'support_data' ) ) ->addArgument( $options ); + $this->getContainer()->add( 'support_meta', Meta::class ) + ->addArgument( $this->getContainer()->get( 'mobile_detect' ) ) + ->addArgument( $options ); $this->getContainer()->addShared( 'support_subscriber', Subscriber::class ) - ->addArgument( $this->getContainer()->get( 'rest_support' ) ); + ->addArgument( $this->getContainer()->get( 'support_rest' ) ) + ->addArgument( $this->getContainer()->get( 'support_meta' ) ); } } diff --git a/inc/Engine/Support/Subscriber.php b/inc/Engine/Support/Subscriber.php index 9f0068ce82..88f58ddd74 100644 --- a/inc/Engine/Support/Subscriber.php +++ b/inc/Engine/Support/Subscriber.php @@ -1,4 +1,5 @@ rest = $rest; + $this->meta = $meta; } /** @@ -29,6 +39,7 @@ public function __construct( Rest $rest ) { public static function get_subscribed_events() { return [ 'rest_api_init' => 'register_support_route', + 'rocket_buffer' => [ 'add_meta_generator', PHP_INT_MAX ], ]; } @@ -42,4 +53,14 @@ public static function get_subscribed_events() { public function register_support_route() { $this->rest->register_route(); } + + /** + * Add the WP Rocket meta generator tag to the HTML + * + * @param string $html The HTML content. + * @return string + */ + public function add_meta_generator( $html ): string { + return $this->meta->add_meta_generator( $html ); + } } diff --git a/inc/classes/dependencies/mobiledetect/mobiledetectlib/Mobile_Detect.php b/inc/classes/dependencies/mobiledetect/mobiledetectlib/Mobile_Detect.php index cfb51b9244..47d2e9c5a3 100644 --- a/inc/classes/dependencies/mobiledetect/mobiledetectlib/Mobile_Detect.php +++ b/inc/classes/dependencies/mobiledetect/mobiledetectlib/Mobile_Detect.php @@ -18,7 +18,7 @@ * @author Nick Ilyin * @author: Victor Stanciu (original author) * - * @version 2.8.41 + * @version 2.8.45 * * Auto-generated isXXXX() magic methods. * php -a examples/dump_magic_methods.php @@ -255,7 +255,7 @@ class WP_Rocket_Mobile_Detect /** * Stores the version number of the current release. */ - const VERSION = '2.8.41'; + const VERSION = '2.8.45'; /** * A type WP_Rocket_for the version() method indicating a string return value. @@ -416,7 +416,7 @@ class WP_Rocket_Mobile_Detect 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)', // https://en.wikipedia.org/wiki/Pixel_C 'GoogleTablet' => 'Android.*Pixel C', - 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P1000|GT-P1003|GT-P1010|GT-P3105|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3108|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P7501|GT-N5100|GT-N5105|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-P5200|GT-P5210|GT-P5210X|SM-T311|SM-T310|SM-T310X|SM-T210|SM-T210R|SM-T211|SM-P600|SM-P601|SM-P605|SM-P900|SM-P901|SM-T217|SM-T217A|SM-T217S|SM-P6000|SM-T3100|SGH-I467|XE500|SM-T110|GT-P5220|GT-I9200X|GT-N5110X|GT-N5120|SM-P905|SM-T111|SM-T2105|SM-T315|SM-T320|SM-T320X|SM-T321|SM-T520|SM-T525|SM-T530NU|SM-T230NU|SM-T330NU|SM-T900|XE500T1C|SM-P605V|SM-P905V|SM-T337V|SM-T537V|SM-T707V|SM-T807V|SM-P600X|SM-P900X|SM-T210X|SM-T230|SM-T230X|SM-T325|GT-P7503|SM-T531|SM-T330|SM-T530|SM-T705|SM-T705C|SM-T535|SM-T331|SM-T800|SM-T700|SM-T537|SM-T807|SM-P907A|SM-T337A|SM-T537A|SM-T707A|SM-T807A|SM-T237|SM-T807P|SM-P607T|SM-T217T|SM-T337T|SM-T807T|SM-T116NQ|SM-T116BU|SM-P550|SM-T350|SM-T550|SM-T9000|SM-P9000|SM-T705Y|SM-T805|GT-P3113|SM-T710|SM-T810|SM-T815|SM-T360|SM-T533|SM-T113|SM-T335|SM-T715|SM-T560|SM-T670|SM-T677|SM-T377|SM-T567|SM-T357T|SM-T555|SM-T561|SM-T713|SM-T719|SM-T813|SM-T819|SM-T580|SM-T355Y?|SM-T280|SM-T817A|SM-T820|SM-W700|SM-P580|SM-T587|SM-P350|SM-P555M|SM-P355M|SM-T113NU|SM-T815Y|SM-T585|SM-T285|SM-T825|SM-W708|SM-T835|SM-T830|SM-T837V|SM-T720|SM-T510|SM-T387V|SM-P610|SM-T290|SM-T515|SM-T590|SM-T595|SM-T725|SM-T817P|SM-P585N0|SM-T395|SM-T295|SM-T865|SM-P610N|SM-P615|SM-T970|SM-T380|SM-T5950|SM-T905|SM-T231|SM-T500|SM-T860|SM-T536|SM-T837A|SM-X200|SM-T220|SM-T870|SM-X906C', // SCH-P709|SCH-P729|SM-T2558|GT-I9205 - Samsung Mega - treat them like a regular phone. + 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P1000|GT-P1003|GT-P1010|GT-P3105|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3108|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P7501|GT-N5100|GT-N5105|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-P5200|GT-P5210|GT-P5210X|SM-T311|SM-T310|SM-T310X|SM-T210|SM-T210R|SM-T211|SM-P600|SM-P601|SM-P605|SM-P900|SM-P901|SM-T217|SM-T217A|SM-T217S|SM-P6000|SM-T3100|SGH-I467|XE500|SM-T110|GT-P5220|GT-I9200X|GT-N5110X|GT-N5120|SM-P905|SM-T111|SM-T2105|SM-T315|SM-T320|SM-T320X|SM-T321|SM-T520|SM-T525|SM-T530NU|SM-T230NU|SM-T330NU|SM-T900|XE500T1C|SM-P605V|SM-P905V|SM-T337V|SM-T537V|SM-T707V|SM-T807V|SM-P600X|SM-P900X|SM-T210X|SM-T230|SM-T230X|SM-T325|GT-P7503|SM-T531|SM-T330|SM-T530|SM-T705|SM-T705C|SM-T535|SM-T331|SM-T800|SM-T700|SM-T537|SM-T807|SM-P907A|SM-T337A|SM-T537A|SM-T707A|SM-T807A|SM-T237|SM-T807P|SM-P607T|SM-T217T|SM-T337T|SM-T807T|SM-T116NQ|SM-T116BU|SM-P550|SM-T350|SM-T550|SM-T9000|SM-P9000|SM-T705Y|SM-T805|GT-P3113|SM-T710|SM-T810|SM-T815|SM-T360|SM-T533|SM-T113|SM-T335|SM-T715|SM-T560|SM-T670|SM-T677|SM-T377|SM-T567|SM-T357T|SM-T555|SM-T561|SM-T713|SM-T719|SM-T813|SM-T819|SM-T580|SM-T355Y?|SM-T280|SM-T817A|SM-T820|SM-W700|SM-P580|SM-T587|SM-P350|SM-P555M|SM-P355M|SM-T113NU|SM-T815Y|SM-T585|SM-T285|SM-T825|SM-W708|SM-T835|SM-T830|SM-T837V|SM-T720|SM-T510|SM-T387V|SM-P610|SM-T290|SM-T515|SM-T590|SM-T595|SM-T725|SM-T817P|SM-P585N0|SM-T395|SM-T295|SM-T865|SM-P610N|SM-P615|SM-T970|SM-T380|SM-T5950|SM-T905|SM-T231|SM-T500|SM-T860|SM-T536|SM-T837A|SM-X200|SM-T220|SM-T870|SM-X906C|SM-X700|SM-X706|SM-X706B|SM-X706U|SM-X706N|SM-X800|SM-X806|SM-X806B|SM-X806U|SM-X806N|SM-X900|SM-X906|SM-X906B|SM-X906U|SM-X906N|SM-P613', // SCH-P709|SCH-P729|SM-T2558|GT-I9205 - Samsung Mega - treat them like a regular phone. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html 'Kindle' => 'Kindle|Silk.*Accelerated|Android.*\b(KFOT|KFTT|KFJWI|KFJWA|KFOTE|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|WFJWAE|KFSAWA|KFSAWI|KFASWI|KFARWI|KFFOWI|KFGIWI|KFMEWI)\b|Android.*Silk/[0-9.]+ like Chrome/[0-9.]+ (?!Mobile)', // Only the Surface tablets with Windows RT are considered mobile. @@ -769,7 +769,7 @@ class WP_Rocket_Mobile_Detect // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/ // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011 // https://developers.facebook.com/docs/sharing/webmasters/crawler/ - 'Bot' => 'Googlebot|facebookexternalhit|Google-AMPHTML|s~amp-validator|AdsBot-Google|Google Keyword Suggestion|Facebot|YandexBot|YandexMobileBot|bingbot|ia_archiver|AhrefsBot|Ezooms|GSLFbot|WBSearchBot|Twitterbot|TweetmemeBot|Twikle|PaperLiBot|Wotbox|UnwindFetchor|Exabot|MJ12bot|YandexImages|TurnitinBot|Pingdom|contentkingapp|AspiegelBot', + 'Bot' => 'Googlebot|facebookexternalhit|Google-AMPHTML|s~amp-validator|AdsBot-Google|Google Keyword Suggestion|Facebot|YandexBot|YandexMobileBot|bingbot|ia_archiver|AhrefsBot|Ezooms|GSLFbot|WBSearchBot|Twitterbot|TweetmemeBot|Twikle|PaperLiBot|Wotbox|UnwindFetchor|Exabot|MJ12bot|YandexImages|TurnitinBot|Pingdom|contentkingapp|AspiegelBot|Semrush|DotBot|PetalBot|MetadataScraper', 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2', 'DesktopMode' => 'WPDesktop', 'TV' => 'SonyDTV|HbbTV', // experimental @@ -1180,10 +1180,10 @@ public static function getMobileDetectionRules() if (!$rules) { $rules = array_merge( - self::$phoneDevices, - self::$tabletDevices, - self::$operatingSystems, - self::$browsers + self::getPhoneDevices(), + self::getTabletDevices(), + self::getOperatingSystems(), + self::getBrowsers() ); } @@ -1208,11 +1208,11 @@ public function getMobileDetectionRulesExtended() if (!$rules) { // Merge all rules together. $rules = array_merge( - self::$phoneDevices, - self::$tabletDevices, - self::$operatingSystems, - self::$browsers, - self::$utilities + static::getPhoneDevices(), + static::getTabletDevices(), + static::getOperatingSystems(), + static::getBrowsers(), + static::getUtilities() ); } @@ -1406,7 +1406,7 @@ public function isTablet($userAgent = null, $httpHeaders = null) $this->setDetectionType(self::DETECTION_TYPE_MOBILE); - foreach (self::$tabletDevices as $_regex) { + foreach (static::getTabletDevices() as $_regex) { if ($this->match($_regex, $userAgent)) { return true; } @@ -1462,7 +1462,7 @@ public function match($regex, $userAgent = null) return false; } - $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches); + $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : (is_string($this->userAgent) ? $this->userAgent : '')), $matches); // If positive match is found, store the results WP_Rocket_for debug. if ($match) { $this->matchingRegex = $regex; @@ -1531,7 +1531,7 @@ public function version($propertyName, $type = self::VERSION_TYPE_STRING) $type = self::VERSION_TYPE_STRING; } - $properties = self::getProperties(); + $properties = static::getProperties(); // Check if the property exists in the properties array. if (true === isset($properties[$propertyName])) { @@ -1545,7 +1545,7 @@ public function version($propertyName, $type = self::VERSION_TYPE_STRING) $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString); // Identify and extract the version. - preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match); + preg_match(sprintf('#%s#is', $propertyPattern), (is_string($this->userAgent) ? $this->userAgent : ''), $match); if (false === empty($match[1])) { $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]); diff --git a/tests/Fixtures/inc/Engine/Support/Data/getSupportData.php b/tests/Fixtures/inc/Engine/Support/Data/getSupportData.php index ba803de2e7..504a41d44c 100644 --- a/tests/Fixtures/inc/Engine/Support/Data/getSupportData.php +++ b/tests/Fixtures/inc/Engine/Support/Data/getSupportData.php @@ -79,7 +79,7 @@ 'WP Rocket Version' => '3.7.5', 'Theme' => 'WordPress Default', 'Plugins Enabled' => 'Hello Dolly', - 'WP Rocket Active Options' => 'Mobile Cache - Disable Emojis - Combine Google Fonts - Preload - Heartbeat Control', + 'WP Rocket Active Options' => 'Mobile Cache - Disable Emojis - Combine Google Fonts - Preload - Heartbeat Control - Optimize Critical Images - Automatic Lazy Rendering', ], ], ]; diff --git a/tests/Fixtures/inc/Engine/Support/Meta/addMetaGenerator.php b/tests/Fixtures/inc/Engine/Support/Meta/addMetaGenerator.php new file mode 100644 index 0000000000..409be3e718 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Support/Meta/addMetaGenerator.php @@ -0,0 +1,60 @@ + [ + 'config' => [ + 'nowprocket' => 1, + ], + 'html' => '', + 'expected' => '', + ], + 'testShouldReturnDefaultWhenDNRO' => [ + 'config' => [ + 'donotrocketoptimize' => 1, + ], + 'html' => '', + 'expected' => '', + ], + 'testShouldReturnDefaultWhenWL' => [ + 'config' => [ + 'white_label_footprint' => 1, + ], + 'html' => '', + 'expected' => '', + ], + 'testShouldReturnDefaultWhenFilterDisabled' => [ + 'config' => [ + 'disable_meta' => true, + ], + 'html' => '', + 'expected' => '', + ], + 'testShouldReturnDefaultWhenLoggedIn' => [ + 'config' => [ + 'is_user_logged_in' => true, + ], + 'html' => '', + 'expected' => '', + ], + 'testShouldReturnDefaultWhenNoFeatures' => [ + 'config' => [ + 'disable_meta' => false, + 'cdn' => 0, + 'do_caching_mobile_files' => 0, + 'preload_links' => 0, + ], + 'html' => '', + 'expected' => '', + ], + 'testShouldReturnAddMeta' => [ + 'config' => [ + 'disable_meta' => false, + 'cdn' => 0, + 'do_caching_mobile_files' => 1, + 'preload_links' => 1, + 'is_mobile' => true, + ], + 'html' => '', + 'expected' => '', + ], +]; diff --git a/tests/Integration/inc/Addon/WebP/Subscriber/convertToWebp.php b/tests/Integration/inc/Addon/WebP/Subscriber/convertToWebp.php index 67c5f6e4e0..c2cc04b50e 100644 --- a/tests/Integration/inc/Addon/WebP/Subscriber/convertToWebp.php +++ b/tests/Integration/inc/Addon/WebP/Subscriber/convertToWebp.php @@ -21,6 +21,8 @@ public function set_up() { parent::set_up(); $this->unregisterAllCallbacksExcept( 'rocket_buffer', 'convert_to_webp', 16 ); + + add_filter( 'rocket_disable_meta_generator', '__return_true' ); } public function tear_down() { @@ -29,6 +31,7 @@ public function tear_down() { remove_filter( 'rocket_file_extensions_for_webp', [ $this, 'set_extensions_webp'] ); remove_filter( 'rocket_attributes_for_webp', [ $this, 'set_attributes_webp' ] ); remove_filter( 'rocket_cdn_cnames', [ $this, 'set_cdn_cnames'] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); $this->restoreWpHook( 'rocket_buffer' ); diff --git a/tests/Integration/inc/Engine/CDN/Subscriber/rewrite.php b/tests/Integration/inc/Engine/CDN/Subscriber/rewrite.php index 29b112c4eb..33cbba4fa2 100644 --- a/tests/Integration/inc/Engine/CDN/Subscriber/rewrite.php +++ b/tests/Integration/inc/Engine/CDN/Subscriber/rewrite.php @@ -12,12 +12,15 @@ class Test_Rewrite extends TestCase { public function set_up() { parent::set_up(); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); + $this->unregisterAllCallbacksExcept( 'rocket_buffer', 'rewrite', 2 ); } public function tear_down() { remove_filter( 'content_url', [ $this, 'setContentURL' ] ); remove_filter( 'includes_url', [ $this, 'setIncludesURL' ] ); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); $this->restoreWpHook( 'rocket_buffer' ); diff --git a/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php b/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php index a456930769..71a21a4cb3 100644 --- a/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php +++ b/tests/Integration/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php @@ -34,6 +34,8 @@ public static function tear_down_after_class() { public function set_up() { parent::set_up(); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); + $this->unregisterAllCallbacksExcept( 'rocket_buffer', 'maybe_apply_optimizations', 17 ); } @@ -41,6 +43,7 @@ public function tear_down() { unset( $_GET ); remove_filter( 'rocket_performance_hints_optimization_delay', [ $this, 'add_delay' ] ); remove_filter( 'pre_get_rocket_option_cache_logged_user', [ $this, 'get_cache_user' ] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); $this->restoreWpHook( 'rocket_buffer' ); if ( $this->user_id > 0 ) { diff --git a/tests/Integration/inc/Engine/Media/ImageDimensions/Subscriber/specifyImageDimensions.php b/tests/Integration/inc/Engine/Media/ImageDimensions/Subscriber/specifyImageDimensions.php index aec2370c49..170de944a6 100644 --- a/tests/Integration/inc/Engine/Media/ImageDimensions/Subscriber/specifyImageDimensions.php +++ b/tests/Integration/inc/Engine/Media/ImageDimensions/Subscriber/specifyImageDimensions.php @@ -17,6 +17,8 @@ class Test_SpecifyImageDimensions extends FilesystemTestCase { public function set_up() { parent::set_up(); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); + $this->unregisterAllCallbacksExcept('rocket_buffer', 'specify_image_dimensions', 17); } public function tear_down() { @@ -40,6 +42,7 @@ public function tear_down() { remove_filter( 'site_url', [ $this, 'setSiteUrl' ] ); remove_filter( 'home_url', [ $this, 'setHomeUrl' ] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); unset( $GLOBALS['wp'] ); diff --git a/tests/Integration/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php b/tests/Integration/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php index dec107d61c..58eca8d8dd 100644 --- a/tests/Integration/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php +++ b/tests/Integration/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php @@ -24,6 +24,7 @@ public function set_up() { add_filter('rocket_lazyload_excluded_src', [$this, 'exclude_lazyload']); add_filter('pre_http_request', [$this, 'mock_http'], 10, 3); add_filter('rocket_lazyload_css_hash', [$this, 'rocket_lazyload_css_hash'], 10, 2); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); } public function tear_down() { @@ -31,6 +32,8 @@ public function tear_down() { remove_filter('rocket_lazyload_excluded_src', [$this, 'exclude_lazyload']); remove_filter('pre_get_rocket_option_lazyload_css_bg_img', [$this, 'lazyload_css_bg_img']); remove_filter('rocket_lazyload_css_hash', [$this, 'rocket_lazyload_css_hash']); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); + $this->restoreWpHook('rocket_buffer'); parent::tear_down(); } diff --git a/tests/Integration/inc/Engine/Optimization/DelayJS/Subscriber/delayJs.php b/tests/Integration/inc/Engine/Optimization/DelayJS/Subscriber/delayJs.php index 52ef757140..b57db416fa 100644 --- a/tests/Integration/inc/Engine/Optimization/DelayJS/Subscriber/delayJs.php +++ b/tests/Integration/inc/Engine/Optimization/DelayJS/Subscriber/delayJs.php @@ -25,6 +25,7 @@ public function set_up() { // Disable ATF optimization to prevent DB request (unrelated to the test). add_filter( 'rocket_above_the_fold_optimization', '__return_false' ); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); $this->unregisterAllCallbacksExcept( 'rocket_buffer', 'delay_js', 26 ); } @@ -37,6 +38,7 @@ public function tear_down() { remove_filter( 'pre_get_rocket_option_delay_js', [ $this, 'set_delay_js' ] ); remove_filter( 'pre_get_rocket_option_delay_js_exclusions', [ $this, 'set_delay_js_exclusions' ] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); delete_transient( 'wpr_dynamic_lists' ); if ( isset( $this->post->ID ) ) { diff --git a/tests/Integration/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php b/tests/Integration/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php index 2d459e4f8c..ae219ecb7a 100644 --- a/tests/Integration/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php +++ b/tests/Integration/inc/Engine/Optimization/Minify/CSS/Subscriber/process.php @@ -29,6 +29,7 @@ public function set_up() { add_filter( 'pre_get_rocket_option_minify_css', [ $this, 'return_true' ] ); add_filter( 'pre_get_rocket_option_minify_css_key', [ $this, 'return_key' ] ); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); } public function tear_down() { @@ -38,6 +39,7 @@ public function tear_down() { remove_filter( 'pre_get_rocket_option_minify_css', [ $this, 'return_true' ] ); remove_filter( 'pre_get_rocket_option_minify_css_key', [ $this, 'return_key' ] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); $this->unsetSettings(); } diff --git a/tests/Integration/inc/Engine/Optimization/Minify/JS/Subscriber/process.php b/tests/Integration/inc/Engine/Optimization/Minify/JS/Subscriber/process.php index 807e036025..1519d7e33a 100644 --- a/tests/Integration/inc/Engine/Optimization/Minify/JS/Subscriber/process.php +++ b/tests/Integration/inc/Engine/Optimization/Minify/JS/Subscriber/process.php @@ -27,6 +27,8 @@ class Test_Process extends TestCase { public function set_up() { parent::set_up(); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); + $this->unregisterAllCallbacksExcept( 'rocket_buffer', 'process', 22 ); } @@ -40,6 +42,8 @@ public function tear_down() { remove_filter( 'pre_get_rocket_option_defer_all_js', [ $this, 'return_defer_all_js' ] ); remove_filter( 'rocket_excluded_inline_js_content', [ $this, 'set_excluded_inline'] ); remove_filter( 'rocket_minify_excluded_external_js', [ $this, 'set_excluded_external'] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); + delete_transient( 'wpr_dynamic_lists' ); $this->unsetSettings(); diff --git a/tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/treeshake.php b/tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/treeshake.php index 12062e5dfe..d4d8ce747d 100644 --- a/tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/treeshake.php +++ b/tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/treeshake.php @@ -23,6 +23,7 @@ public function set_up() { add_filter('pre_get_rocket_option_remove_unused_css', [$this, 'rucss']); add_filter('rocket_exclude_rucss_fonts_preload', [$this, 'exclude_fonts_preload']); add_filter('rocket_used_css_dir_level', [$this, 'used_css_dir_level']); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); } public function tear_down() { @@ -31,6 +32,7 @@ public function tear_down() { remove_filter('pre_get_rocket_option_remove_unused_css', [$this, 'rucss']); remove_filter('rocket_exclude_rucss_fonts_preload', [$this, 'exclude_fonts_preload']); remove_filter('rocket_used_css_dir_level', [$this, 'used_css_dir_level']); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); $this->restoreWpHook('rocket_buffer'); diff --git a/tests/Integration/inc/Engine/Support/Data/getSupportData.php b/tests/Integration/inc/Engine/Support/Data/getSupportData.php index f9e45ad4d5..c97d505485 100644 --- a/tests/Integration/inc/Engine/Support/Data/getSupportData.php +++ b/tests/Integration/inc/Engine/Support/Data/getSupportData.php @@ -19,12 +19,18 @@ public function set_up() { global $wp_version; + add_filter( 'rocket_above_the_fold_optimization', '__return_true' ); + add_filter( 'rocket_lrc_optimization', '__return_true' ); + $this->wp_version = $wp_version; } public function tear_down() { global $wp_version; + remove_filter( 'rocket_above_the_fold_optimization', '__return_true' ); + remove_filter( 'rocket_lrc_optimization', '__return_true' ); + $wp_version = $this->wp_version; parent::tear_down(); diff --git a/tests/Integration/inc/ThirdParty/Themes/Divi/disableImageDimensionsHeightPercentage.php b/tests/Integration/inc/ThirdParty/Themes/Divi/disableImageDimensionsHeightPercentage.php index 2b9b5391f0..d042089161 100644 --- a/tests/Integration/inc/ThirdParty/Themes/Divi/disableImageDimensionsHeightPercentage.php +++ b/tests/Integration/inc/ThirdParty/Themes/Divi/disableImageDimensionsHeightPercentage.php @@ -25,6 +25,7 @@ public function set_up() { $this->unregisterAllCallbacksExcept( 'rocket_buffer', 'specify_image_dimensions', 17 ); add_filter( 'rocket_specify_image_dimensions', '__return_true' ); + add_filter( 'rocket_disable_meta_generator', '__return_true' ); } public function tear_down() { @@ -34,6 +35,7 @@ public function tear_down() { remove_filter( 'rocket_specify_image_dimensions', '__return_true' ); unset( $GLOBALS['wp'] ); + remove_filter( 'rocket_disable_meta_generator', '__return_true' ); parent::tear_down(); } diff --git a/tests/Unit/inc/Addon/WebP/Subscriber/convertToWebp.php b/tests/Unit/inc/Addon/WebP/Subscriber/convertToWebp.php index 323a3ffc62..6adb3c7948 100644 --- a/tests/Unit/inc/Addon/WebP/Subscriber/convertToWebp.php +++ b/tests/Unit/inc/Addon/WebP/Subscriber/convertToWebp.php @@ -40,6 +40,11 @@ public function setUp(): void { * @dataProvider providerTestData */ public function testShouldReturnExpected( $config, $original, $expected ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + $this->options->shouldReceive( 'get' ) ->with( 'cache_webp', 0 ) ->andReturn( $config['webp'] ); diff --git a/tests/Unit/inc/Engine/CDN/CDN/rewrite.php b/tests/Unit/inc/Engine/CDN/CDN/rewrite.php index 0f6d13c994..79d0e4e8b1 100644 --- a/tests/Unit/inc/Engine/CDN/CDN/rewrite.php +++ b/tests/Unit/inc/Engine/CDN/CDN/rewrite.php @@ -3,7 +3,7 @@ namespace WP_Rocket\Tests\Unit\inc\Engine\CDN\CDN; use Mockery; -use Brain\Monkey\Functions; +use Brain\Monkey\{Filters, Functions}; use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\CDN\CDN; @@ -26,6 +26,11 @@ public function setUp() : void { * @dataProvider providerTestData */ public function testShouldRewriteURLToCDN( $home_url, $original, $expected ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + Functions\when( 'content_url' )->justReturn( "{$home_url}/wp-content/" ); Functions\when( 'includes_url' )->justReturn( "{$home_url}/wp-includes/" ); Functions\when( 'wp_upload_dir' )->justReturn( "{$home_url}/wp-content/uploads/" ); diff --git a/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/insertCriticalCssBuffer.php b/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/insertCriticalCssBuffer.php index 648919b6b4..f653214891 100644 --- a/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/insertCriticalCssBuffer.php +++ b/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/insertCriticalCssBuffer.php @@ -2,7 +2,7 @@ namespace WP_Rocket\Tests\Unit\inc\Engine\CriticalPath\CriticalCSSSubscriber; -use Brain\Monkey\Functions; +use Brain\Monkey\{Filters, Functions}; use WP_Rocket\Tests\Unit\FilesystemTestCase; /** @@ -33,6 +33,11 @@ public function setUp() : void { * @dataProvider providerTestData */ public function testShouldInsertCriticalCSS( $config, $expected, $expected_html = null ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + $critical_css_path = $this->config['vfs_dir'] . '1/'; $this->assertTrue( $this->filesystem->is_dir( $critical_css_path ) ); diff --git a/tests/Unit/inc/Engine/Media/ImageDimensions/ImageDimensions/specifyImageDimensions.php b/tests/Unit/inc/Engine/Media/ImageDimensions/ImageDimensions/specifyImageDimensions.php index 9741c10a22..8636d63684 100644 --- a/tests/Unit/inc/Engine/Media/ImageDimensions/ImageDimensions/specifyImageDimensions.php +++ b/tests/Unit/inc/Engine/Media/ImageDimensions/ImageDimensions/specifyImageDimensions.php @@ -52,6 +52,11 @@ public function testShouldAddMissedDimensions( $input, $config, $expected ) { return $site_url . ltrim( $path, '/' ); } ); + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + if ( isset( $config['rocket_specify_image_dimensions_filter'] ) ){ Filters\expectApplied( 'rocket_specify_image_dimensions' ) ->once() diff --git a/tests/Unit/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php b/tests/Unit/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php index 1062346ae4..a2b5a8e2ae 100644 --- a/tests/Unit/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php +++ b/tests/Unit/inc/Engine/Media/Lazyload/CSS/Subscriber/maybeReplaceCssImages.php @@ -23,6 +23,11 @@ public function testShouldReturnAsExpected( $config, $expected ) { Filters\expectApplied('rocket_generate_lazyloaded_css')->with($expected['data'])->andReturn($config['data']); } + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + $this->context->shouldReceive('is_allowed')->andReturn($config['is_allowed']); $this->assertSame($expected['output'], $this->subscriber->maybe_replace_css_images($config['html'])); } diff --git a/tests/Unit/inc/Engine/Optimization/DelayJS/HTML/delayJs.php b/tests/Unit/inc/Engine/Optimization/DelayJS/HTML/delayJs.php index c94000547c..0ccd195c8c 100644 --- a/tests/Unit/inc/Engine/Optimization/DelayJS/HTML/delayJs.php +++ b/tests/Unit/inc/Engine/Optimization/DelayJS/HTML/delayJs.php @@ -3,6 +3,7 @@ namespace WP_Rocket\Tests\Unit\inc\Engine\Optimization\DelayJS\HTML; use Mockery; +use Brain\Monkey\Filters; use Brain\Monkey\Functions; use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\Optimization\DelayJS\HTML; @@ -38,6 +39,11 @@ public function testShouldProcessScriptHTML( $config, $html, $expected ) { $this->logger->allows()->debug(Mockery::any()); + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + Functions\expect( 'rocket_bypass' ) ->atMost() ->once() diff --git a/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/optimize.php b/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/optimize.php index 30575b979d..917d5d9ab4 100644 --- a/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/optimize.php +++ b/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/optimize.php @@ -3,6 +3,7 @@ namespace WP_Rocket\Tests\Unit\inc\Engine\Optimization\LazyRenderContent\Frontend\Controller; +use Brain\Monkey\Filters; use Mockery; use WP_Rocket\Engine\Optimization\LazyRenderContent\Context\Context; use WP_Rocket\Engine\Optimization\LazyRenderContent\Database\Rows\LazyRenderContent as LRCRow; @@ -26,6 +27,11 @@ public function set_up() { * @dataProvider configTestData */ public function testShouldReturnExpected( $config, $html, $expected ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + $row = $this->getMockBuilder( LRCRow::class ) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Unit/inc/Engine/Optimization/Minify/CSS/Minify/optimize.php b/tests/Unit/inc/Engine/Optimization/Minify/CSS/Minify/optimize.php index f5baf92726..b6c1006dd7 100644 --- a/tests/Unit/inc/Engine/Optimization/Minify/CSS/Minify/optimize.php +++ b/tests/Unit/inc/Engine/Optimization/Minify/CSS/Minify/optimize.php @@ -34,6 +34,11 @@ public function setUp() : void { * @dataProvider providerTestData */ public function testShouldMinifyCSS( $original, $expected, $cdn_host, $cdn_url, $site_url, $external_url, $excluded_css = [], $has_integrity = false, $valid_integrity = true ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + Filters\expectApplied( 'rocket_cdn_hosts' ) ->zeroOrMoreTimes() ->with( [], [ 'all', 'css_and_js', 'css' ] ) diff --git a/tests/Unit/inc/Engine/Optimization/Minify/JS/Combine/optimize.php b/tests/Unit/inc/Engine/Optimization/Minify/JS/Combine/optimize.php index 6a0f4e4a5a..e69f392bef 100644 --- a/tests/Unit/inc/Engine/Optimization/Minify/JS/Combine/optimize.php +++ b/tests/Unit/inc/Engine/Optimization/Minify/JS/Combine/optimize.php @@ -62,6 +62,11 @@ public function setUp(): void { * @dataProvider providerTestData */ public function testShouldCombineJS( $original, $expected, $config ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + $this->options->shouldReceive( 'get' ) ->with( 'minify_js_key', 'rocket_uniqid' ) ->andReturn( 'rocket_uniqid' ); diff --git a/tests/Unit/inc/Engine/Optimization/Minify/JS/Minify/optimize.php b/tests/Unit/inc/Engine/Optimization/Minify/JS/Minify/optimize.php index b8e17bedff..352ddb5f8a 100644 --- a/tests/Unit/inc/Engine/Optimization/Minify/JS/Minify/optimize.php +++ b/tests/Unit/inc/Engine/Optimization/Minify/JS/Minify/optimize.php @@ -47,6 +47,11 @@ public function setUp() : void { * @dataProvider providerTestData */ public function testShouldMinifyJS( $original, $expected, $cdn_hosts, $cdn_url, $site_url, $external_url, $has_integrity = false, $valid_integrity = true ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); + Filters\expectApplied( 'rocket_minify_excluded_external_js' ) ->andReturn( ['cse.google.com/cse.js'] ); diff --git a/tests/Unit/inc/Engine/Optimization/RUCSS/Controller/UsedCSS/treeshake.php b/tests/Unit/inc/Engine/Optimization/RUCSS/Controller/UsedCSS/treeshake.php index c52583b2e7..5b7aea1781 100644 --- a/tests/Unit/inc/Engine/Optimization/RUCSS/Controller/UsedCSS/treeshake.php +++ b/tests/Unit/inc/Engine/Optimization/RUCSS/Controller/UsedCSS/treeshake.php @@ -1,6 +1,6 @@ atMost() + ->once() + ->andReturn( true ); + $wp = new WP(); $GLOBALS['wp'] = $wp; diff --git a/tests/Unit/inc/Engine/Preload/Fonts/preloadFonts.php b/tests/Unit/inc/Engine/Preload/Fonts/preloadFonts.php index 9da31b847d..2b81779026 100644 --- a/tests/Unit/inc/Engine/Preload/Fonts/preloadFonts.php +++ b/tests/Unit/inc/Engine/Preload/Fonts/preloadFonts.php @@ -37,6 +37,10 @@ public function setUp() : void { public function testShouldAddPreloadTagsWhenValidFonts( $buffer, $bypass, $filter, $rocket_options, $expected ) { Functions\when( 'rocket_bypass' )->justReturn( $bypass ); Functions\when( 'home_url' )->justReturn( 'http://example.org' ); + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->atMost() + ->once() + ->andReturn( true ); if ( $filter ) { Filters\expectApplied( 'rocket_disable_preload_fonts' ) diff --git a/tests/Unit/inc/Engine/Support/Meta/addMetaGenerator.php b/tests/Unit/inc/Engine/Support/Meta/addMetaGenerator.php new file mode 100644 index 0000000000..e3d29a473a --- /dev/null +++ b/tests/Unit/inc/Engine/Support/Meta/addMetaGenerator.php @@ -0,0 +1,79 @@ +options = Mockery::mock( Options_Data::class ); + $this->mobile_detect = Mockery::mock( WP_Rocket_Mobile_Detect::class ); + $this->meta = new Meta( $this->mobile_detect, $this->options ); + } + + /** + * @dataProvider configTestData + */ + public function testShouldReturnExpected( $config, $html, $expected ) { + Functions\when( 'rocket_bypass' )->alias( function() use ( $config ) { + return isset( $config['nowprocket'] ) ? (bool) $config['nowprocket'] : false; + } ); + + $this->white_label_footprint = $config['white_label_footprint'] ?? null; + $this->donotrocketoptimize = $config['donotrocketoptimize'] ?? null; + $this->rocket_version = '3.17'; + + if ( isset( $config['disable_meta'] ) ) { + Filters\expectApplied( 'rocket_disable_meta_generator' ) + ->once() + ->andReturn( $config['disable_meta'] ); + } + + Functions\when( 'is_user_logged_in' )->justReturn( $config['is_user_logged_in'] ?? false ); + + if ( isset( $config['do_caching_mobile_files'] ) ) { + $this->options->shouldReceive( 'get' ) + ->with( 'do_caching_mobile_files', 0 ) + ->andReturn( $config['do_caching_mobile_files'] ); + } + + if ( isset( $config['cdn'] ) ) { + $this->options->shouldReceive( 'get' ) + ->with( 'cdn', 0 ) + ->andReturn( $config['cdn'] ); + } + + Functions\when( 'rocket_get_dns_prefetch_domains' )->justReturn( [] ); + + if ( isset( $config['preload_links'] ) ) { + $this->options->shouldReceive( 'get' ) + ->with( 'preload_links', 0 ) + ->andReturn( $config['preload_links'] ); + } + + $this->mobile_detect->shouldReceive( 'isMobile' ) + ->andReturn( $config['is_mobile'] ?? false ); + + $this->assertSame( + $expected, + $this->meta->add_meta_generator( $html ) + ); + } +}