From 3a4ece1d6445cd805d267fc397dc774b338f515a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Thu, 14 Nov 2024 16:02:46 -0500 Subject: [PATCH 01/18] add Clean class --- inc/Engine/Media/Fonts/Clean/Clean.php | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 inc/Engine/Media/Fonts/Clean/Clean.php diff --git a/inc/Engine/Media/Fonts/Clean/Clean.php b/inc/Engine/Media/Fonts/Clean/Clean.php new file mode 100644 index 0000000000..fd753d1d5d --- /dev/null +++ b/inc/Engine/Media/Fonts/Clean/Clean.php @@ -0,0 +1,61 @@ +filesystem = $filesystem; + $this->base_path = rocket_get_constant( 'WP_ROCKET_CACHE_ROOT_PATH', '' ) . 'fonts/' . get_current_blog_id() . '/'; + } + + /** + * Clean CSS & fonts files stored locally + * + * @return void + */ + public function clean_css_fonts() { + $this->filesystem->delete_all_files_from_directory( $this->base_path ); + } + + /** + * Clean CSS & fonts files stored locally on option change + * + * @param mixed $old_value Old option value. + * @param mixed $value New option value. + * + * @return void + */ + public function clean_on_option_change( $old_value, $value ) { + if ( ! isset( $old_value['host_fonts_locally'], $value['host_fonts_locally'] ) ) { + return; + } + + if ( $old_value['host_fonts_locally'] === $value['host_fonts_locally'] ) { + return; + } + + $this->clean_css_fonts(); + + do_action( 'rocket_fonts_locally_hosted_changed' ); + } +} From 5301e98f57de4acae58bfd591bce94fa3d7edb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Thu, 14 Nov 2024 16:02:51 -0500 Subject: [PATCH 02/18] add Subscriber --- inc/Engine/Media/Fonts/Clean/Subscriber.php | 57 +++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 inc/Engine/Media/Fonts/Clean/Subscriber.php diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php new file mode 100644 index 0000000000..dc3c15ff8b --- /dev/null +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -0,0 +1,57 @@ +clean = $clean; + } + + /** + * Returns an array of events that this subscriber wants to listen to. + * + * @return array + */ + public static function get_subscribed_events(): array { + return [ + 'rocket_clean_domain' => 'clean_css_fonts', + 'update_option_wp_rocket_settings' => ['clean_on_option_change', 10, 2], + ]; + } + + /** + * Clean CSS & fonts files stored locally + * + * @return void + */ + public function clean_css_fonts() { + $this->clean->clean_css_fonts(); + } + + /** + * Clean CSS & fonts files stored locally on option change + * + * @param mixed $old_value Old option value. + * @param mixed $value New option value. + * + * @return void + */ + public function clean_on_option_change( $old_value, $value ) { + $this->clean->clean_on_option_change( $old_value, $value ); + } +} From 56859defb7bb2f46ffb6e4a39238ef0a0ef3f3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Thu, 14 Nov 2024 16:03:12 -0500 Subject: [PATCH 03/18] Add new callback --- inc/Engine/Optimization/RUCSS/Admin/Subscriber.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php b/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php index 08814e970a..3b023bbac8 100644 --- a/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php +++ b/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php @@ -70,6 +70,7 @@ public static function get_subscribed_events(): array { 'switch_theme' => 'truncate_used_css', 'permalink_structure_changed' => 'truncate_used_css', 'rocket_domain_options_changed' => 'truncate_used_css', + 'rocket_host_fonts_locally_changed' => 'truncate_used_css', 'wp_trash_post' => 'delete_used_css_on_update_or_delete', 'delete_post' => 'delete_used_css_on_update_or_delete', 'clean_post_cache' => 'delete_used_css_on_update_or_delete', From 76b24ddbeed4f1ad2ed98b5d8e4e99d8050d9e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Thu, 14 Nov 2024 16:10:19 -0500 Subject: [PATCH 04/18] fix code styling --- inc/Engine/Media/Fonts/Clean/Subscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index dc3c15ff8b..ab71569b06 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -30,7 +30,7 @@ public function __construct( Clean $clean ) { public static function get_subscribed_events(): array { return [ 'rocket_clean_domain' => 'clean_css_fonts', - 'update_option_wp_rocket_settings' => ['clean_on_option_change', 10, 2], + 'update_option_wp_rocket_settings' => [ 'clean_on_option_change', 10, 2 ], ]; } From 6121ff49e2e8a38de6e1b150cc0c34c0d154c822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 4 Dec 2024 11:25:08 -0500 Subject: [PATCH 05/18] update filter name --- inc/Engine/Media/Fonts/Clean/Clean.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Clean/Clean.php b/inc/Engine/Media/Fonts/Clean/Clean.php index fd753d1d5d..f20c0509d4 100644 --- a/inc/Engine/Media/Fonts/Clean/Clean.php +++ b/inc/Engine/Media/Fonts/Clean/Clean.php @@ -3,6 +3,8 @@ namespace WP_Rocket\Engine\Media\Fonts\Clean; +use WP_Rocket\Engine\Media\Fonts\Filesystem; + class Clean { /** * Filesystem instance @@ -56,6 +58,11 @@ public function clean_on_option_change( $old_value, $value ) { $this->clean_css_fonts(); - do_action( 'rocket_fonts_locally_hosted_changed' ); + /** + * Fires when the option to host fonts locally is changed + * + * @since 3.18 + */ + do_action( 'rocket_host_fonts_locally_changed' ); } } From 895bfe4c25a9edb45a5baac89c28440011330064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 4 Dec 2024 11:43:53 -0500 Subject: [PATCH 06/18] instantiate clean classes --- inc/Engine/Media/Fonts/ServiceProvider.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/inc/Engine/Media/Fonts/ServiceProvider.php b/inc/Engine/Media/Fonts/ServiceProvider.php index 7448a84198..92eb9c681c 100644 --- a/inc/Engine/Media/Fonts/ServiceProvider.php +++ b/inc/Engine/Media/Fonts/ServiceProvider.php @@ -7,6 +7,8 @@ use WP_Rocket\Engine\Media\Fonts\Filesystem; use WP_Rocket\Engine\Media\Fonts\Admin\Settings; use WP_Rocket\Engine\Media\Fonts\Admin\Subscriber as AdminSubscriber; +use WP_Rocket\Engine\Media\Fonts\Clean\Clean; +use WP_Rocket\Engine\Media\Fonts\Clean\Subscriber as CleanSubscriber; use WP_Rocket\Engine\Media\Fonts\Context\Context; use WP_Rocket\Engine\Media\Fonts\Frontend\Controller as FrontendController; use WP_Rocket\Engine\Media\Fonts\Frontend\Subscriber as FrontendSubscriber; @@ -31,6 +33,8 @@ class ServiceProvider extends AbstractServiceProvider { 'media_fonts_context', 'media_fonts_frontend_controller', 'media_fonts_frontend_subscriber', + 'media_fonts_clean', + 'media_fonts_clean_subscriber', ]; /** @@ -58,19 +62,23 @@ public function register(): void { $this->getContainer()->addShared( 'media_fonts_admin_subscriber', AdminSubscriber::class ) ->addArgument( 'media_fonts_settings' ); + $this->getContainer()->add( 'media_fonts_clean', Clean::class ) + ->addArgument( 'media_fonts_filesystem' ); + + $this->getContainer()->addShared( 'media_fonts_clean_subscriber', CleanSubscriber::class ) + ->addArgument( 'media_fonts_clean' ); + $this->getContainer()->add( 'media_fonts_context', Context::class ) - ->addArgument( $this->getContainer()->get( 'options' ) ); + ->addArgument( 'options' ); $this->getContainer()->add( 'media_fonts_frontend_controller', FrontendController::class ) ->addArguments( [ - $this->getContainer()->get( 'media_fonts_context' ), - $this->getContainer()->get( 'media_fonts_filesystem' ), + 'media_fonts_context', + 'media_fonts_filesystem', ] ); - $this->getContainer()->add( 'media_fonts_frontend_subscriber', FrontendSubscriber::class ) - ->addArgument( - $this->getContainer()->get( 'media_fonts_frontend_controller' ) - ); + $this->getContainer()->addShared( 'media_fonts_frontend_subscriber', FrontendSubscriber::class ) + ->addArgument( 'media_fonts_frontend_controller' ); } } From 088af9704fa6c601cb23b44b7b646937bbd8b7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 4 Dec 2024 11:44:13 -0500 Subject: [PATCH 07/18] update clean path --- inc/Engine/Media/Fonts/Clean/Clean.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Clean/Clean.php b/inc/Engine/Media/Fonts/Clean/Clean.php index f20c0509d4..02cf9cd4ef 100644 --- a/inc/Engine/Media/Fonts/Clean/Clean.php +++ b/inc/Engine/Media/Fonts/Clean/Clean.php @@ -36,7 +36,9 @@ public function __construct( $filesystem ) { * @return void */ public function clean_css_fonts() { - $this->filesystem->delete_all_files_from_directory( $this->base_path ); + $path = $this->base_path . 'google-fonts/'; + + $this->filesystem->delete_all_files_from_directory( $path ); } /** From e28b971ad445946db2592afa871877222cb9f3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 4 Dec 2024 11:44:18 -0500 Subject: [PATCH 08/18] update hook name --- inc/Engine/Media/Fonts/Clean/Subscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index ab71569b06..128c6ed586 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -29,7 +29,7 @@ public function __construct( Clean $clean ) { */ public static function get_subscribed_events(): array { return [ - 'rocket_clean_domain' => 'clean_css_fonts', + 'rocket_after_clean_domain' => 'clean_css_fonts', 'update_option_wp_rocket_settings' => [ 'clean_on_option_change', 10, 2 ], ]; } From 8c6ddcce07c21eb1fccdcd2bef9a118d2ea6c0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 4 Dec 2024 11:44:24 -0500 Subject: [PATCH 09/18] load clean subscriber --- inc/Plugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/Plugin.php b/inc/Plugin.php index eae9d928e4..e8ba4c5f36 100644 --- a/inc/Plugin.php +++ b/inc/Plugin.php @@ -406,6 +406,7 @@ private function init_common_subscribers() { 'taxonomy_subscriber', 'media_fonts_frontend_subscriber', 'media_fonts_admin_subscriber', + 'media_fonts_clean_subscriber', ]; $host_type = HostResolver::get_host_service(); From 71051de4d7ae3ad29316c972f96ffa29bc3631cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 4 Dec 2024 13:31:02 -0500 Subject: [PATCH 10/18] add tests for clean_on_option_change() --- .../Fonts/Clean/Clean/cleanOnOptionChange.php | 27 ++++++++++++ .../Fonts/Clean/Clean/cleanOnOptionChange.php | 41 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/Fixtures/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php create mode 100644 tests/Unit/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php diff --git a/tests/Fixtures/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php b/tests/Fixtures/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php new file mode 100644 index 0000000000..8a4e8ee886 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php @@ -0,0 +1,27 @@ + [ + 'old_value' => [], + 'value' => [], + 'expected' => false, + ], + 'testShouldDoNothingWhenOldValueAndNewValueAreTheSame' => [ + 'old_value' => [ + 'host_fonts_locally' => 0, + ], + 'value' => [ + 'host_fonts_locally' => 0, + ], + 'expected' => false, + ], + 'testShouldDeleteAllFilesWhenOldValueAndNewValueAreDifferent' => [ + 'old_value' => [ + 'host_fonts_locally' => 0, + ], + 'value' => [ + 'host_fonts_locally' => 1, + ], + 'expected' => true, + ], +]; diff --git a/tests/Unit/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php b/tests/Unit/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php new file mode 100644 index 0000000000..b5b1d84f11 --- /dev/null +++ b/tests/Unit/inc/Engine/Media/Fonts/Clean/Clean/cleanOnOptionChange.php @@ -0,0 +1,41 @@ +justReturn( 1 ); + + $this->filesystem = Mockery::mock( Filesystem::class ); + $this->clean = new Clean( $this->filesystem ); + } + + /** + * @dataProvider configTestData + */ + public function testShouldDoExpected( $old_value, $value, $expected ) { + if ( $expected ) { + $this->filesystem->shouldReceive( 'delete_all_files_from_directory' )->once(); + } else { + $this->filesystem->shouldNotReceive( 'delete_all_files_from_directory' ); + } + + $this->clean->clean_on_option_change( $old_value, $value ); + } +} From 7f2f3ae99129b5eb37ad527019f842de5334e8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 15:59:13 -0500 Subject: [PATCH 11/18] clean minify files when enabling/disabling host fonts locally --- inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php b/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php index d4e29e6485..3fe7255c57 100755 --- a/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php +++ b/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php @@ -78,6 +78,7 @@ protected function maybe_minify_regenerate( array $new, array $old ) { // phpcs: 'minify_css', 'exclude_css', 'cdn', + 'host_fonts_locally', ]; foreach ( $settings_to_check as $setting ) { From 1ca09d9d0caf84b37ce7d7b7ee4aa8cba4aeee0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 15:59:29 -0500 Subject: [PATCH 12/18] clean host fonts CSS when enabling/disabling CDN --- inc/Engine/Media/Fonts/Clean/Clean.php | 46 ++++++++++++++++++--- inc/Engine/Media/Fonts/Clean/Subscriber.php | 13 ++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/inc/Engine/Media/Fonts/Clean/Clean.php b/inc/Engine/Media/Fonts/Clean/Clean.php index 02cf9cd4ef..42019a4275 100644 --- a/inc/Engine/Media/Fonts/Clean/Clean.php +++ b/inc/Engine/Media/Fonts/Clean/Clean.php @@ -50,11 +50,7 @@ public function clean_css_fonts() { * @return void */ public function clean_on_option_change( $old_value, $value ) { - if ( ! isset( $old_value['host_fonts_locally'], $value['host_fonts_locally'] ) ) { - return; - } - - if ( $old_value['host_fonts_locally'] === $value['host_fonts_locally'] ) { + if ( ! $this->did_setting_change( 'host_fonts_locally', $old_value, $value ) ) { return; } @@ -67,4 +63,44 @@ public function clean_on_option_change( $old_value, $value ) { */ do_action( 'rocket_host_fonts_locally_changed' ); } + + /** + * Clean CSS & fonts files stored locally on CDN change + * + * @param mixed $old_value Old option value. + * @param mixed $value New option value. + * + * @return void + */ + public function clean_on_cdn_change( $old_value, $value ) { + if ( ! $this->did_setting_change( 'cdn', $old_value, $value ) ) { + return; + } + + if ( ! $this->did_setting_change( 'cdn_cnames', $old_value, $value ) ) { + return; + } + + $this->clean_css_fonts(); + } + + /** + * Checks if the given setting's value changed. + * + * @param string $setting The settings's value to check in the old and new values. + * @param mixed $old_value Old option value. + * @param mixed $value New option value. + * + * @return bool + */ + private function did_setting_change( $setting, array $old_value, array $value ) { + return ( + array_key_exists( $setting, $old_value ) + && + array_key_exists( $setting, $value ) + && + // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual + $old_value[ $setting ] != $value[ $setting ] + ); + } } diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index 128c6ed586..ca415b7606 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -31,6 +31,7 @@ public static function get_subscribed_events(): array { return [ 'rocket_after_clean_domain' => 'clean_css_fonts', 'update_option_wp_rocket_settings' => [ 'clean_on_option_change', 10, 2 ], + 'update_option_wp_rocket_settings' => [ 'clean_on_cdn_change', 11, 2 ], ]; } @@ -54,4 +55,16 @@ public function clean_css_fonts() { public function clean_on_option_change( $old_value, $value ) { $this->clean->clean_on_option_change( $old_value, $value ); } + + /** + * Clean CSS & fonts files stored locally on CDN change + * + * @param mixed $old_value Old option value. + * @param mixed $value New option value. + * + * @return void + */ + public function clean_on_cdn_change( $old_value, $value ) { + $this->clean->clean_on_cdn_change( $old_value, $value ); + } } From cee21a44628cca04a34bd9ddb00f9f69d87c3a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 16:06:34 -0500 Subject: [PATCH 13/18] fix styling --- inc/Engine/Media/Fonts/Clean/Clean.php | 6 +++--- inc/Engine/Media/Fonts/Clean/Subscriber.php | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/inc/Engine/Media/Fonts/Clean/Clean.php b/inc/Engine/Media/Fonts/Clean/Clean.php index 42019a4275..b1c66bcc0e 100644 --- a/inc/Engine/Media/Fonts/Clean/Clean.php +++ b/inc/Engine/Media/Fonts/Clean/Clean.php @@ -88,12 +88,12 @@ public function clean_on_cdn_change( $old_value, $value ) { * Checks if the given setting's value changed. * * @param string $setting The settings's value to check in the old and new values. - * @param mixed $old_value Old option value. - * @param mixed $value New option value. + * @param mixed $old_value Old option value. + * @param mixed $value New option value. * * @return bool */ - private function did_setting_change( $setting, array $old_value, array $value ) { + private function did_setting_change( $setting, $old_value, $value ) { return ( array_key_exists( $setting, $old_value ) && diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index ca415b7606..548160deaf 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -30,8 +30,10 @@ public function __construct( Clean $clean ) { public static function get_subscribed_events(): array { return [ 'rocket_after_clean_domain' => 'clean_css_fonts', - 'update_option_wp_rocket_settings' => [ 'clean_on_option_change', 10, 2 ], - 'update_option_wp_rocket_settings' => [ 'clean_on_cdn_change', 11, 2 ], + 'update_option_wp_rocket_settings' => [ + [ 'clean_on_option_change', 10, 2 ], + [ 'clean_on_cdn_change', 11, 2 ] + ], ]; } From c17b04d2ace0a0f6c0c933ca99be7ee07df9f772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 16:11:08 -0500 Subject: [PATCH 14/18] add missing comma --- inc/Engine/Media/Fonts/Clean/Subscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index 548160deaf..78ec2e7bcb 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -32,7 +32,7 @@ public static function get_subscribed_events(): array { 'rocket_after_clean_domain' => 'clean_css_fonts', 'update_option_wp_rocket_settings' => [ [ 'clean_on_option_change', 10, 2 ], - [ 'clean_on_cdn_change', 11, 2 ] + [ 'clean_on_cdn_change', 11, 2 ], ], ]; } From aa97cfeba4f61827dd6f70931e26283a5be80b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 10 Dec 2024 11:22:00 -0500 Subject: [PATCH 15/18] add deletion of fonts & background css folders on uninstall --- inc/Engine/WPRocketUninstall.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/Engine/WPRocketUninstall.php b/inc/Engine/WPRocketUninstall.php index ae30a0ad06..c29345dd31 100644 --- a/inc/Engine/WPRocketUninstall.php +++ b/inc/Engine/WPRocketUninstall.php @@ -113,6 +113,8 @@ class WPRocketUninstall { 'busting', 'critical-css', 'used-css', + 'fonts', + 'background-css', ]; /** From 3cc17c213e25d79197d00fcd3c5764f0d11eec9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 10 Dec 2024 13:51:45 -0500 Subject: [PATCH 16/18] separate methods to clean CSS & fonts --- inc/Engine/Media/Fonts/Clean/Clean.php | 21 ++++++++++++++++----- inc/Engine/Media/Fonts/Clean/Subscriber.php | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/inc/Engine/Media/Fonts/Clean/Clean.php b/inc/Engine/Media/Fonts/Clean/Clean.php index b1c66bcc0e..6b55d8522a 100644 --- a/inc/Engine/Media/Fonts/Clean/Clean.php +++ b/inc/Engine/Media/Fonts/Clean/Clean.php @@ -31,12 +31,23 @@ public function __construct( $filesystem ) { } /** - * Clean CSS & fonts files stored locally + * Clean fonts CSS files stored locally * * @return void */ - public function clean_css_fonts() { - $path = $this->base_path . 'google-fonts/'; + public function clean_fonts_css() { + $path = $this->base_path . 'google-fonts/css/'; + + $this->filesystem->delete_all_files_from_directory( $path ); + } + + /** + * Clean fonts files stored locally + * + * @return void + */ + public function clean_fonts() { + $path = $this->base_path . 'google-fonts/fonts/'; $this->filesystem->delete_all_files_from_directory( $path ); } @@ -54,7 +65,7 @@ public function clean_on_option_change( $old_value, $value ) { return; } - $this->clean_css_fonts(); + $this->clean_fonts_css(); /** * Fires when the option to host fonts locally is changed @@ -81,7 +92,7 @@ public function clean_on_cdn_change( $old_value, $value ) { return; } - $this->clean_css_fonts(); + $this->clean_fonts_css(); } /** diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index 78ec2e7bcb..151d30970d 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -29,7 +29,9 @@ public function __construct( Clean $clean ) { */ public static function get_subscribed_events(): array { return [ - 'rocket_after_clean_domain' => 'clean_css_fonts', + 'rocket_after_clean_domain' => 'clean_fonts_css', + 'switch_theme' => 'clean_fonts', + 'rocket_domain_options_changed' => 'clean_fonts', 'update_option_wp_rocket_settings' => [ [ 'clean_on_option_change', 10, 2 ], [ 'clean_on_cdn_change', 11, 2 ], @@ -38,12 +40,21 @@ public static function get_subscribed_events(): array { } /** - * Clean CSS & fonts files stored locally + * Clean fonts CSS files stored locally * * @return void */ - public function clean_css_fonts() { - $this->clean->clean_css_fonts(); + public function clean_fonts_css() { + $this->clean->clean_fonts_css(); + } + + /** + * Clean fonts files stored locally + * + * @return void + */ + public function clean_fonts() { + $this->clean->clean_fonts(); } /** From 6c276138c06f0ca5a62d2f2f8162bc6068a2f8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 10 Dec 2024 15:19:23 -0500 Subject: [PATCH 17/18] use different callback --- inc/Engine/Optimization/RUCSS/Admin/Subscriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php b/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php index 3b023bbac8..2962c44b87 100644 --- a/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php +++ b/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php @@ -70,7 +70,7 @@ public static function get_subscribed_events(): array { 'switch_theme' => 'truncate_used_css', 'permalink_structure_changed' => 'truncate_used_css', 'rocket_domain_options_changed' => 'truncate_used_css', - 'rocket_host_fonts_locally_changed' => 'truncate_used_css', + 'rocket_host_fonts_locally_changed' => 'delete_used_css_rows', 'wp_trash_post' => 'delete_used_css_on_update_or_delete', 'delete_post' => 'delete_used_css_on_update_or_delete', 'clean_post_cache' => 'delete_used_css_on_update_or_delete', @@ -207,7 +207,7 @@ public function truncate_used_css() { * * @return void */ - private function delete_used_css_rows() { + public function delete_used_css_rows() { $this->used_css->delete_all_used_css(); if ( 0 < $this->used_css->get_not_completed_count() ) { From efe6c4ebabb600ea22c8cdbe4090f091a5ba50ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Thu, 12 Dec 2024 08:41:52 -0500 Subject: [PATCH 18/18] also clean CSS --- inc/Engine/Media/Fonts/Clean/Subscriber.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Clean/Subscriber.php b/inc/Engine/Media/Fonts/Clean/Subscriber.php index 151d30970d..ff963e48e3 100644 --- a/inc/Engine/Media/Fonts/Clean/Subscriber.php +++ b/inc/Engine/Media/Fonts/Clean/Subscriber.php @@ -31,7 +31,10 @@ public static function get_subscribed_events(): array { return [ 'rocket_after_clean_domain' => 'clean_fonts_css', 'switch_theme' => 'clean_fonts', - 'rocket_domain_options_changed' => 'clean_fonts', + 'rocket_domain_options_changed' => [ + [ 'clean_fonts_css' ], + [ 'clean_fonts' ], + ], 'update_option_wp_rocket_settings' => [ [ 'clean_on_option_change', 10, 2 ], [ 'clean_on_cdn_change', 11, 2 ],