Skip to content

Commit

Permalink
clean host fonts CSS when enabling/disabling CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona committed Dec 6, 2024
1 parent 7f2f3ae commit 1ca09d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
46 changes: 41 additions & 5 deletions inc/Engine/Media/Fonts/Clean/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.

Check notice on line 91 in inc/Engine/Media/Fonts/Clean/Clean.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/Fonts/Clean/Clean.php#L91

Expected 2 spaces after parameter type; 1 found
* @param mixed $value New option value.

Check notice on line 92 in inc/Engine/Media/Fonts/Clean/Clean.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/Fonts/Clean/Clean.php#L92

Expected 2 spaces after parameter type; 1 found
*
* @return bool
*/
private function did_setting_change( $setting, array $old_value, array $value ) {

Check failure on line 96 in inc/Engine/Media/Fonts/Clean/Clean.php

View workflow job for this annotation

GitHub Actions / WPRocket lint with PHP Stan. PHP 8.2 on ubuntu-latest.

PHPDoc tag @param for parameter $old_value with type mixed is not subtype of native type array.

Check failure on line 96 in inc/Engine/Media/Fonts/Clean/Clean.php

View workflow job for this annotation

GitHub Actions / WPRocket lint with PHP Stan. PHP 8.2 on ubuntu-latest.

PHPDoc tag @param for parameter $value with type mixed is not subtype of native type array.

Check notice on line 96 in inc/Engine/Media/Fonts/Clean/Clean.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/Fonts/Clean/Clean.php#L96

Expected type hint "mixed"; found "array" for $old_value
return (
array_key_exists( $setting, $old_value )
&&
array_key_exists( $setting, $value )
&&
// phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
$old_value[ $setting ] != $value[ $setting ]
);
}
}
13 changes: 13 additions & 0 deletions inc/Engine/Media/Fonts/Clean/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ],

Check failure on line 33 in inc/Engine/Media/Fonts/Clean/Subscriber.php

View workflow job for this annotation

GitHub Actions / WPRocket lint with PHP Stan. PHP 8.2 on ubuntu-latest.

Array has 2 duplicate keys with value 'update_option_wp_rocket_settings' ('update_option_wp_rocket_settings', 'update_option_wp_rocket_settings').
'update_option_wp_rocket_settings' => [ 'clean_on_cdn_change', 11, 2 ],
];
}

Expand All @@ -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 );
}
}

0 comments on commit 1ca09d9

Please sign in to comment.