From 5e7d40c68160a54121c801a1439c9245d2ab8bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Wed, 12 Feb 2025 02:29:14 +0100 Subject: [PATCH 01/15] Add Preload Fonts feature with service provider and context integration --- .../PerformanceHints/ServiceProvider.php | 2 + .../Media/PreloadFonts/Context/Context.php | 28 +++++ inc/Engine/Media/PreloadFonts/Factory.php | 112 ++++++++++++++++++ .../PreloadFonts/Frontend/Controller.php | 69 +++++++++++ .../Media/PreloadFonts/ServiceProvider.php | 85 +++++++++++++ 5 files changed, 296 insertions(+) create mode 100644 inc/Engine/Media/PreloadFonts/Context/Context.php create mode 100644 inc/Engine/Media/PreloadFonts/Factory.php create mode 100644 inc/Engine/Media/PreloadFonts/Frontend/Controller.php create mode 100644 inc/Engine/Media/PreloadFonts/ServiceProvider.php diff --git a/inc/Engine/Common/PerformanceHints/ServiceProvider.php b/inc/Engine/Common/PerformanceHints/ServiceProvider.php index 1330e11e3a..82367e5c4c 100644 --- a/inc/Engine/Common/PerformanceHints/ServiceProvider.php +++ b/inc/Engine/Common/PerformanceHints/ServiceProvider.php @@ -49,6 +49,7 @@ class ServiceProvider extends AbstractServiceProvider { 'performance_hints_warmup_subscriber', 'performance_hints_admin_bar', 'performance_hints_clean', + 'preload_fonts_factory', ]; /** @@ -74,6 +75,7 @@ public function register(): void { $factory_array = [ $this->getContainer()->get( 'atf_factory' ), $this->getContainer()->get( 'lrc_factory' ), + $this->getContainer()->get( 'preload_fonts_factory' ), ]; foreach ( $factory_array as $factory ) { diff --git a/inc/Engine/Media/PreloadFonts/Context/Context.php b/inc/Engine/Media/PreloadFonts/Context/Context.php new file mode 100644 index 0000000000..d4884ec89d --- /dev/null +++ b/inc/Engine/Media/PreloadFonts/Context/Context.php @@ -0,0 +1,28 @@ +ajax_controller = $ajax_controller; + $this->frontend_controller = $frontend_controller; + $this->table = $table; + $this->queries = $queries; + $this->context = $context; + } + + /** + * Provides an Ajax controller object. + * + * @return AjaxControllerInterface + */ + public function get_ajax_controller(): AjaxControllerInterface { + return $this->ajax_controller; + } + + /** + * Provides a Frontend object. + * + * @return FrontendControllerInterface + */ + public function get_frontend_controller(): FrontendControllerInterface { + return $this->frontend_controller; + } + + /** + * Provides a Table object. + * + * @return TableInterface + */ + public function table(): TableInterface { + return $this->table; + } + + /** + * Provides a Queries object. + * + * @return QueriesInterface + */ + public function queries(): QueriesInterface { + return $this->queries; + } + + /** + * Provides a Context object. + * + * @return ContextInterface + */ + public function get_context(): ContextInterface { + return $this->context; + } +} diff --git a/inc/Engine/Media/PreloadFonts/Frontend/Controller.php b/inc/Engine/Media/PreloadFonts/Frontend/Controller.php new file mode 100644 index 0000000000..f27b3b5879 --- /dev/null +++ b/inc/Engine/Media/PreloadFonts/Frontend/Controller.php @@ -0,0 +1,69 @@ +provides, true ); + } + + /** + * Registers the classes in the container + * + * @return void + */ + public function register(): void { + $this->getContainer()->addShared( 'pf_table', Table::class ); + $this->getContainer()->add( 'pf_query', Queries::class ); + $this->getContainer()->add( 'pf_context', Context::class ); + + $this->getContainer()->get( 'pf_table' ); + + $this->getContainer()->add( 'pf_controller', FrontController::class ) + ->addArguments( + [ + $this->getContainer()->get( 'options' ), + $this->getContainer()->get( 'pf_query' ), + $this->getContainer()->get( 'pf_context' ), + ] + ); + + $this->getContainer()->add( 'atf_ajax_controller', AJAXControllerTrait::class ) + ->addArguments( + [ + $this->getContainer()->get( 'pf_query' ), + $this->getContainer()->get( 'pf_context' ), + ] + ); + + $this->getContainer()->addShared( 'pf_factory', Factory::class ) + ->addArguments( + [ + $this->getContainer()->get( 'pf_ajax_controller' ), + $this->getContainer()->get( 'pf_controller' ), + $this->getContainer()->get( 'pf_table' ), + $this->getContainer()->get( 'pf_query' ), + $this->getContainer()->get( 'pf_context' ), + ] + ); + } +} From 32c972b45e01305a6926db09a59f200d908755d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Thu, 13 Feb 2025 02:31:40 +0100 Subject: [PATCH 02/15] Fix missing constructor --- .../PreloadFonts/Frontend/Controller.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/inc/Engine/Media/PreloadFonts/Frontend/Controller.php b/inc/Engine/Media/PreloadFonts/Frontend/Controller.php index f27b3b5879..03080cbd5f 100644 --- a/inc/Engine/Media/PreloadFonts/Frontend/Controller.php +++ b/inc/Engine/Media/PreloadFonts/Frontend/Controller.php @@ -3,9 +3,45 @@ namespace WP_Rocket\Engine\Media\PreloadFonts\Frontend; +use WP_Rocket\Admin\Options_Data; use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface; +use WP_Rocket\Engine\Media\PreloadFonts\Database\Queries\PreloadFonts as PFQuery; +use WP_Rocket\Engine\Media\PreloadFonts\Context\Context; class Controller implements ControllerInterface { + /** + * Options instance + * + * @var Options_Data + */ + private $options; + + /** + * Queries instance + * + * @var ATFQuery + */ + private $query; + + /** + * Context instance. + * + * @var Context + */ + private $context; + + /** + * Constructor + * + * @param Options_Data $options Options instance. + * @param ATFQuery $query Queries instance. + * @param Context $context Context instance. + */ + public function __construct( Options_Data $options, PFQuery $query, Context $context ) { + $this->options = $options; + $this->query = $query; + $this->context = $context; + } /** * Applies optimization. * From 7d06d1df7362b4572415e86512b3c4b8001b0e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Thu, 13 Feb 2025 02:31:50 +0100 Subject: [PATCH 03/15] Fix references --- inc/Engine/Common/PerformanceHints/ServiceProvider.php | 3 +-- inc/Engine/Media/PreloadFonts/ServiceProvider.php | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/Engine/Common/PerformanceHints/ServiceProvider.php b/inc/Engine/Common/PerformanceHints/ServiceProvider.php index 82367e5c4c..2c44b92c30 100644 --- a/inc/Engine/Common/PerformanceHints/ServiceProvider.php +++ b/inc/Engine/Common/PerformanceHints/ServiceProvider.php @@ -49,7 +49,6 @@ class ServiceProvider extends AbstractServiceProvider { 'performance_hints_warmup_subscriber', 'performance_hints_admin_bar', 'performance_hints_clean', - 'preload_fonts_factory', ]; /** @@ -75,7 +74,7 @@ public function register(): void { $factory_array = [ $this->getContainer()->get( 'atf_factory' ), $this->getContainer()->get( 'lrc_factory' ), - $this->getContainer()->get( 'preload_fonts_factory' ), + // $this->getContainer()->get( 'preload_fonts_factory' ), ]; foreach ( $factory_array as $factory ) { diff --git a/inc/Engine/Media/PreloadFonts/ServiceProvider.php b/inc/Engine/Media/PreloadFonts/ServiceProvider.php index 21e099e9cc..576bf000a0 100644 --- a/inc/Engine/Media/PreloadFonts/ServiceProvider.php +++ b/inc/Engine/Media/PreloadFonts/ServiceProvider.php @@ -8,7 +8,7 @@ use WP_Rocket\Engine\Media\PreloadFonts\Database\Queries\PreloadFonts as PreloadFontsQuery; use WP_Rocket\Engine\Media\PreloadFonts\AJAX\Controller as AJAXController; use WP_Rocket\Engine\Media\PreloadFonts\Context\Context; -use WP_Rocket\Engine\Media\PreloadFonts\Frontend\Controller as FrontController; +use WP_Rocket\Engine\Media\PreloadFonts\Frontend\Controller as FrontendController; use WP_Rocket\Engine\Media\PreloadFonts\Frontend\Subscriber as FrontendSubscriber; class ServiceProvider extends AbstractServiceProvider { @@ -27,6 +27,7 @@ class ServiceProvider extends AbstractServiceProvider { 'preload_fonts_ajax_controller', 'preload_fonts_context', 'preload_fonts_frontend_subscriber', + 'preload_fonts_front_controller', ]; /** @@ -54,7 +55,7 @@ public function register(): void { $this->getContainer()->add( 'preload_fonts_query', PreloadFontsQuery::class ); $this->getContainer()->add( 'preload_fonts_context', Context::class ) ->addArgument( $options ); - $this->getContainer()->add( 'preload_fonts_front_controller', FrontController::class ) + $this->getContainer()->add( 'preload_fonts_front_controller', FrontendController::class ) ->addArguments( [ $this->getContainer()->get( 'options' ), @@ -73,7 +74,7 @@ public function register(): void { $this->getContainer()->addShared( 'preload_fonts_frontend_subscriber', FrontendSubscriber::class ); - $this->getContainer()->addShared( 'pf_factory', Factory::class ) + $this->getContainer()->addShared( 'preload_fonts_factory', Factory::class ) ->addArguments( [ $this->getContainer()->get( 'preload_fonts_ajax_controller' ), From ca9bd704a4f25431fc6e246cf53476352469f137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Thu, 13 Feb 2025 02:50:54 +0100 Subject: [PATCH 04/15] Add test --- .../Subscriber/maybe_apply_optimizations.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php index 05c71f65b5..0a004cfc43 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php @@ -97,6 +97,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_output_with_beacon, ], @@ -109,6 +112,37 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], + ], + 'expected' => $html_output_with_beacon, + ], + 'shouldAddBeaconWhenOnlyMissingPreloadFontsData' => [ + 'config' => [ + 'html' => $html_input, + 'atf' => [ + 'row' => [ + 'row' => [ + 'status' => 'completed', + 'url' => 'http://example.org', + 'lcp' => json_encode( (object) [ + 'type' => 'img', + 'src' => 'http://example.org/wp-content/uploads/image.jpg', + ] ), + 'viewport' => json_encode( [ + 0 => (object) [ + 'type' => 'img', + 'src' => 'http://example.org/wp-content/uploads/image2.jpg', + ], + ] ), + ], + ], + ], + 'lrc' => $lrc, + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_output_with_beacon, ], From 66e41dc48a2799df15e1b330d107beef9ecfb73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Thu, 13 Feb 2025 02:54:34 +0100 Subject: [PATCH 05/15] Fix phpstan --- inc/Engine/Media/PreloadFonts/Frontend/Controller.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/inc/Engine/Media/PreloadFonts/Frontend/Controller.php b/inc/Engine/Media/PreloadFonts/Frontend/Controller.php index 03080cbd5f..fe6fc7c632 100644 --- a/inc/Engine/Media/PreloadFonts/Frontend/Controller.php +++ b/inc/Engine/Media/PreloadFonts/Frontend/Controller.php @@ -14,27 +14,27 @@ class Controller implements ControllerInterface { * * @var Options_Data */ - private $options; + private $options; // @phpstan-ignore-line Use of this will come later. /** * Queries instance * - * @var ATFQuery + * @var PFQuery */ - private $query; + private $query; // @phpstan-ignore-line Use of this will come later. /** * Context instance. * * @var Context */ - private $context; + private $context; // @phpstan-ignore-line Use of this will come later. /** * Constructor * * @param Options_Data $options Options instance. - * @param ATFQuery $query Queries instance. + * @param PFQuery $query Queries instance. * @param Context $context Context instance. */ public function __construct( Options_Data $options, PFQuery $query, Context $context ) { @@ -42,6 +42,7 @@ public function __construct( Options_Data $options, PFQuery $query, Context $con $this->query = $query; $this->context = $context; } + /** * Applies optimization. * From 031cfa77261e212d0861fa0c314b949ce1a60392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Thu, 13 Feb 2025 03:00:00 +0100 Subject: [PATCH 06/15] Add shared factory to service provider --- inc/Engine/Common/PerformanceHints/ServiceProvider.php | 2 +- inc/Engine/Media/PreloadFonts/ServiceProvider.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/Engine/Common/PerformanceHints/ServiceProvider.php b/inc/Engine/Common/PerformanceHints/ServiceProvider.php index 2c44b92c30..7621867d0c 100644 --- a/inc/Engine/Common/PerformanceHints/ServiceProvider.php +++ b/inc/Engine/Common/PerformanceHints/ServiceProvider.php @@ -74,7 +74,7 @@ public function register(): void { $factory_array = [ $this->getContainer()->get( 'atf_factory' ), $this->getContainer()->get( 'lrc_factory' ), - // $this->getContainer()->get( 'preload_fonts_factory' ), + $this->getContainer()->get( 'preload_fonts_factory' ), ]; foreach ( $factory_array as $factory ) { diff --git a/inc/Engine/Media/PreloadFonts/ServiceProvider.php b/inc/Engine/Media/PreloadFonts/ServiceProvider.php index 576bf000a0..fabd2fa10a 100644 --- a/inc/Engine/Media/PreloadFonts/ServiceProvider.php +++ b/inc/Engine/Media/PreloadFonts/ServiceProvider.php @@ -28,6 +28,7 @@ class ServiceProvider extends AbstractServiceProvider { 'preload_fonts_context', 'preload_fonts_frontend_subscriber', 'preload_fonts_front_controller', + 'preload_fonts_factory', ]; /** From 546f158e8d2d216b7730f0a581ca78ade44dab19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Thu, 13 Feb 2025 03:42:38 +0100 Subject: [PATCH 07/15] Adds tests --- .../HTML/no_closing_body_tag_output.html | 3 +- .../HTML/output_double_body_tag.html | 2 +- .../Subscriber/HTML/output_w_beacon.html | 2 +- .../HTML/output_with_beacon_and_atf_opt.html | 2 +- .../output_with_beacon_and_only_lrc_opt.html | 2 +- .../Subscriber/maybe_apply_optimizations.php | 90 +++++++++++++++++++ tests/Integration/DBTrait.php | 24 +++++ .../Subscriber/maybe_apply_optimizations.php | 6 ++ 8 files changed, 126 insertions(+), 5 deletions(-) diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/no_closing_body_tag_output.html b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/no_closing_body_tag_output.html index ac76359cdb..e038a7e2a4 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/no_closing_body_tag_output.html +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/no_closing_body_tag_output.html @@ -4,4 +4,5 @@ - + + diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_double_body_tag.html b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_double_body_tag.html index 44ba1df4c0..c3515006ff 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_double_body_tag.html +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_double_body_tag.html @@ -18,5 +18,5 @@

Iframe Header

" width="600" height="400" style="border:none;"> - + diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_w_beacon.html b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_w_beacon.html index a4fe6228a8..f2d5eece95 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_w_beacon.html +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_w_beacon.html @@ -3,5 +3,5 @@ Test - + diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_atf_opt.html b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_atf_opt.html index 8e8bf4b6da..9f5b519d52 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_atf_opt.html +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_atf_opt.html @@ -4,5 +4,5 @@ Sample alt - + diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_only_lrc_opt.html b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_only_lrc_opt.html index 7016432590..b8d92ac663 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_only_lrc_opt.html +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/HTML/output_with_beacon_and_only_lrc_opt.html @@ -8,5 +8,5 @@
- + diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php index 0a004cfc43..eba7c2a15a 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Frontend/Subscriber/maybe_apply_optimizations.php @@ -33,6 +33,17 @@ ], ]; +$preload_fonts = [ + 'row' => [ + 'status' => 'completed', + 'url' => 'http://example.org', + 'fonts' => json_encode( [ + 'font1', + 'font2', + ] ), + ], +]; + return [ 'test_data' => [ 'shouldReturnOriginalWhenBypassAndRow' => [ @@ -56,6 +67,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_input, ], @@ -69,6 +81,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_input, ], @@ -83,6 +98,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_input, ], @@ -156,6 +174,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_output_with_beacon, ], @@ -179,6 +200,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_output_with_preload, ], @@ -204,6 +226,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_output, ], @@ -225,6 +248,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_bg_responsive_imgset_template.php'), ], @@ -246,6 +270,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_bg_responsive_webkit_template.php'), ], @@ -267,6 +292,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_layered_bg.php'), ], @@ -287,6 +313,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_single_bg.php'), ], @@ -307,6 +334,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_responsive.php'), ], @@ -325,6 +353,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_with_relative_img_lcp.php'), ], @@ -343,6 +372,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_with_absolute_img_lcp.php'), ], @@ -361,6 +391,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_image.php'), ], @@ -379,6 +410,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_with_fetchpriority.html'), ], @@ -397,6 +429,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_with_markup_comment.html'), ], @@ -424,6 +457,7 @@ ], ], 'lrc' =>$lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_output_with_bg_image_lcp, ], @@ -451,6 +485,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_output_with_picture_img_lcp, ], @@ -478,6 +513,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_output_with_img_lcp, ], @@ -494,6 +530,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => $html_output, ], @@ -526,6 +563,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_picture.php'), ], @@ -558,6 +596,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_picture_2.php'), ], @@ -590,6 +629,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_picture_3.php'), ], @@ -620,6 +660,7 @@ ], ], 'lrc' => $lrc, + 'preload_fonts' => $preload_fonts, ], 'expected' => file_get_contents(__DIR__ . '/HTML/output_lcp_picture_4.php'), ], @@ -640,6 +681,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_output_with_beacon_and_lcp_opt, ], @@ -650,9 +694,49 @@ 'row' => null, ], 'lrc' => $lrc, + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_output_with_beacon_and_only_lrc_opt, ], + 'ShouldAddBeaconToPageWhenOnlyLrcMissing' => [ + 'config' => [ + 'html' => $html_input_with_domain_img_lcp, + 'atf' => [ + 'row' => [ + 'status' => 'completed', + 'url' => 'http://example.org', + 'lcp' => json_encode( (object) [ + 'type' => 'img', + 'src' => 'http://example.org/wp-content/uploads/sample_url_image.png', + ] ), + 'viewport' => json_encode ( [] ), + ], + ], + 'lrc' => [ + 'row' => null, + ], + 'preload_fonts' => [ + 'row' => $preload_fonts, + ], + ], + 'expected' => $html_output_with_beacon_and_lcp_opt, + ], + 'ShouldAddBeauconToPageWhenOnlyLcpIsMissing' => [ + 'config' => [ + 'html' => $html_input_with_only_lrc_opt, + 'atf' => [ + 'row' => null, + ], + 'lrc' => $lrc, + 'preload_fonts' => [ + 'row' => $preload_fonts, + ], + ], + 'expected' => $html_output_with_beacon_and_only_lrc_opt, + + ], 'shouldNotDuplicateBeaconOnAPage' => [ 'config' => [ 'html' => $html_with_double_body, @@ -662,6 +746,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_with_double_body_output, ], @@ -674,6 +761,9 @@ 'lrc' => [ 'row' => null, ], + 'preload_fonts' => [ + 'row' => null, + ], ], 'expected' => $html_input_without_closing_body_tag_output, ], diff --git a/tests/Integration/DBTrait.php b/tests/Integration/DBTrait.php index 20c80aed50..7448cc83bf 100644 --- a/tests/Integration/DBTrait.php +++ b/tests/Integration/DBTrait.php @@ -59,6 +59,12 @@ public static function addLrc( array $resource ) { return $lrc_query->add_item( $resource ); } + public static function addPreloadFonts(array $resource) { + $container = apply_filters( 'rocket_container', null ); + $preload_fonts_query = $container->get( 'preload_fonts_query' ); + return $preload_fonts_query->add_item( $resource ); + } + public static function installFresh() { $container = apply_filters( 'rocket_container', null ); @@ -114,6 +120,15 @@ public static function installLrcTable() { } } + public static function installPreloadFontsTable() { + $container = apply_filters( 'rocket_container', null ); + $preload_fonts_table = $container->get( 'preload_fonts_table' ); + + if ( ! $preload_fonts_table->exists() ) { + $preload_fonts_table->install(); + } + } + public static function uninstallAll() { $container = apply_filters( 'rocket_container', null ); $rucss_usedcss_table = $container->get( 'rucss_usedcss_table' ); @@ -170,6 +185,15 @@ public static function uninstallLrcTable() { } } + public static function uninstallPreloadFontsTable() { + $container = apply_filters( 'rocket_container', null ); + $preload_fonts_table = $container->get( 'preload_fonts_table' ); + + if ( $preload_fonts_table->exists() ) { + $preload_fonts_table->uninstall(); + } + } + public static function removeDBHooks() { $container = apply_filters( 'rocket_container', null ); 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 882b5bb8ff..23ce585afa 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 @@ -22,11 +22,13 @@ public static function set_up_before_class() { // Install in set_up_before_class because of exists(). self::installAtfTable(); self::installLrcTable(); + self::installPreloadFontsTable(); } public static function tear_down_after_class() { self::uninstallAtfTable(); self::uninstallLrcTable(); + self::uninstallPreloadFontsTable(); parent::tear_down_after_class(); } @@ -76,6 +78,10 @@ public function testShouldReturnAsExpected( $config, $expected ) { self::addLrc( $config['lrc']['row'] ); } + if ( ! empty( $config['preload_fonts']['row'] ) ) { + self::addPreloadFonts( $config['preload_fonts']['row'] ); + } + if ( isset( $config['filter_delay'] ) ) { add_filter( 'rocket_performance_hints_optimization_delay', [ $this, 'add_delay' ] ); } From 3b5315a6974094a1efa0b4e66dddeb2a358bd5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 14 Feb 2025 02:53:33 +0100 Subject: [PATCH 08/15] Fix stan ignore --- .../Database/Queries/QueriesInterface.php | 9 +++++ inc/Engine/Media/AboveTheFold/Factory.php | 2 +- phpstan-baseline.neon | 40 +++---------------- 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/inc/Engine/Common/PerformanceHints/Database/Queries/QueriesInterface.php b/inc/Engine/Common/PerformanceHints/Database/Queries/QueriesInterface.php index dd362f1b52..5371013848 100644 --- a/inc/Engine/Common/PerformanceHints/Database/Queries/QueriesInterface.php +++ b/inc/Engine/Common/PerformanceHints/Database/Queries/QueriesInterface.php @@ -14,4 +14,13 @@ interface QueriesInterface { * @return bool|int Returns a boolean or integer value. The exact return value depends on the implementation. */ public function delete_old_rows(); + + /** + * Sets the cleanup interval. + * + * This method sets the interval at which the cleanup process should run. + * + * @param int $interval The interval in seconds. + */ + public function set_cleanup_interval( int $interval ); } diff --git a/inc/Engine/Media/AboveTheFold/Factory.php b/inc/Engine/Media/AboveTheFold/Factory.php index 160ee54b8e..9f1b2d7173 100644 --- a/inc/Engine/Media/AboveTheFold/Factory.php +++ b/inc/Engine/Media/AboveTheFold/Factory.php @@ -110,7 +110,7 @@ public function queries(): QueriesInterface { return $this->queries; } - return $this->queries->set_cleanup_interval( $delete_interval ); // @phpstan-ignore-line + return $this->queries->set_cleanup_interval( $delete_interval ); } /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6e027d3e20..df0692e14c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -300,16 +300,6 @@ parameters: count: 1 path: inc/Engine/Media/AboveTheFold/Context/Context.php - - - message: "#^Hooks should not be used in ORM classes\\: WP_Rocket\\\\Engine\\\\Media\\\\AboveTheFold\\\\Database\\\\Queries\\\\AboveTheFold\\:\\:apply_filters$#" - count: 1 - path: inc/Engine/Media/AboveTheFold/Database/Queries/AboveTheFold.php - - - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 1 - path: inc/Engine/Media/AboveTheFold/Database/Queries/AboveTheFold.php - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -335,11 +325,6 @@ parameters: count: 3 path: inc/Engine/Media/Lazyload/CSS/Front/Extractor.php - - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 1 - path: inc/Engine/Media/Lazyload/CSS/ServiceProvider.php - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 3 @@ -415,16 +400,6 @@ parameters: count: 1 path: inc/Engine/Optimization/LazyRenderContent/Context/Context.php - - - message: "#^Hooks should not be used in ORM classes\\: WP_Rocket\\\\Engine\\\\Optimization\\\\LazyRenderContent\\\\Database\\\\Queries\\\\LazyRenderContent\\:\\:apply_filters$#" - count: 1 - path: inc/Engine/Optimization/LazyRenderContent/Database/Queries/LazyRenderContent.php - - - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 1 - path: inc/Engine/Optimization/LazyRenderContent/Database/Queries/LazyRenderContent.php - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 2 @@ -742,27 +717,27 @@ parameters: - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 18 + count: 21 path: tests/Integration/AjaxTestCase.php - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 18 + count: 21 path: tests/Integration/ApiTestCase.php - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 18 + count: 21 path: tests/Integration/FilesystemTestCase.php - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 18 + count: 21 path: tests/Integration/RESTVfsTestCase.php - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 18 + count: 21 path: tests/Integration/TestCase.php - @@ -2185,11 +2160,6 @@ parameters: count: 1 path: tests/Integration/inc/functions/rocketIsPluginActive.php - - - message: "#^Path in include_once\\(\\) \"vfs\\://public/wp\\-content/plugins/wp\\-rocket/inc/classes/dependencies/mobiledetect/mobiledetectlib/Mobile_Detect\\.php\" is not a file or it does not exist\\.$#" - count: 1 - path: tests/Integration/vfs:/public/wp-content/advanced-cache.php - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 5 From ddbdac6fd382e944e822a4ebac2caab445ae514e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 14 Feb 2025 04:07:34 +0100 Subject: [PATCH 09/15] Add test for check_data --- .../AJAX/Controller/checkData.php | 53 ++++++++++++ .../AJAX/Controller/checkData.php | 81 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 tests/Fixtures/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php create mode 100644 tests/Unit/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php diff --git a/tests/Fixtures/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php b/tests/Fixtures/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php new file mode 100644 index 0000000000..eca9f7b596 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php @@ -0,0 +1,53 @@ + [ + 'config' => [ + 'url' => 'http://example.org', + 'is_mobile' => false, + 'filter' => false, + 'row' => (object) [ + 'preload_fonts' => json_encode( [ + (object) [ + 'db47c7d69edcf4565baa182deb470091', + 'db47c7d69edcf4565baa182deb470092', + ], + ] ), + ], + ], + 'expected' => [ + 'result' => true, + 'message' => true + ], + ], + 'testShouldReturnSuccess' => [ + 'config' => [ + 'url' => 'http://example.org', + 'is_mobile' => false, + 'filter' => true, + 'row' => (object) [ + 'preload_fonts' => json_encode( [ + (object) [ + 'db47c7d69edcf4565baa182deb470091', + 'db47c7d69edcf4565baa182deb470092', + ], + ] ), + ], + ], + 'expected' => [ + 'result' => true, + 'message' => true + ], + ], + 'testShouldReturnError' => [ + 'config' => [ + 'url' => 'http://example.org', + 'is_mobile' => false, + 'row' => false, + 'filter' => true, + ], + 'expected' => [ + 'result' => false, + 'message' => false + ], + ], +]; diff --git a/tests/Unit/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php b/tests/Unit/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php new file mode 100644 index 0000000000..76548c11dd --- /dev/null +++ b/tests/Unit/inc/Engine/Media/PreloadFonts/AJAX/Controller/checkData.php @@ -0,0 +1,81 @@ +query = $this->createPartialMock( PreloadFonts::class, [ 'get_row' ] ); + $this->context = Mockery::mock( Context::class ); + $this->controller = new Controller( $this->query, $this->context ); + $this->temp_post = $_POST; + + $this->stubEscapeFunctions(); + } + + protected function tearDown(): void { + unset( $_POST ); + $_POST = $this->temp_post; + + parent::tearDown(); + } + + /** + * @dataProvider configTestData + */ + public function testShouldReturnExpected( $config, $expected ) { + $this->stubEscapeFunctions(); + $this->stubTranslationFunctions(); + + $_POST = [ + 'url' => addslashes( $config['url'] ), + 'is_mobile' => addslashes( $config['is_mobile'] ), + ]; + + $this->context->shouldReceive( 'is_allowed' ) + ->atMost() + ->once() + ->andReturn( $config['filter'] ); + + Functions\expect( 'check_ajax_referer' ) + ->once() + ->with( 'rocket_beacon', 'rocket_beacon_nonce' ) + ->andReturn( true ); + + Functions\when('esc_url_raw')->alias( + function( $url ){ + return $url; + } + ); + + Functions\when( 'wp_unslash' )->alias( + function ( $value ) { + return is_string( $value ) ? stripslashes( $value ) : $value; + } + ); + + $this->query->method( 'get_row' ) + ->with( $config['url'], $config['is_mobile'] ) + ->willReturn( $config['row'] ); + + $this->assertSame( [ 'preload_fonts' => $expected['message'] ], $this->controller->check_data() ); + } +} From 8b4ea58f688d9611bf5d677b0c956e8527e28965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 14 Feb 2025 04:10:55 +0100 Subject: [PATCH 10/15] Add test for has_preload_fonts --- .../Rows/PreloadFonts/hasPreloadFonts.php | 32 +++++++++++++++++++ .../Rows/PreloadFonts/hasPreloadFonts.php | 22 +++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/Fixtures/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php create mode 100644 tests/Unit/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php diff --git a/tests/Fixtures/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php b/tests/Fixtures/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php new file mode 100644 index 0000000000..3167cfca24 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php @@ -0,0 +1,32 @@ + [ + 'config' => [ + 'status' => 'in-progress', + 'fonts' => '["font1", "font2"]', + ], + 'expected' => false, + ], + 'shouldReturnFalseWhenFontsIsEmpty' => [ + 'config' => [ + 'status' => 'completed', + 'fonts' => '', + ], + 'expected' => false, + ], + 'shouldReturnFalseWhenFontsIsEmptyArray' => [ + 'config' => [ + 'status' => 'completed', + 'fonts' => '[]', + ], + 'expected' => false, + ], + 'shouldReturnTrueWhenStatusIsCompletedAndFontsIsNotEmpty' => [ + 'config' => [ + 'status' => 'completed', + 'fonts' => '["font1", "font2"]', + ], + 'expected' => true, + ], +]; diff --git a/tests/Unit/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php b/tests/Unit/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php new file mode 100644 index 0000000000..a0343a3233 --- /dev/null +++ b/tests/Unit/inc/Engine/Media/PreloadFonts/Database/Rows/PreloadFonts/hasPreloadFonts.php @@ -0,0 +1,22 @@ +assertSame($expected, $preloadFonts->has_preload_fonts()); + } +} From 9e9dff0891b7811c1ccd85b5206a75cee984b9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 14 Feb 2025 04:16:31 +0100 Subject: [PATCH 11/15] Add default uninstall to preload fond table --- tests/Integration/bootstrap.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php index a105c30749..6794844f51 100644 --- a/tests/Integration/bootstrap.php +++ b/tests/Integration/bootstrap.php @@ -286,6 +286,9 @@ function() { $lrc_table = $container->get( 'lrc_table' ); $lrc_table->uninstall(); + + $preload_fonts_table = $container->get( 'preload_fonts_table' ); + $preload_fonts_table->uninstall(); } ); From 86be3dffc9f4f38cd43d6ea9ac18d41a225e5000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 14 Feb 2025 07:41:02 +0100 Subject: [PATCH 12/15] Add filter to enable feature + add default disable to integration tests --- inc/Engine/Media/PreloadFonts/Context/Context.php | 2 +- tests/Integration/bootstrap.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/inc/Engine/Media/PreloadFonts/Context/Context.php b/inc/Engine/Media/PreloadFonts/Context/Context.php index c09a26e004..ed3618f38a 100644 --- a/inc/Engine/Media/PreloadFonts/Context/Context.php +++ b/inc/Engine/Media/PreloadFonts/Context/Context.php @@ -34,6 +34,6 @@ public function is_allowed( array $data = [] ): bool { return false; } - return (bool) $this->options->get( 'rocket_preload_fonts', 1 ); + return wpm_apply_filters_typed( 'boolean', 'rocket_preload_fonts_optimization', (bool) $this->options->get( 'rocket_preload_fonts', 1 ) ); } } diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php index 6794844f51..5f499c3baf 100644 --- a/tests/Integration/bootstrap.php +++ b/tests/Integration/bootstrap.php @@ -17,9 +17,10 @@ 'muplugins_loaded', function () { - // Disable ATF & LRC optimizations to prevent DB requests (unrelated to other tests). + // Disable ATF, LRC & Preload fonts optimizations to prevent DB requests (unrelated to other tests). add_filter( 'rocket_above_the_fold_optimization', '__return_false' ); add_filter( 'rocket_lrc_optimization', '__return_false' ); + add_filter( 'rocket_preload_fonts_optimization', '__return_false' ); if ( BootstrapManager::isGroup( 'TranslatePress' ) ) { require WP_ROCKET_TESTS_FIXTURES_DIR . '/classes/TRP_Translate_Press.php'; @@ -266,6 +267,7 @@ function () { if ( BootstrapManager::isGroup( 'PerformanceHints' ) ) { add_filter( 'rocket_above_the_fold_optimization', '__return_true' ); add_filter( 'rocket_lrc_optimization', '__return_true' ); + add_filter( 'rocket_preload_fonts_optimization', '__return_true' ); } // Load the plugin. From f45d1c80306700c0f34c7ca62314f32b46611029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 14 Feb 2025 07:50:58 +0100 Subject: [PATCH 13/15] fix tests --- tests/Integration/inc/Engine/Support/Data/getSupportData.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Integration/inc/Engine/Support/Data/getSupportData.php b/tests/Integration/inc/Engine/Support/Data/getSupportData.php index c97d505485..b831f5fd40 100644 --- a/tests/Integration/inc/Engine/Support/Data/getSupportData.php +++ b/tests/Integration/inc/Engine/Support/Data/getSupportData.php @@ -21,6 +21,7 @@ public function set_up() { add_filter( 'rocket_above_the_fold_optimization', '__return_true' ); add_filter( 'rocket_lrc_optimization', '__return_true' ); + add_filter( 'rocket_preload_fonts_optimization', '__return_true' ); $this->wp_version = $wp_version; } @@ -30,6 +31,8 @@ public function tear_down() { remove_filter( 'rocket_above_the_fold_optimization', '__return_true' ); remove_filter( 'rocket_lrc_optimization', '__return_true' ); + remove_filter( 'rocket_preload_fonts_optimization', '__return_true' ); + $wp_version = $this->wp_version; From d2d28a4f559472518c8401d247ddf0dd79a668cc Mon Sep 17 00:00:00 2001 From: Khadreal Date: Fri, 14 Feb 2025 13:08:35 +0100 Subject: [PATCH 14/15] Update test db hooks --- tests/Integration/DBTrait.php | 9 +++++++++ uninstall.php | 1 + 2 files changed, 10 insertions(+) diff --git a/tests/Integration/DBTrait.php b/tests/Integration/DBTrait.php index 7448cc83bf..424f198187 100644 --- a/tests/Integration/DBTrait.php +++ b/tests/Integration/DBTrait.php @@ -82,6 +82,9 @@ public static function installFresh() { $lrc_table = $container->get( 'lrc_table' ); $lrc_table->install(); + + $preload_fonts_table = $container->get( 'preload_fonts_table' ); + $preload_fonts_table->install(); } public static function installUsedCssTable() { @@ -151,6 +154,11 @@ public static function uninstallAll() { if ( $lrc_table->exists() ) { $lrc_table->uninstall(); } + + $preload_fonts_table = $container->get( 'preload_fonts_table' ); + if ( $preload_fonts_table->exists() ) { + $preload_fonts_table->uninstall(); + } } public static function uninstallUsedCssTable() { @@ -202,6 +210,7 @@ public static function removeDBHooks() { $container->get( 'preload_caches_table' ), $container->get( 'atf_table' ), $container->get( 'lrc_table' ), + $container->get( 'preload_fonts_table' ), ]; foreach ( $tables as $table ) { diff --git a/uninstall.php b/uninstall.php index 5fd62b9b9e..707068a77b 100755 --- a/uninstall.php +++ b/uninstall.php @@ -30,6 +30,7 @@ require_once __DIR__ . '/inc/Engine/Common/PerformanceHints/Database/Table/AbstractTable.php'; require_once __DIR__ . '/inc/Engine/Media/AboveTheFold/Database/Tables/AboveTheFold.php'; require_once __DIR__ . '/inc/Engine/Optimization/LazyRenderContent/Database/Table/LazyRenderContent.php'; +require_once __DIR__ . '/inc/Engine/Media/PreloadFonts/Database/Table/PreloadFonts.php'; $rocket_rucss_usedcss_table = new WP_Rocket\Engine\Optimization\RUCSS\Database\Tables\UsedCSS(); $rocket_cache_table = new WP_Rocket\Engine\Preload\Database\Tables\Cache(); From cb7b9f2c5683ae77cf6bb2b3c4edf98c71ca4934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Tue, 18 Feb 2025 15:41:45 +0100 Subject: [PATCH 15/15] Add CronTrait to factory --- inc/Engine/Media/PreloadFonts/Factory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/Engine/Media/PreloadFonts/Factory.php b/inc/Engine/Media/PreloadFonts/Factory.php index bdb951a185..41ece3069a 100644 --- a/inc/Engine/Media/PreloadFonts/Factory.php +++ b/inc/Engine/Media/PreloadFonts/Factory.php @@ -4,6 +4,7 @@ namespace WP_Rocket\Engine\Media\PreloadFonts; +use WP_Rocket\Engine\Common\PerformanceHints\Cron\CronTrait; use WP_Rocket\Engine\Common\PerformanceHints\FactoryInterface; use WP_Rocket\Engine\Common\PerformanceHints\AJAX\ControllerInterface as AjaxControllerInterface; use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface as FrontendControllerInterface; @@ -12,6 +13,7 @@ use WP_Rocket\Engine\Common\Context\ContextInterface; class Factory implements FactoryInterface { + use CronTrait; /** * Ajax Controller instance. @@ -98,7 +100,8 @@ public function table(): TableInterface { * @return QueriesInterface */ public function queries(): QueriesInterface { - return $this->queries; + // Defines the interval for deletion and returns Queries object. + return $this->deletion_interval( 'rocket_pf_cleanup_interval' ); } /**