From 52b954a5af1b069a14b45e1fbaa1fddb00405134 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jun 2024 03:13:41 +0530 Subject: [PATCH 1/4] Fix PHPStan errors caused by called no-op parent methods --- includes/sanitizers/class-amp-comments-sanitizer.php | 2 -- includes/sanitizers/class-amp-script-sanitizer.php | 2 -- includes/sanitizers/class-amp-style-sanitizer.php | 2 -- 3 files changed, 6 deletions(-) diff --git a/includes/sanitizers/class-amp-comments-sanitizer.php b/includes/sanitizers/class-amp-comments-sanitizer.php index a6ea378b86a..649220c4c2c 100644 --- a/includes/sanitizers/class-amp-comments-sanitizer.php +++ b/includes/sanitizers/class-amp-comments-sanitizer.php @@ -42,8 +42,6 @@ class AMP_Comments_Sanitizer extends AMP_Base_Sanitizer { * @param AMP_Base_Sanitizer[] $sanitizers Sanitizers. */ public function init( $sanitizers ) { - parent::init( $sanitizers ); - if ( array_key_exists( AMP_Style_Sanitizer::class, $sanitizers ) && diff --git a/includes/sanitizers/class-amp-script-sanitizer.php b/includes/sanitizers/class-amp-script-sanitizer.php index 24fe1f39c83..4a8a615bdd5 100644 --- a/includes/sanitizers/class-amp-script-sanitizer.php +++ b/includes/sanitizers/class-amp-script-sanitizer.php @@ -99,8 +99,6 @@ class AMP_Script_Sanitizer extends AMP_Base_Sanitizer { * @param AMP_Base_Sanitizer[] $sanitizers Sanitizers. */ public function init( $sanitizers ) { - parent::init( $sanitizers ); - $this->sanitizers = $sanitizers; } diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index d9c5e0a3d8c..467ddd10a8a 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -891,8 +891,6 @@ private function is_class_allowed_in_amp_date_picker( $class ) { * @param AMP_Base_Sanitizer[] $sanitizers Sanitizers. */ public function init( $sanitizers ) { - parent::init( $sanitizers ); - $this->sanitizers = $sanitizers; } From 05b93e2ef62085858e63bdaeebdd435ee18cd770 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jun 2024 15:39:55 +0530 Subject: [PATCH 2/4] Add support for theme.json v3 in reader theme --- src/ReaderThemeSupportFeatures.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ReaderThemeSupportFeatures.php b/src/ReaderThemeSupportFeatures.php index 3266978d479..4c9943a1f48 100644 --- a/src/ReaderThemeSupportFeatures.php +++ b/src/ReaderThemeSupportFeatures.php @@ -151,6 +151,13 @@ final class ReaderThemeSupportFeatures implements Service, Registerable { */ const KEY_CUSTOM_SPACING_SIZE = 'customSpacingSize'; + /** + * Key for `defaultSpacingSizes` boolean in theme.json (v3) + * + * @var string + */ + const KEY_DEFAULT_SPACING_SIZES = 'defaultSpacingSizes'; + /** * Action fired when the cached primary_theme_support should be updated. * @@ -496,10 +503,23 @@ private function print_editor_gradient_presets_styles( array $gradient_presets ) * Print spacing sizes custom properties. */ private function print_spacing_sizes_custom_properties() { - $custom_properties = []; - $spacing_sizes = wp_get_global_settings( [ self::KEY_SPACING, self::KEY_SPACING_SIZES ], self::KEY_THEME ); - $is_wp_generating_spacing_sizes = 0 !== wp_get_global_settings( [ self::KEY_SPACING, self::KEY_SPACING_SCALE ], self::KEY_THEME )[ self::KEY_STEPS ]; - $custom_spacing_size = wp_get_global_settings( [ self::KEY_SPACING, self::KEY_CUSTOM_SPACING_SIZE ], self::KEY_THEME ); + $custom_properties = []; + $spacing = wp_get_global_settings( [ self::KEY_SPACING ], self::KEY_THEME ); + $spacing_sizes = $spacing[ self::KEY_SPACING_SIZES ] ?? []; + $custom_spacing_size = $spacing[ self::KEY_CUSTOM_SPACING_SIZE ] ?? false; + $spacing_scale = $spacing[ self::KEY_SPACING_SCALE ] ?? []; + + /* + * By default check for `defaultSpacingSizes` boolean introduced in theme.json (v3) + * and if it's false, then check for `steps` in `spacingScale` which is v2 default. + * + * @see . + */ + $is_wp_generating_spacing_sizes = $spacing[ self::KEY_DEFAULT_SPACING_SIZES ] ?? false; + + if ( isset( $spacing_scale[ self::KEY_STEPS ] ) ) { + $is_wp_generating_spacing_sizes = 0 !== $spacing_scale[ self::KEY_STEPS ]; + } if ( ! $is_wp_generating_spacing_sizes && $custom_spacing_size ) { if ( isset( $spacing_sizes[ self::KEY_THEME ] ) ) { From 3968abdbdd0b91e38506fafa16cc684aca4363a1 Mon Sep 17 00:00:00 2001 From: Lovekesh Kumar Date: Fri, 7 Jun 2024 01:58:57 +0530 Subject: [PATCH 3/4] Fix PHPDoc comments Co-authored-by: Weston Ruter --- src/ReaderThemeSupportFeatures.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ReaderThemeSupportFeatures.php b/src/ReaderThemeSupportFeatures.php index 4c9943a1f48..6d741b3127f 100644 --- a/src/ReaderThemeSupportFeatures.php +++ b/src/ReaderThemeSupportFeatures.php @@ -152,7 +152,7 @@ final class ReaderThemeSupportFeatures implements Service, Registerable { const KEY_CUSTOM_SPACING_SIZE = 'customSpacingSize'; /** - * Key for `defaultSpacingSizes` boolean in theme.json (v3) + * Key for `defaultSpacingSizes` boolean in theme.json (v3). * * @var string */ @@ -509,7 +509,7 @@ private function print_spacing_sizes_custom_properties() { $custom_spacing_size = $spacing[ self::KEY_CUSTOM_SPACING_SIZE ] ?? false; $spacing_scale = $spacing[ self::KEY_SPACING_SCALE ] ?? []; - /* + /** * By default check for `defaultSpacingSizes` boolean introduced in theme.json (v3) * and if it's false, then check for `steps` in `spacingScale` which is v2 default. * From 59862291e54dec2d343974faefdf7d2301a3ff1f Mon Sep 17 00:00:00 2001 From: Lovekesh Kumar Date: Fri, 7 Jun 2024 02:00:42 +0530 Subject: [PATCH 4/4] Update `isset()` with `array_key_exists()` Co-authored-by: Weston Ruter --- src/ReaderThemeSupportFeatures.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReaderThemeSupportFeatures.php b/src/ReaderThemeSupportFeatures.php index 6d741b3127f..fe52f20968f 100644 --- a/src/ReaderThemeSupportFeatures.php +++ b/src/ReaderThemeSupportFeatures.php @@ -517,7 +517,7 @@ private function print_spacing_sizes_custom_properties() { */ $is_wp_generating_spacing_sizes = $spacing[ self::KEY_DEFAULT_SPACING_SIZES ] ?? false; - if ( isset( $spacing_scale[ self::KEY_STEPS ] ) ) { + if ( array_key_exists( self::KEY_STEPS, $spacing_scale ) ) { $is_wp_generating_spacing_sizes = 0 !== $spacing_scale[ self::KEY_STEPS ]; }