Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu.../block-su...
File: border.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Border block support flag.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.8.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Registers the style attribute used by the border feature if needed for block
[9] Fix | Delete
* types that support borders.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 5.8.0
[12] Fix | Delete
* @since 6.1.0 Improved conditional blocks optimization.
[13] Fix | Delete
* @access private
[14] Fix | Delete
*
[15] Fix | Delete
* @param WP_Block_Type $block_type Block Type.
[16] Fix | Delete
*/
[17] Fix | Delete
function wp_register_border_support( $block_type ) {
[18] Fix | Delete
// Setup attributes and styles within that if needed.
[19] Fix | Delete
if ( ! $block_type->attributes ) {
[20] Fix | Delete
$block_type->attributes = array();
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
if ( block_has_support( $block_type, '__experimentalBorder' ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
[24] Fix | Delete
$block_type->attributes['style'] = array(
[25] Fix | Delete
'type' => 'object',
[26] Fix | Delete
);
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
if ( wp_has_border_feature_support( $block_type, 'color' ) && ! array_key_exists( 'borderColor', $block_type->attributes ) ) {
[30] Fix | Delete
$block_type->attributes['borderColor'] = array(
[31] Fix | Delete
'type' => 'string',
[32] Fix | Delete
);
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Adds CSS classes and inline styles for border styles to the incoming
[38] Fix | Delete
* attributes array. This will be applied to the block markup in the front-end.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 5.8.0
[41] Fix | Delete
* @since 6.1.0 Implemented the style engine to generate CSS and classnames.
[42] Fix | Delete
* @access private
[43] Fix | Delete
*
[44] Fix | Delete
* @param WP_Block_Type $block_type Block type.
[45] Fix | Delete
* @param array $block_attributes Block attributes.
[46] Fix | Delete
* @return array Border CSS classes and inline styles.
[47] Fix | Delete
*/
[48] Fix | Delete
function wp_apply_border_support( $block_type, $block_attributes ) {
[49] Fix | Delete
if ( wp_should_skip_block_supports_serialization( $block_type, 'border' ) ) {
[50] Fix | Delete
return array();
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$border_block_styles = array();
[54] Fix | Delete
$has_border_color_support = wp_has_border_feature_support( $block_type, 'color' );
[55] Fix | Delete
$has_border_width_support = wp_has_border_feature_support( $block_type, 'width' );
[56] Fix | Delete
[57] Fix | Delete
// Border radius.
[58] Fix | Delete
if (
[59] Fix | Delete
wp_has_border_feature_support( $block_type, 'radius' ) &&
[60] Fix | Delete
isset( $block_attributes['style']['border']['radius'] ) &&
[61] Fix | Delete
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' )
[62] Fix | Delete
) {
[63] Fix | Delete
$border_radius = $block_attributes['style']['border']['radius'];
[64] Fix | Delete
[65] Fix | Delete
if ( is_numeric( $border_radius ) ) {
[66] Fix | Delete
$border_radius .= 'px';
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
$border_block_styles['radius'] = $border_radius;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
// Border style.
[73] Fix | Delete
if (
[74] Fix | Delete
wp_has_border_feature_support( $block_type, 'style' ) &&
[75] Fix | Delete
isset( $block_attributes['style']['border']['style'] ) &&
[76] Fix | Delete
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' )
[77] Fix | Delete
) {
[78] Fix | Delete
$border_block_styles['style'] = $block_attributes['style']['border']['style'];
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
// Border width.
[82] Fix | Delete
if (
[83] Fix | Delete
$has_border_width_support &&
[84] Fix | Delete
isset( $block_attributes['style']['border']['width'] ) &&
[85] Fix | Delete
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' )
[86] Fix | Delete
) {
[87] Fix | Delete
$border_width = $block_attributes['style']['border']['width'];
[88] Fix | Delete
[89] Fix | Delete
// This check handles original unitless implementation.
[90] Fix | Delete
if ( is_numeric( $border_width ) ) {
[91] Fix | Delete
$border_width .= 'px';
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
$border_block_styles['width'] = $border_width;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// Border color.
[98] Fix | Delete
if (
[99] Fix | Delete
$has_border_color_support &&
[100] Fix | Delete
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' )
[101] Fix | Delete
) {
[102] Fix | Delete
$preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
[103] Fix | Delete
$custom_border_color = isset( $block_attributes['style']['border']['color'] ) ? $block_attributes['style']['border']['color'] : null;
[104] Fix | Delete
$border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
// Generates styles for individual border sides.
[108] Fix | Delete
if ( $has_border_color_support || $has_border_width_support ) {
[109] Fix | Delete
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
[110] Fix | Delete
$border = isset( $block_attributes['style']['border'][ $side ] ) ? $block_attributes['style']['border'][ $side ] : null;
[111] Fix | Delete
$border_side_values = array(
[112] Fix | Delete
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
[113] Fix | Delete
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null,
[114] Fix | Delete
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null,
[115] Fix | Delete
);
[116] Fix | Delete
$border_block_styles[ $side ] = $border_side_values;
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
// Collect classes and styles.
[121] Fix | Delete
$attributes = array();
[122] Fix | Delete
$styles = wp_style_engine_get_styles( array( 'border' => $border_block_styles ) );
[123] Fix | Delete
[124] Fix | Delete
if ( ! empty( $styles['classnames'] ) ) {
[125] Fix | Delete
$attributes['class'] = $styles['classnames'];
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( ! empty( $styles['css'] ) ) {
[129] Fix | Delete
$attributes['style'] = $styles['css'];
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
return $attributes;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Checks whether the current block type supports the border feature requested.
[137] Fix | Delete
*
[138] Fix | Delete
* If the `__experimentalBorder` support flag is a boolean `true` all border
[139] Fix | Delete
* support features are available. Otherwise, the specific feature's support
[140] Fix | Delete
* flag nested under `experimentalBorder` must be enabled for the feature
[141] Fix | Delete
* to be opted into.
[142] Fix | Delete
*
[143] Fix | Delete
* @since 5.8.0
[144] Fix | Delete
* @access private
[145] Fix | Delete
*
[146] Fix | Delete
* @param WP_Block_Type $block_type Block type to check for support.
[147] Fix | Delete
* @param string $feature Name of the feature to check support for.
[148] Fix | Delete
* @param mixed $default_value Fallback value for feature support, defaults to false.
[149] Fix | Delete
* @return bool Whether the feature is supported.
[150] Fix | Delete
*/
[151] Fix | Delete
function wp_has_border_feature_support( $block_type, $feature, $default_value = false ) {
[152] Fix | Delete
// Check if all border support features have been opted into via `"__experimentalBorder": true`.
[153] Fix | Delete
if ( $block_type instanceof WP_Block_Type ) {
[154] Fix | Delete
$block_type_supports_border = isset( $block_type->supports['__experimentalBorder'] )
[155] Fix | Delete
? $block_type->supports['__experimentalBorder']
[156] Fix | Delete
: $default_value;
[157] Fix | Delete
if ( true === $block_type_supports_border ) {
[158] Fix | Delete
return true;
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
// Check if the specific feature has been opted into individually
[163] Fix | Delete
// via nested flag under `__experimentalBorder`.
[164] Fix | Delete
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
// Register the block support.
[168] Fix | Delete
WP_Block_Supports::get_instance()->register(
[169] Fix | Delete
'border',
[170] Fix | Delete
array(
[171] Fix | Delete
'register_attribute' => 'wp_register_border_support',
[172] Fix | Delete
'apply' => 'wp_apply_border_support',
[173] Fix | Delete
)
[174] Fix | Delete
);
[175] Fix | Delete
[176] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function