Changeset 53076
- Timestamp:
- 04/05/2022 12:06:48 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/border.php
r52302 r53076 51 51 */ 52 52 function wp_apply_border_support( $block_type, $block_attributes ) { 53 if ( wp_s kip_border_serialization( $block_type) ) {53 if ( wp_should_skip_block_supports_serialization( $block_type, 'border' ) ) { 54 54 return array(); 55 55 } … … 61 61 if ( 62 62 wp_has_border_feature_support( $block_type, 'radius' ) && 63 isset( $block_attributes['style']['border']['radius'] ) 63 isset( $block_attributes['style']['border']['radius'] ) && 64 ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' ) 64 65 ) { 65 66 $border_radius = $block_attributes['style']['border']['radius']; … … 85 86 if ( 86 87 wp_has_border_feature_support( $block_type, 'style' ) && 87 isset( $block_attributes['style']['border']['style'] ) 88 isset( $block_attributes['style']['border']['style'] ) && 89 ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) 88 90 ) { 89 91 $border_style = $block_attributes['style']['border']['style']; … … 94 96 if ( 95 97 wp_has_border_feature_support( $block_type, 'width' ) && 96 isset( $block_attributes['style']['border']['width'] ) 98 isset( $block_attributes['style']['border']['width'] ) && 99 ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) 97 100 ) { 98 101 $border_width = $block_attributes['style']['border']['width']; … … 107 110 108 111 // Border color. 109 if ( wp_has_border_feature_support( $block_type, 'color' ) ) { 112 if ( 113 wp_has_border_feature_support( $block_type, 'color' ) && 114 ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) 115 ) { 110 116 $has_named_border_color = array_key_exists( 'borderColor', $block_attributes ); 111 117 $has_custom_border_color = isset( $block_attributes['style']['border']['color'] ); … … 135 141 136 142 return $attributes; 137 }138 139 /**140 * Checks whether serialization of the current block's border properties should141 * occur.142 *143 * @since 5.8.0144 * @access private145 *146 * @param WP_Block_Type $block_type Block type.147 * @return bool Whether serialization of the current block's border properties148 * should occur.149 */150 function wp_skip_border_serialization( $block_type ) {151 $border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false );152 153 return is_array( $border_support ) &&154 array_key_exists( '__experimentalSkipSerialization', $border_support ) &&155 $border_support['__experimentalSkipSerialization'];156 143 } 157 144 -
trunk/src/wp-includes/block-supports/colors.php
r52069 r53076 76 76 if ( 77 77 is_array( $color_support ) && 78 array_key_exists( '__experimentalSkipSerialization', $color_support ) && 79 $color_support['__experimentalSkipSerialization'] 78 wp_should_skip_block_supports_serialization( $block_type, 'color' ) 80 79 ) { 81 80 return array(); … … 90 89 // Text colors. 91 90 // Check support for text colors. 92 if ( $has_text_colors_support ) {91 if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) { 93 92 $has_named_text_color = array_key_exists( 'textColor', $block_attributes ); 94 93 $has_custom_text_color = isset( $block_attributes['style']['color']['text'] ); … … 107 106 108 107 // Background colors. 109 if ( $has_background_colors_support ) {108 if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) { 110 109 $has_named_background_color = array_key_exists( 'backgroundColor', $block_attributes ); 111 110 $has_custom_background_color = isset( $block_attributes['style']['color']['background'] ); … … 124 123 125 124 // Gradients. 126 if ( $has_gradients_support ) {125 if ( $has_gradients_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) ) { 127 126 $has_named_gradient = array_key_exists( 'gradient', $block_attributes ); 128 127 $has_custom_gradient = isset( $block_attributes['style']['color']['gradient'] ); -
trunk/src/wp-includes/block-supports/dimensions.php
r52302 r53076 5 5 * This does not include the `spacing` block support even though that visually 6 6 * appears under the "Dimensions" panel in the editor. It remains in its 7 * original `spacing.php` file for backwards compatibility.7 * original `spacing.php` file for compatibility with core. 8 8 * 9 9 * @package WordPress … … 52 52 */ 53 53 function wp_apply_dimensions_support( $block_type, $block_attributes ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable 54 if ( wp_s kip_dimensions_serialization( $block_type) ) {54 if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalDimensions' ) ) { 55 55 return array(); 56 56 } … … 64 64 } 65 65 66 /**67 * Checks whether serialization of the current block's dimensions properties68 * should occur.69 *70 * @since 5.9.071 * @access private72 *73 * @param WP_Block_type $block_type Block type.74 * @return bool Whether to serialize spacing support styles & classes.75 */76 function wp_skip_dimensions_serialization( $block_type ) {77 $dimensions_support = _wp_array_get( $block_type->supports, array( '__experimentalDimensions' ), false );78 return is_array( $dimensions_support ) &&79 array_key_exists( '__experimentalSkipSerialization', $dimensions_support ) &&80 $dimensions_support['__experimentalSkipSerialization'];81 }82 83 66 // Register the block support. 84 67 WP_Block_Supports::get_instance()->register( -
trunk/src/wp-includes/block-supports/elements.php
r53012 r53076 19 19 function wp_render_elements_support( $block_content, $block ) { 20 20 if ( ! $block_content ) { 21 return $block_content; 22 } 23 24 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); 25 $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' ); 26 27 if ( $skip_link_color_serialization ) { 21 28 return $block_content; 22 29 } -
trunk/src/wp-includes/block-supports/spacing.php
r52434 r53076 45 45 */ 46 46 function wp_apply_spacing_support( $block_type, $block_attributes ) { 47 if ( wp_s kip_spacing_serialization( $block_type) ) {47 if ( wp_should_skip_block_supports_serialization( $block_type, 'spacing' ) ) { 48 48 return array(); 49 49 } … … 51 51 $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false ); 52 52 $has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false ); 53 $skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' ); 54 $skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' ); 53 55 $styles = array(); 54 56 55 if ( $has_padding_support ) {57 if ( $has_padding_support && ! $skip_padding ) { 56 58 $padding_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'padding' ), null ); 57 59 if ( is_array( $padding_value ) ) { … … 64 66 } 65 67 66 if ( $has_margin_support ) {68 if ( $has_margin_support && ! $skip_margin ) { 67 69 $margin_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'margin' ), null ); 68 70 if ( is_array( $margin_value ) ) { … … 78 80 } 79 81 80 /**81 * Checks whether serialization of the current block's spacing properties should82 * occur.83 *84 * @since 5.9.085 * @access private86 *87 * @param WP_Block_Type $block_type Block type.88 * @return bool Whether to serialize spacing support styles & classes.89 */90 function wp_skip_spacing_serialization( $block_type ) {91 $spacing_support = _wp_array_get( $block_type->supports, array( 'spacing' ), false );92 93 return is_array( $spacing_support ) &&94 array_key_exists( '__experimentalSkipSerialization', $spacing_support ) &&95 $spacing_support['__experimentalSkipSerialization'];96 }97 98 82 // Register the block support. 99 83 WP_Block_Supports::get_instance()->register( -
trunk/src/wp-includes/block-supports/typography.php
r52302 r53076 82 82 } 83 83 84 $skip_typography_serialization = _wp_array_get( $typography_supports, array( '__experimentalSkipSerialization' ), false ); 85 if ( $skip_typography_serialization ) { 84 if ( wp_should_skip_block_supports_serialization( $block_type, 'typography' ) ) { 86 85 return array(); 87 86 } … … 100 99 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); 101 100 102 if ( $has_font_size_support ) {101 if ( $has_font_size_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' ) ) { 103 102 $has_named_font_size = array_key_exists( 'fontSize', $block_attributes ); 104 103 $has_custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] ); … … 111 110 } 112 111 113 if ( $has_font_family_support ) {112 if ( $has_font_family_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontFamily' ) ) { 114 113 $has_named_font_family = array_key_exists( 'fontFamily', $block_attributes ); 115 114 $has_custom_font_family = isset( $block_attributes['style']['typography']['fontFamily'] ); … … 130 129 } 131 130 132 if ( $has_font_style_support ) {131 if ( $has_font_style_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontStyle' ) ) { 133 132 $font_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' ); 134 133 if ( $font_style ) { … … 137 136 } 138 137 139 if ( $has_font_weight_support ) {138 if ( $has_font_weight_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontWeight' ) ) { 140 139 $font_weight = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' ); 141 140 if ( $font_weight ) { … … 144 143 } 145 144 146 if ( $has_line_height_support ) {145 if ( $has_line_height_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'lineHeight' ) ) { 147 146 $has_line_height = isset( $block_attributes['style']['typography']['lineHeight'] ); 148 147 if ( $has_line_height ) { … … 151 150 } 152 151 153 if ( $has_text_decoration_support ) {152 if ( $has_text_decoration_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' ) ) { 154 153 $text_decoration_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' ); 155 154 if ( $text_decoration_style ) { … … 158 157 } 159 158 160 if ( $has_text_transform_support ) {159 if ( $has_text_transform_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' ) ) { 161 160 $text_transform_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' ); 162 161 if ( $text_transform_style ) { … … 165 164 } 166 165 167 if ( $has_letter_spacing_support ) {166 if ( $has_letter_spacing_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' ) ) { 168 167 $letter_spacing_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'letterSpacing', 'letter-spacing' ); 169 168 if ( $letter_spacing_style ) { -
trunk/src/wp-settings.php
r53004 r53076 318 318 require ABSPATH . WPINC . '/block-patterns.php'; 319 319 require ABSPATH . WPINC . '/class-wp-block-supports.php'; 320 require ABSPATH . WPINC . '/block-supports/utils.php'; 320 321 require ABSPATH . WPINC . '/block-supports/align.php'; 321 322 require ABSPATH . WPINC . '/block-supports/border.php'; -
trunk/tests/phpunit/tests/block-supports/colors.php
r52264 r53076 45 45 unregister_block_type( 'test/color-slug-with-numbers' ); 46 46 } 47 48 /** 49 * @ticket 55505 50 */ 51 function test_color_with_skipped_serialization_block_supports() { 52 $block_name = 'test/color-with-skipped-serialization-block-supports'; 53 register_block_type( 54 $block_name, 55 array( 56 'api_version' => 2, 57 'attributes' => array( 58 'style' => array( 59 'type' => 'object', 60 ), 61 ), 62 'supports' => array( 63 'color' => array( 64 'text' => true, 65 'gradients' => true, 66 '__experimentalSkipSerialization' => true, 67 ), 68 ), 69 ) 70 ); 71 72 $registry = WP_Block_Type_Registry::get_instance(); 73 $block_type = $registry->get_registered( $block_name ); 74 $block_atts = array( 75 'style' => array( 76 'color' => array( 77 'text' => '#d92828', 78 'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,13,13) 46%,rgb(155,81,224) 100%)', 79 ), 80 ), 81 ); 82 83 $actual = wp_apply_colors_support( $block_type, $block_atts ); 84 $expected = array(); 85 86 $this->assertSame( $expected, $actual ); 87 unregister_block_type( $block_name ); 88 } 89 90 /** 91 * @ticket 55505 92 */ 93 function test_gradient_with_individual_skipped_serialization_block_supports() { 94 $block_name = 'test/gradient-with-individual-skipped-serialization-block-support'; 95 register_block_type( 96 $block_name, 97 array( 98 'api_version' => 2, 99 'attributes' => array( 100 'style' => array( 101 'type' => 'object', 102 ), 103 ), 104 'supports' => array( 105 'color' => array( 106 'text' => true, 107 'gradients' => true, 108 '__experimentalSkipSerialization' => array( 'gradients' ), 109 ), 110 ), 111 ) 112 ); 113 114 $registry = WP_Block_Type_Registry::get_instance(); 115 $block_type = $registry->get_registered( $block_name ); 116 $block_atts = array( 117 'style' => array( 118 'color' => array( 119 'text' => '#d92828', 120 ), 121 ), 122 ); 123 124 $actual = wp_apply_colors_support( $block_type, $block_atts ); 125 $expected = array( 126 'class' => 'has-text-color', 127 'style' => 'color: #d92828;', 128 ); 129 130 $this->assertSame( $expected, $actual ); 131 unregister_block_type( $block_name ); 132 } 47 133 } -
trunk/tests/phpunit/tests/block-supports/typography.php
r52264 r53076 63 63 } 64 64 65 /** 66 * @ticket 55505 67 */ 68 function test_typography_with_skipped_serialization_block_supports() { 69 $block_name = 'test/typography-with-skipped-serialization-block-supports'; 70 register_block_type( 71 $block_name, 72 array( 73 'api_version' => 2, 74 'attributes' => array( 75 'style' => array( 76 'type' => 'object', 77 ), 78 ), 79 'supports' => array( 80 'typography' => array( 81 'fontSize' => true, 82 'lineHeight' => true, 83 '__experimentalFontFamily' => true, 84 '__experimentalLetterSpacing' => true, 85 '__experimentalSkipSerialization' => true, 86 ), 87 ), 88 ) 89 ); 90 $registry = WP_Block_Type_Registry::get_instance(); 91 $block_type = $registry->get_registered( $block_name ); 92 $block_atts = array( 93 'style' => array( 94 'typography' => array( 95 'fontSize' => 'serif', 96 'lineHeight' => 'serif', 97 'fontFamily' => '22px', 98 'letterSpacing' => '22px', 99 ), 100 ), 101 ); 102 103 $actual = wp_apply_typography_support( $block_type, $block_atts ); 104 $expected = array(); 105 106 $this->assertSame( $expected, $actual ); 107 unregister_block_type( $block_name ); 108 } 109 110 /** 111 * @ticket 55505 112 */ 113 function test_letter_spacing_with_individual_skipped_serialization_block_supports() { 114 $block_name = 'test/letter-spacing-with-individua-skipped-serialization-block-supports'; 115 register_block_type( 116 $block_name, 117 array( 118 'api_version' => 2, 119 'attributes' => array( 120 'style' => array( 121 'type' => 'object', 122 ), 123 ), 124 'supports' => array( 125 'typography' => array( 126 '__experimentalLetterSpacing' => true, 127 '__experimentalSkipSerialization' => array( 128 'letterSpacing', 129 ), 130 ), 131 ), 132 ) 133 ); 134 $registry = WP_Block_Type_Registry::get_instance(); 135 $block_type = $registry->get_registered( $block_name ); 136 $block_atts = array( 'style' => array( 'typography' => array( 'letterSpacing' => '22px' ) ) ); 137 138 $actual = wp_apply_typography_support( $block_type, $block_atts ); 139 $expected = array(); 140 141 $this->assertSame( $expected, $actual ); 142 unregister_block_type( $block_name ); 143 } 144 65 145 function test_font_family_with_legacy_inline_styles_using_a_css_var() { 66 146 $block_name = 'test/font-family-with-inline-styles-using-css-var';
Note: See TracChangeset
for help on using the changeset viewer.