Skip to content

Commit

Permalink
use CommentTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabrisrp committed Oct 15, 2024
1 parent 9d6d0c8 commit 921c7d7
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 13 deletions.
5 changes: 5 additions & 0 deletions inc/Addon/WebP/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
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.
*
* @since 3.4
*/
class Subscriber extends AbstractWebp implements Subscriber_Interface {
use CommentTrait;

/**
* Options_Data instance.
*
Expand Down Expand Up @@ -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 . '<!-- Rocket has webp -->';
}

Expand Down
5 changes: 4 additions & 1 deletion inc/Engine/CDN/CDN.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
namespace WP_Rocket\Engine\CDN;

use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Support\CommentTrait;

/**
* CDN class
*
* @since 3.4
*/
class CDN {
use CommentTrait;

/**
* WP Rocket Options instance
*
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/CriticalPath/CriticalCSSSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -16,6 +17,7 @@
*/
class CriticalCSSSubscriber implements Subscriber_Interface {
use RegexTrait;
use CommentTrait;

/**
* Instance of Critical CSS.
Expand Down Expand Up @@ -602,7 +604,9 @@ public function insert_critical_css_buffer( $buffer ) {
1
);

return preg_replace( '#</body>#iU', $this->return_remove_cpcss_script() . '</body>', $buffer, 1 );
$buffer = preg_replace( '#</body>#iU', $this->return_remove_cpcss_script() . '</body>', $buffer, 1 );

Check notice on line 607 in inc/Engine/CriticalPath/CriticalCSSSubscriber.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/CriticalPath/CriticalCSSSubscriber.php#L607

Expected 1 space after "="; 2 found

return $this->add_meta_comment( 'async_css', $buffer );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/Media/AboveTheFold/Frontend/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/Media/ImageDimensions/ImageDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/Media/Lazyload/CSS/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
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;

class Subscriber implements Subscriber_Interface, LoggerAwareInterface {
use LoggerAware;
use RegexTrait;
use CommentTrait;

/**
* Extract background images from CSS.
Expand Down Expand Up @@ -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;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions inc/Engine/Media/Lazyload/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -18,6 +19,7 @@
class Subscriber implements Subscriber_Interface {
use RegexTrait;
use CanLazyloadTrait;
use CommentTrait;

const SCRIPT_VERSION = '17.8.3';

Expand Down Expand Up @@ -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() ) {
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion inc/Engine/Optimization/DeferJS/DeferJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/Optimization/DelayJS/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -122,7 +124,9 @@ function ( $value ) {
$this->excluded
);

return $this->parse( $html );
$html = $this->parse( $html );

return $this->add_meta_comment( 'delay_js', $html );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
4 changes: 3 additions & 1 deletion inc/Engine/Optimization/Minify/CSS/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -13,6 +14,7 @@
*/
class Minify extends AbstractCSSOptimization implements ProcessorInterface {
use CSSTrait;
use CommentTrait;

/**
* Minifies CSS files
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
5 changes: 4 additions & 1 deletion inc/Engine/Optimization/Minify/JS/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -15,6 +16,8 @@
* @since 3.1
*/
class Combine extends AbstractJSOptimization implements ProcessorInterface {
use CommentTrait;

/**
* Minifier instance
*
Expand Down Expand Up @@ -155,7 +158,7 @@ public function optimize( $html ) {
]
);

return $html;
return $this->add_meta_comment( 'minify_concatenate_js', $html );
}

/**
Expand Down
5 changes: 4 additions & 1 deletion inc/Engine/Optimization/Minify/JS/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -11,6 +12,8 @@
* @since 3.1
*/
class Minify extends AbstractJSOptimization implements ProcessorInterface {
use CommentTrait;

/**
* Minifies JS files
*
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
4 changes: 3 additions & 1 deletion inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
12 changes: 11 additions & 1 deletion inc/Engine/Preload/Fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -12,6 +13,7 @@
* @since 3.6
*/
class Fonts implements Subscriber_Interface {
use CommentTrait;

/**
* WP Rocket Options instance.
Expand Down Expand Up @@ -114,7 +116,15 @@ public function preload_fonts( $html ): string {
);
}

return preg_replace( '#</title>#', $preloads, $html, 1 );
$result = preg_replace( '#</title>#', $preloads, $html, 1 );

if ( null === $result ) {
return $html;
}

$result = $this->add_meta_comment( 'preload_fonts', $result );

return $result;
}

/**
Expand Down

0 comments on commit 921c7d7

Please sign in to comment.