From cfccc141a4809bf12623e5a25532588c783a428d Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 13 Jan 2025 12:25:19 +0530 Subject: [PATCH 01/14] Add ancestor block context --- plugins/auto-sizes/hooks.php | 2 +- .../includes/improve-calculate-sizes.php | 55 ++++++++++++++++++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/plugins/auto-sizes/hooks.php b/plugins/auto-sizes/hooks.php index 55cbe9dec2..2feab89013 100644 --- a/plugins/auto-sizes/hooks.php +++ b/plugins/auto-sizes/hooks.php @@ -39,4 +39,4 @@ function auto_sizes_render_generator(): void { add_filter( 'render_block_core/image', 'auto_sizes_filter_image_tag', 10, 3 ); add_filter( 'render_block_core/cover', 'auto_sizes_filter_image_tag', 10, 3 ); add_filter( 'get_block_type_uses_context', 'auto_sizes_filter_uses_context', 10, 2 ); -add_filter( 'render_block_context', 'auto_sizes_filter_render_block_context', 10, 2 ); +add_filter( 'render_block_context', 'auto_sizes_filter_render_block_context', 10, 3 ); diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index 7b57f08e36..a94c3e6f54 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -273,11 +273,12 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo * * @since 1.4.0 * - * @param array $context Current block context. - * @param array $block The block being rendered. + * @param array $context Current block context. + * @param array $block The block being rendered. + * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. * @return array Modified block context. */ -function auto_sizes_filter_render_block_context( array $context, array $block ): array { +function auto_sizes_filter_render_block_context( array $context, array $block, WP_Block $parent_block = null ): array { // When no max alignment is set, the maximum is assumed to be 'full'. $context['max_alignment'] = $context['max_alignment'] ?? 'full'; @@ -298,5 +299,53 @@ function auto_sizes_filter_render_block_context( array $context, array $block ): } } + static $block_width_data = array(); + + if ( null !== $parent_block ) { + $block_width_data = array(); + } + + $block_width_data = $parent_block->context['block_width_data'] ?? $block_width_data; + if ( 'core/group' === $block['blockName'] || 'core/columns' === $block['blockName'] ) { + if ( isset( $block['attrs']['align'] ) ) { + switch ( $block['attrs']['align'] ) { + case 'full': + $block_width_data[][ $block['blockName'] ] = 'full'; + break; + case 'wide': + $block_width_data[][ $block['blockName'] ] = 'wide'; // Use actual `wideWidth` here. + break; + default: + $block_width_data[][ $block['blockName'] ] = 'default'; // Use actual `contentWidth` here. + break; + } + } else { + $block_width_data[][ $block['blockName'] ] = 'default'; // Use actual `contentWidth` here. + } + } + + if ( 'core/columns' === $block['blockName'] ) { + // This is a special context key just to pass to the child 'core/column' block. + $context['column_count'] = count( $block['innerBlocks'] ); + } + + if ( 'core/column' === $block['blockName'] ) { + $found_image_block = wp_get_first_block( $block['innerBlocks'], 'core/image' ); + $found_cover_block = wp_get_first_block( $block['innerBlocks'], 'core/cover' ); + if ( count( $found_image_block ) > 0 || count( $found_cover_block ) > 0 ) { + if ( isset( $block['attrs']['width'] ) && '' !== $block['attrs']['width'] ) { + // Use specific column width. + $block_width_data[][ $block['blockName'] ] = $block['attrs']['width']; + } elseif ( isset( $parent_block->context['column_count'] ) && $parent_block->context['column_count'] ) { + // Determine the width based on equally sized columns. + $block_width_data[][ $block['blockName'] ] = '' . ( 100 / $parent_block->context['column_count'] ) . '%'; + } + } + } + + if ( $block_width_data ) { + $context['block_width_data'] = $block_width_data; + } + return $context; } From ae55c97a2da22d05fdb954f186c353e9c38d0a67 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 13 Jan 2025 12:56:24 +0530 Subject: [PATCH 02/14] Add block_width_data in to user context filter --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index a94c3e6f54..62e83d3f16 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -263,7 +263,7 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo if ( in_array( $block_type->name, $consumer_blocks, true ) ) { // Use array_values to reset the array keys after merging. - return array_values( array_unique( array_merge( $uses_context, array( 'max_alignment' ) ) ) ); + return array_values( array_unique( array_merge( $uses_context, array( 'max_alignment', 'block_width_data' ) ) ) ); } return $uses_context; } From f235cb56b711f9b6330297a29235960613183041 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 13 Jan 2025 14:09:01 +0530 Subject: [PATCH 03/14] Minor changes --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index 62e83d3f16..e06747c4e4 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -278,7 +278,7 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. * @return array Modified block context. */ -function auto_sizes_filter_render_block_context( array $context, array $block, WP_Block $parent_block = null ): array { +function auto_sizes_filter_render_block_context( array $context, array $block, ?WP_Block $parent_block ): array { // When no max alignment is set, the maximum is assumed to be 'full'. $context['max_alignment'] = $context['max_alignment'] ?? 'full'; @@ -301,7 +301,7 @@ function auto_sizes_filter_render_block_context( array $context, array $block, W static $block_width_data = array(); - if ( null !== $parent_block ) { + if ( null === $parent_block ) { $block_width_data = array(); } From be6cd9f8f62d0bc0938a53fe06bfbf472be688a8 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 13 Jan 2025 14:43:39 +0530 Subject: [PATCH 04/14] Remove inline comment --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index e06747c4e4..a5922b7e18 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -313,14 +313,14 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? $block_width_data[][ $block['blockName'] ] = 'full'; break; case 'wide': - $block_width_data[][ $block['blockName'] ] = 'wide'; // Use actual `wideWidth` here. + $block_width_data[][ $block['blockName'] ] = 'wide'; break; default: - $block_width_data[][ $block['blockName'] ] = 'default'; // Use actual `contentWidth` here. + $block_width_data[][ $block['blockName'] ] = 'default'; break; } } else { - $block_width_data[][ $block['blockName'] ] = 'default'; // Use actual `contentWidth` here. + $block_width_data[][ $block['blockName'] ] = 'default'; } } From f25e791678b3b67c0b7936a86b121caac9e8d1e7 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 10 Mar 2025 18:03:04 +0530 Subject: [PATCH 05/14] Utilize max alignment option instead of array --- .wp-env.json | 2 +- .../includes/improve-calculate-sizes.php | 78 +++++++------------ 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/.wp-env.json b/.wp-env.json index 3887c95a09..9de2f22b8b 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,5 +1,5 @@ { - "core": null, + "core": "https://wordpress.org/wordpress-6.8-beta1.zip", "plugins": [ "./plugins/optimization-detective", "./plugins/auto-sizes", diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index a5922b7e18..57018d4bbc 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -6,6 +6,19 @@ * @since 1.4.0 */ +/* + * Map alignment values to a weighting value so they can be compared. + * Note that 'left' and 'right' alignments are only constrained by max alignment. + */ +const AUTO_SIZES_CONSTRAINTS = array( + 'full' => 0, + 'wide' => 1, + 'left' => 2, + 'right' => 2, + 'default' => 3, + 'center' => 3, +); + /** * Primes attachment into the cache with a single database query. * @@ -172,18 +185,8 @@ function auto_sizes_calculate_better_sizes( int $id, $size, string $align, int $ // Normalize default alignment values. $align = '' !== $align ? $align : 'default'; - /* - * Map alignment values to a weighting value so they can be compared. - * Note that 'left' and 'right' alignments are only constrained by max alignment. - */ - $constraints = array( - 'full' => 0, - 'wide' => 1, - 'left' => 2, - 'right' => 2, - 'default' => 3, - 'center' => 3, - ); + // Use the defined constant for constraints. + $constraints = AUTO_SIZES_CONSTRAINTS; $alignment = $constraints[ $align ] > $constraints[ $max_alignment ] ? $align : $max_alignment; @@ -259,11 +262,14 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo $consumer_blocks = array( 'core/cover', 'core/image', + 'core/group', + 'core/columns', + 'core/column', ); if ( in_array( $block_type->name, $consumer_blocks, true ) ) { // Use array_values to reset the array keys after merging. - return array_values( array_unique( array_merge( $uses_context, array( 'max_alignment', 'block_width_data' ) ) ) ); + return array_values( array_unique( array_merge( $uses_context, array( 'max_alignment', 'column_count', 'column_width' ) ) ) ); } return $uses_context; } @@ -289,38 +295,13 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? ); if ( in_array( $block['blockName'], $provider_blocks, true ) ) { - $alignment = $block['attrs']['align'] ?? ''; + // Normalize default alignment values. + $alignment = isset( $block['attrs']['align'] ) && '' !== $block['attrs']['align'] ? $block['attrs']['align'] : 'default'; + // Use the defined constant for constraints. + $constraints = AUTO_SIZES_CONSTRAINTS; - // If the container block doesn't have alignment, it's assumed to be 'default'. - if ( '' === $alignment ) { - $context['max_alignment'] = 'default'; - } elseif ( 'wide' === $alignment ) { - $context['max_alignment'] = 'wide'; - } - } - - static $block_width_data = array(); - - if ( null === $parent_block ) { - $block_width_data = array(); - } - - $block_width_data = $parent_block->context['block_width_data'] ?? $block_width_data; - if ( 'core/group' === $block['blockName'] || 'core/columns' === $block['blockName'] ) { - if ( isset( $block['attrs']['align'] ) ) { - switch ( $block['attrs']['align'] ) { - case 'full': - $block_width_data[][ $block['blockName'] ] = 'full'; - break; - case 'wide': - $block_width_data[][ $block['blockName'] ] = 'wide'; - break; - default: - $block_width_data[][ $block['blockName'] ] = 'default'; - break; - } - } else { - $block_width_data[][ $block['blockName'] ] = 'default'; + if ( 'default' === $alignment || 'wide' === $alignment ) { + $context['max_alignment'] = $constraints[ $context['max_alignment'] ] > $constraints[ $alignment ] ? $context['max_alignment'] : $alignment; } } @@ -335,17 +316,12 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? if ( count( $found_image_block ) > 0 || count( $found_cover_block ) > 0 ) { if ( isset( $block['attrs']['width'] ) && '' !== $block['attrs']['width'] ) { // Use specific column width. - $block_width_data[][ $block['blockName'] ] = $block['attrs']['width']; + $context['column_width'] = $block['attrs']['width']; } elseif ( isset( $parent_block->context['column_count'] ) && $parent_block->context['column_count'] ) { // Determine the width based on equally sized columns. - $block_width_data[][ $block['blockName'] ] = '' . ( 100 / $parent_block->context['column_count'] ) . '%'; + $context['column_width'] = '' . ( 100 / $parent_block->context['column_count'] ) . '%'; } } } - - if ( $block_width_data ) { - $context['block_width_data'] = $block_width_data; - } - return $context; } From 54ee498c61c66926c5812083cd4faaf19d0e73f4 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 11 Mar 2025 16:48:29 +0530 Subject: [PATCH 06/14] Calculate column width per parent columns --- .../includes/improve-calculate-sizes.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index 57018d4bbc..dc6a6f5c5c 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -99,6 +99,7 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b $alignment = $block->attributes['align'] ?? ''; $width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0; $max_alignment = $block->context['max_alignment'] ?? ''; + $column_width = $block->context['column_width'] ?? ''; /* * Update width for cover block. @@ -314,12 +315,22 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? $found_image_block = wp_get_first_block( $block['innerBlocks'], 'core/image' ); $found_cover_block = wp_get_first_block( $block['innerBlocks'], 'core/cover' ); if ( count( $found_image_block ) > 0 || count( $found_cover_block ) > 0 ) { + // Get column width, if explicitly set. if ( isset( $block['attrs']['width'] ) && '' !== $block['attrs']['width'] ) { - // Use specific column width. - $context['column_width'] = $block['attrs']['width']; + $current_width = floatval( rtrim( $block['attrs']['width'], '%' ) ) / 100; } elseif ( isset( $parent_block->context['column_count'] ) && $parent_block->context['column_count'] ) { - // Determine the width based on equally sized columns. - $context['column_width'] = '' . ( 100 / $parent_block->context['column_count'] ) . '%'; + // Default to equally divided width if not explicitly set. + $current_width = 1 / $parent_block->context['column_count']; + } else { + // Full width fallback. + $current_width = 1; + } + + // Multiply with parent's width if available. + if ( isset( $parent_block->context['column_width'] ) ) { + $context['column_width'] = $parent_block->context['column_width'] * $current_width; + } else { + $context['column_width'] = $current_width; } } } From 09d49904cde646451477511b357861638663272a Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 20 Mar 2025 09:44:24 +0530 Subject: [PATCH 07/14] Define block specific context usade --- .../includes/improve-calculate-sizes.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index dc6a6f5c5c..2194eee9a6 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -259,18 +259,18 @@ function auto_sizes_get_layout_width( string $alignment ): string { * @return string[] The filtered context keys used by the block type. */ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $block_type ): array { - // The list of blocks that can consume outer layout context. - $consumer_blocks = array( - 'core/cover', - 'core/image', - 'core/group', - 'core/columns', - 'core/column', + // Define block-specific context usage. + $block_specific_context = array( + 'core/cover' => array( 'max_alignment' ), + 'core/image' => array( 'max_alignment', 'column_width' ), + 'core/group' => array( 'max_alignment' ), + 'core/columns' => array( 'max_alignment', 'column_width' ), + 'core/column' => array( 'column_count' ), ); - if ( in_array( $block_type->name, $consumer_blocks, true ) ) { - // Use array_values to reset the array keys after merging. - return array_values( array_unique( array_merge( $uses_context, array( 'max_alignment', 'column_count', 'column_width' ) ) ) ); + if ( isset( $block_specific_context[ $block_type->name ] ) ) { + // Use array_values to reset array keys after merging. + return array_values( array_unique( array_merge( $uses_context, $block_specific_context[ $block_type->name ] ) ) ); } return $uses_context; } From d74494e4d152d42b1eff6103a70b9b0ea2181277 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 20 Mar 2025 09:58:58 +0530 Subject: [PATCH 08/14] Use floats to clarify that the value should generally be a floating point number --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index 2194eee9a6..96c1444334 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -320,10 +320,10 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? $current_width = floatval( rtrim( $block['attrs']['width'], '%' ) ) / 100; } elseif ( isset( $parent_block->context['column_count'] ) && $parent_block->context['column_count'] ) { // Default to equally divided width if not explicitly set. - $current_width = 1 / $parent_block->context['column_count']; + $current_width = 1.0 / $parent_block->context['column_count']; } else { // Full width fallback. - $current_width = 1; + $current_width = 1.0; } // Multiply with parent's width if available. From 75d689b6a417bc8f2eba07e9383ff75511b201fd Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 20 Mar 2025 10:02:48 +0530 Subject: [PATCH 09/14] Use more generic term for column width context key --- .../includes/improve-calculate-sizes.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index 96c1444334..64ea8ba907 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -95,11 +95,11 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b */ $filter = static function ( $sizes, $size ) use ( $block ) { - $id = isset( $block->attributes['id'] ) ? (int) $block->attributes['id'] : 0; - $alignment = $block->attributes['align'] ?? ''; - $width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0; - $max_alignment = $block->context['max_alignment'] ?? ''; - $column_width = $block->context['column_width'] ?? ''; + $id = isset( $block->attributes['id'] ) ? (int) $block->attributes['id'] : 0; + $alignment = $block->attributes['align'] ?? ''; + $width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0; + $max_alignment = $block->context['max_alignment'] ?? ''; + $container_relative_width = $block->context['container_relative_width'] ?? ''; /* * Update width for cover block. @@ -262,9 +262,9 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo // Define block-specific context usage. $block_specific_context = array( 'core/cover' => array( 'max_alignment' ), - 'core/image' => array( 'max_alignment', 'column_width' ), + 'core/image' => array( 'max_alignment', 'container_relative_width' ), 'core/group' => array( 'max_alignment' ), - 'core/columns' => array( 'max_alignment', 'column_width' ), + 'core/columns' => array( 'max_alignment', 'container_relative_width' ), 'core/column' => array( 'column_count' ), ); @@ -327,10 +327,10 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? } // Multiply with parent's width if available. - if ( isset( $parent_block->context['column_width'] ) ) { - $context['column_width'] = $parent_block->context['column_width'] * $current_width; + if ( isset( $parent_block->context['container_relative_width'] ) ) { + $context['container_relative_width'] = $parent_block->context['container_relative_width'] * $current_width; } else { - $context['column_width'] = $current_width; + $context['container_relative_width'] = $current_width; } } } From d9b748737dfe835dd8473aa06798e44cc716b03f Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 20 Mar 2025 14:52:16 +0530 Subject: [PATCH 10/14] Add missing context and default value --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index 64ea8ba907..c75a2a6611 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -99,7 +99,7 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b $alignment = $block->attributes['align'] ?? ''; $width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0; $max_alignment = $block->context['max_alignment'] ?? ''; - $container_relative_width = $block->context['container_relative_width'] ?? ''; + $container_relative_width = $block->context['container_relative_width'] ?? '1.0'; /* * Update width for cover block. @@ -265,7 +265,7 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo 'core/image' => array( 'max_alignment', 'container_relative_width' ), 'core/group' => array( 'max_alignment' ), 'core/columns' => array( 'max_alignment', 'container_relative_width' ), - 'core/column' => array( 'column_count' ), + 'core/column' => array( 'max_alignment', 'column_count' ), ); if ( isset( $block_specific_context[ $block_type->name ] ) ) { From b981edc9c2038cff26957ea17599cfc6308ade78 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 26 Mar 2025 09:37:16 +0530 Subject: [PATCH 11/14] Use WP trunk version --- .wp-env.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.wp-env.json b/.wp-env.json index 9de2f22b8b..4df2389d11 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,5 +1,5 @@ { - "core": "https://wordpress.org/wordpress-6.8-beta1.zip", + "core": "WordPress/WordPress#master", "plugins": [ "./plugins/optimization-detective", "./plugins/auto-sizes", From 085d98e8ffeff15691fbe8d45cce29d91dfaa715 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 1 Apr 2025 09:45:40 +0530 Subject: [PATCH 12/14] Remove unuse variable --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index c75a2a6611..d23c4f4e4c 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -95,11 +95,10 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b */ $filter = static function ( $sizes, $size ) use ( $block ) { - $id = isset( $block->attributes['id'] ) ? (int) $block->attributes['id'] : 0; - $alignment = $block->attributes['align'] ?? ''; - $width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0; - $max_alignment = $block->context['max_alignment'] ?? ''; - $container_relative_width = $block->context['container_relative_width'] ?? '1.0'; + $id = isset( $block->attributes['id'] ) ? (int) $block->attributes['id'] : 0; + $alignment = $block->attributes['align'] ?? ''; + $width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0; + $max_alignment = $block->context['max_alignment'] ?? ''; /* * Update width for cover block. From 55349c2d8c8d1f091e90e5bc449df3afd3fe8756 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 1 Apr 2025 09:56:37 +0530 Subject: [PATCH 13/14] Add missing context for cover block --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index d23c4f4e4c..f6a2c8ebac 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -260,7 +260,7 @@ function auto_sizes_get_layout_width( string $alignment ): string { function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $block_type ): array { // Define block-specific context usage. $block_specific_context = array( - 'core/cover' => array( 'max_alignment' ), + 'core/cover' => array( 'max_alignment', 'container_relative_width' ), 'core/image' => array( 'max_alignment', 'container_relative_width' ), 'core/group' => array( 'max_alignment' ), 'core/columns' => array( 'max_alignment', 'container_relative_width' ), From 7757e50042f001b80504c93fdbed0ed69c493f06 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 1 Apr 2025 10:46:40 +0530 Subject: [PATCH 14/14] Remove specific alignment value checks --- plugins/auto-sizes/includes/improve-calculate-sizes.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php index f6a2c8ebac..72269fa043 100644 --- a/plugins/auto-sizes/includes/improve-calculate-sizes.php +++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php @@ -300,9 +300,7 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ? // Use the defined constant for constraints. $constraints = AUTO_SIZES_CONSTRAINTS; - if ( 'default' === $alignment || 'wide' === $alignment ) { - $context['max_alignment'] = $constraints[ $context['max_alignment'] ] > $constraints[ $alignment ] ? $context['max_alignment'] : $alignment; - } + $context['max_alignment'] = $constraints[ $context['max_alignment'] ] > $constraints[ $alignment ] ? $context['max_alignment'] : $alignment; } if ( 'core/columns' === $block['blockName'] ) {