| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | * |
| 40 | 40 | * @return array Border CSS classes and inline styles. |
| 41 | 41 | */ |
| 42 | 42 | function gutenberg_apply_border_support( $block_type, $block_attributes ) { |
| 43 | - if ( wp_should_skip_block_supports_serialization( $block_type, 'border' ) ) { | |
| 43 | + if ( gutenberg_should_skip_block_supports_serialization( $block_type, 'border' ) ) { | |
| 44 | 44 | return array(); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $border_block_styles = array(); |
| @@ -51,9 +51,9 @@ | ||
| 51 | 51 | // Border radius. |
| 52 | 52 | if ( |
| 53 | 53 | gutenberg_has_border_feature_support( $block_type, 'radius' ) && |
| 54 | 54 | isset( $block_attributes['style']['border']['radius'] ) && |
| 55 | - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' ) | |
| 55 | + ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' ) | |
| 56 | 56 | ) { |
| 57 | 57 | $border_radius = $block_attributes['style']['border']['radius']; |
| 58 | 58 | |
| 59 | 59 | if ( is_numeric( $border_radius ) ) { |
| @@ -66,9 +66,9 @@ | ||
| 66 | 66 | // Border style. |
| 67 | 67 | if ( |
| 68 | 68 | gutenberg_has_border_feature_support( $block_type, 'style' ) && |
| 69 | 69 | isset( $block_attributes['style']['border']['style'] ) && |
| 70 | - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) | |
| 70 | + ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) | |
| 71 | 71 | ) { |
| 72 | 72 | $border_block_styles['style'] = $block_attributes['style']['border']['style']; |
| 73 | 73 | } |
| 74 | 74 | |
| @@ -75,9 +75,9 @@ | ||
| 75 | 75 | // Border width. |
| 76 | 76 | if ( |
| 77 | 77 | $has_border_width_support && |
| 78 | 78 | isset( $block_attributes['style']['border']['width'] ) && |
| 79 | - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) | |
| 79 | + ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) | |
| 80 | 80 | ) { |
| 81 | 81 | $border_width = $block_attributes['style']['border']['width']; |
| 82 | 82 | |
| 83 | 83 | // This check handles original unitless implementation. |
| @@ -90,12 +90,12 @@ | ||
| 90 | 90 | |
| 91 | 91 | // Border color. |
| 92 | 92 | if ( |
| 93 | 93 | $has_border_color_support && |
| 94 | - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) | |
| 94 | + ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) | |
| 95 | 95 | ) { |
| 96 | 96 | $preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null; |
| 97 | - $custom_border_color = $block_attributes['style']['border']['color'] ?? null; | |
| 97 | + $custom_border_color = _wp_array_get( $block_attributes, array( 'style', 'border', 'color' ), null ); | |
| 98 | 98 | $border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Generate styles for individual border sides. |
| @@ -100,13 +100,13 @@ | ||
| 100 | 100 | |
| 101 | 101 | // Generate styles for individual border sides. |
| 102 | 102 | if ( $has_border_color_support || $has_border_width_support ) { |
| 103 | 103 | foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { |
| 104 | - $border = $block_attributes['style']['border'][ $side ] ?? null; | |
| 104 | + $border = _wp_array_get( $block_attributes, array( 'style', 'border', $side ), null ); | |
| 105 | 105 | $border_side_values = array( |
| 106 | - 'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null, | |
| 107 | - 'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null, | |
| 108 | - 'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null, | |
| 106 | + 'width' => isset( $border['width'] ) && ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null, | |
| 107 | + 'color' => isset( $border['color'] ) && ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null, | |
| 108 | + 'style' => isset( $border['style'] ) && ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null, | |
| 109 | 109 | ); |
| 110 | 110 | $border_block_styles[ $side ] = $border_side_values; |
| 111 | 111 | } |
| 112 | 112 | } |
| @@ -133,26 +133,26 @@ | ||
| 133 | 133 | * support features are available. Otherwise, the specific feature's support |
| 134 | 134 | * flag nested under `experimentalBorder` must be enabled for the feature |
| 135 | 135 | * to be opted into. |
| 136 | 136 | * |
| 137 | - * @param WP_Block_Type $block_type Block type to check for support. | |
| 138 | - * @param string $feature Name of the feature to check support for. | |
| 139 | - * @param mixed $default_value Fallback value for feature support, defaults to false. | |
| 137 | + * @param WP_Block_Type $block_type Block type to check for support. | |
| 138 | + * @param string $feature Name of the feature to check support for. | |
| 139 | + * @param mixed $default Fallback value for feature support, defaults to false. | |
| 140 | 140 | * |
| 141 | 141 | * @return boolean Whether or not the feature is supported. |
| 142 | 142 | */ |
| 143 | -function gutenberg_has_border_feature_support( $block_type, $feature, $default_value = false ) { | |
| 143 | +function gutenberg_has_border_feature_support( $block_type, $feature, $default = false ) { | |
| 144 | 144 | // Check if all border support features have been opted into via `"__experimentalBorder": true`. |
| 145 | - if ( $block_type instanceof WP_Block_Type ) { | |
| 146 | - $block_type_supports_border = $block_type->supports['__experimentalBorder'] ?? $default_value; | |
| 147 | - if ( true === $block_type_supports_border ) { | |
| 148 | - return true; | |
| 149 | - } | |
| 145 | + if ( | |
| 146 | + property_exists( $block_type, 'supports' ) && | |
| 147 | + ( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default ) ) | |
| 148 | + ) { | |
| 149 | + return true; | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Check if the specific feature has been opted into individually |
| 153 | 153 | // via nested flag under `__experimentalBorder`. |
| 154 | - return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value ); | |
| 154 | + return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default ); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Register the block support. |
| 158 | 158 | WP_Block_Supports::get_instance()->register( |