Edit File by line
/home/zeestwma/richards.../wp-inclu.../block-su...
File: position.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Position block support flag.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 6.2.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Registers the style block attribute for block types that support it.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 6.2.0
[11] Fix | Delete
* @access private
[12] Fix | Delete
*
[13] Fix | Delete
* @param WP_Block_Type $block_type Block Type.
[14] Fix | Delete
*/
[15] Fix | Delete
function wp_register_position_support( $block_type ) {
[16] Fix | Delete
$has_position_support = block_has_support( $block_type, 'position', false );
[17] Fix | Delete
[18] Fix | Delete
// Set up 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 ( $has_position_support && ! 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
[30] Fix | Delete
/**
[31] Fix | Delete
* Renders position styles to the block wrapper.
[32] Fix | Delete
*
[33] Fix | Delete
* @since 6.2.0
[34] Fix | Delete
* @access private
[35] Fix | Delete
*
[36] Fix | Delete
* @param string $block_content Rendered block content.
[37] Fix | Delete
* @param array $block Block object.
[38] Fix | Delete
* @return string Filtered block content.
[39] Fix | Delete
*/
[40] Fix | Delete
function wp_render_position_support( $block_content, $block ) {
[41] Fix | Delete
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
[42] Fix | Delete
$has_position_support = block_has_support( $block_type, 'position', false );
[43] Fix | Delete
[44] Fix | Delete
if (
[45] Fix | Delete
! $has_position_support ||
[46] Fix | Delete
empty( $block['attrs']['style']['position'] )
[47] Fix | Delete
) {
[48] Fix | Delete
return $block_content;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$global_settings = wp_get_global_settings();
[52] Fix | Delete
$theme_has_sticky_support = isset( $global_settings['position']['sticky'] ) ? $global_settings['position']['sticky'] : false;
[53] Fix | Delete
$theme_has_fixed_support = isset( $global_settings['position']['fixed'] ) ? $global_settings['position']['fixed'] : false;
[54] Fix | Delete
[55] Fix | Delete
// Only allow output for position types that the theme supports.
[56] Fix | Delete
$allowed_position_types = array();
[57] Fix | Delete
if ( true === $theme_has_sticky_support ) {
[58] Fix | Delete
$allowed_position_types[] = 'sticky';
[59] Fix | Delete
}
[60] Fix | Delete
if ( true === $theme_has_fixed_support ) {
[61] Fix | Delete
$allowed_position_types[] = 'fixed';
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$style_attribute = isset( $block['attrs']['style'] ) ? $block['attrs']['style'] : null;
[65] Fix | Delete
$class_name = wp_unique_id( 'wp-container-' );
[66] Fix | Delete
$selector = ".$class_name";
[67] Fix | Delete
$position_styles = array();
[68] Fix | Delete
$position_type = isset( $style_attribute['position']['type'] ) ? $style_attribute['position']['type'] : '';
[69] Fix | Delete
$wrapper_classes = array();
[70] Fix | Delete
[71] Fix | Delete
if (
[72] Fix | Delete
in_array( $position_type, $allowed_position_types, true )
[73] Fix | Delete
) {
[74] Fix | Delete
$wrapper_classes[] = $class_name;
[75] Fix | Delete
$wrapper_classes[] = 'is-position-' . $position_type;
[76] Fix | Delete
$sides = array( 'top', 'right', 'bottom', 'left' );
[77] Fix | Delete
[78] Fix | Delete
foreach ( $sides as $side ) {
[79] Fix | Delete
$side_value = isset( $style_attribute['position'][ $side ] ) ? $style_attribute['position'][ $side ] : null;
[80] Fix | Delete
if ( null !== $side_value ) {
[81] Fix | Delete
/*
[82] Fix | Delete
* For fixed or sticky top positions,
[83] Fix | Delete
* ensure the value includes an offset for the logged in admin bar.
[84] Fix | Delete
*/
[85] Fix | Delete
if (
[86] Fix | Delete
'top' === $side &&
[87] Fix | Delete
( 'fixed' === $position_type || 'sticky' === $position_type )
[88] Fix | Delete
) {
[89] Fix | Delete
// Ensure 0 values can be used in `calc()` calculations.
[90] Fix | Delete
if ( '0' === $side_value || 0 === $side_value ) {
[91] Fix | Delete
$side_value = '0px';
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
// Ensure current side value also factors in the height of the logged in admin bar.
[95] Fix | Delete
$side_value = "calc($side_value + var(--wp-admin--admin-bar--position-offset, 0px))";
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$position_styles[] =
[99] Fix | Delete
array(
[100] Fix | Delete
'selector' => $selector,
[101] Fix | Delete
'declarations' => array(
[102] Fix | Delete
$side => $side_value,
[103] Fix | Delete
),
[104] Fix | Delete
);
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$position_styles[] =
[109] Fix | Delete
array(
[110] Fix | Delete
'selector' => $selector,
[111] Fix | Delete
'declarations' => array(
[112] Fix | Delete
'position' => $position_type,
[113] Fix | Delete
'z-index' => '10',
[114] Fix | Delete
),
[115] Fix | Delete
);
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
if ( ! empty( $position_styles ) ) {
[119] Fix | Delete
/*
[120] Fix | Delete
* Add to the style engine store to enqueue and render position styles.
[121] Fix | Delete
*/
[122] Fix | Delete
wp_style_engine_get_stylesheet_from_css_rules(
[123] Fix | Delete
$position_styles,
[124] Fix | Delete
array(
[125] Fix | Delete
'context' => 'block-supports',
[126] Fix | Delete
'prettify' => false,
[127] Fix | Delete
)
[128] Fix | Delete
);
[129] Fix | Delete
[130] Fix | Delete
// Inject class name to block container markup.
[131] Fix | Delete
$content = new WP_HTML_Tag_Processor( $block_content );
[132] Fix | Delete
$content->next_tag();
[133] Fix | Delete
foreach ( $wrapper_classes as $class ) {
[134] Fix | Delete
$content->add_class( $class );
[135] Fix | Delete
}
[136] Fix | Delete
return (string) $content;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
return $block_content;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
// Register the block support.
[143] Fix | Delete
WP_Block_Supports::get_instance()->register(
[144] Fix | Delete
'position',
[145] Fix | Delete
array(
[146] Fix | Delete
'register_attribute' => 'wp_register_position_support',
[147] Fix | Delete
)
[148] Fix | Delete
);
[149] Fix | Delete
add_filter( 'render_block', 'wp_render_position_support', 10, 2 );
[150] Fix | Delete
[151] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function