Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu.../block-su...
File: layout.php
$layout_styles[] = array(
[500] Fix | Delete
'selector' => $selector,
[501] Fix | Delete
'declarations' => array(
[502] Fix | Delete
'grid-template-columns' => 'repeat(auto-fill, minmax(min(' . $minimum_column_width . ', 100%), 1fr))',
[503] Fix | Delete
'container-type' => 'inline-size',
[504] Fix | Delete
),
[505] Fix | Delete
);
[506] Fix | Delete
}
[507] Fix | Delete
[508] Fix | Delete
if ( $has_block_gap_support && isset( $gap_value ) ) {
[509] Fix | Delete
$combined_gap_value = '';
[510] Fix | Delete
$gap_sides = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' );
[511] Fix | Delete
[512] Fix | Delete
foreach ( $gap_sides as $gap_side ) {
[513] Fix | Delete
$process_value = $gap_value;
[514] Fix | Delete
if ( is_array( $gap_value ) ) {
[515] Fix | Delete
$process_value = isset( $gap_value[ $gap_side ] ) ? $gap_value[ $gap_side ] : $fallback_gap_value;
[516] Fix | Delete
}
[517] Fix | Delete
// Get spacing CSS variable from preset value if provided.
[518] Fix | Delete
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
[519] Fix | Delete
$index_to_splice = strrpos( $process_value, '|' ) + 1;
[520] Fix | Delete
$slug = _wp_to_kebab_case( substr( $process_value, $index_to_splice ) );
[521] Fix | Delete
$process_value = "var(--wp--preset--spacing--$slug)";
[522] Fix | Delete
}
[523] Fix | Delete
$combined_gap_value .= "$process_value ";
[524] Fix | Delete
}
[525] Fix | Delete
$gap_value = trim( $combined_gap_value );
[526] Fix | Delete
[527] Fix | Delete
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
[528] Fix | Delete
$layout_styles[] = array(
[529] Fix | Delete
'selector' => $selector,
[530] Fix | Delete
'declarations' => array( 'gap' => $gap_value ),
[531] Fix | Delete
);
[532] Fix | Delete
}
[533] Fix | Delete
}
[534] Fix | Delete
}
[535] Fix | Delete
[536] Fix | Delete
if ( ! empty( $layout_styles ) ) {
[537] Fix | Delete
/*
[538] Fix | Delete
* Add to the style engine store to enqueue and render layout styles.
[539] Fix | Delete
* Return compiled layout styles to retain backwards compatibility.
[540] Fix | Delete
* Since https://github.com/WordPress/gutenberg/pull/42452,
[541] Fix | Delete
* wp_enqueue_block_support_styles is no longer called in this block supports file.
[542] Fix | Delete
*/
[543] Fix | Delete
return wp_style_engine_get_stylesheet_from_css_rules(
[544] Fix | Delete
$layout_styles,
[545] Fix | Delete
array(
[546] Fix | Delete
'context' => 'block-supports',
[547] Fix | Delete
'prettify' => false,
[548] Fix | Delete
)
[549] Fix | Delete
);
[550] Fix | Delete
}
[551] Fix | Delete
[552] Fix | Delete
return '';
[553] Fix | Delete
}
[554] Fix | Delete
[555] Fix | Delete
/**
[556] Fix | Delete
* Renders the layout config to the block wrapper.
[557] Fix | Delete
*
[558] Fix | Delete
* @since 5.8.0
[559] Fix | Delete
* @since 6.3.0 Adds compound class to layout wrapper for global spacing styles.
[560] Fix | Delete
* @since 6.3.0 Check for layout support via the `layout` key with fallback to `__experimentalLayout`.
[561] Fix | Delete
* @since 6.6.0 Removed duplicate container class from layout styles.
[562] Fix | Delete
* @access private
[563] Fix | Delete
*
[564] Fix | Delete
* @param string $block_content Rendered block content.
[565] Fix | Delete
* @param array $block Block object.
[566] Fix | Delete
* @return string Filtered block content.
[567] Fix | Delete
*/
[568] Fix | Delete
function wp_render_layout_support_flag( $block_content, $block ) {
[569] Fix | Delete
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
[570] Fix | Delete
$block_supports_layout = block_has_support( $block_type, 'layout', false ) || block_has_support( $block_type, '__experimentalLayout', false );
[571] Fix | Delete
$child_layout = isset( $block['attrs']['style']['layout'] ) ? $block['attrs']['style']['layout'] : null;
[572] Fix | Delete
[573] Fix | Delete
if ( ! $block_supports_layout && ! $child_layout ) {
[574] Fix | Delete
return $block_content;
[575] Fix | Delete
}
[576] Fix | Delete
[577] Fix | Delete
$outer_class_names = array();
[578] Fix | Delete
[579] Fix | Delete
// Child layout specific logic.
[580] Fix | Delete
if ( $child_layout ) {
[581] Fix | Delete
$container_content_class = wp_unique_prefixed_id( 'wp-container-content-' );
[582] Fix | Delete
$child_layout_declarations = array();
[583] Fix | Delete
$child_layout_styles = array();
[584] Fix | Delete
[585] Fix | Delete
$self_stretch = isset( $child_layout['selfStretch'] ) ? $child_layout['selfStretch'] : null;
[586] Fix | Delete
[587] Fix | Delete
if ( 'fixed' === $self_stretch && isset( $child_layout['flexSize'] ) ) {
[588] Fix | Delete
$child_layout_declarations['flex-basis'] = $child_layout['flexSize'];
[589] Fix | Delete
$child_layout_declarations['box-sizing'] = 'border-box';
[590] Fix | Delete
} elseif ( 'fill' === $self_stretch ) {
[591] Fix | Delete
$child_layout_declarations['flex-grow'] = '1';
[592] Fix | Delete
}
[593] Fix | Delete
[594] Fix | Delete
if ( isset( $child_layout['columnSpan'] ) ) {
[595] Fix | Delete
$column_span = $child_layout['columnSpan'];
[596] Fix | Delete
$child_layout_declarations['grid-column'] = "span $column_span";
[597] Fix | Delete
}
[598] Fix | Delete
if ( isset( $child_layout['rowSpan'] ) ) {
[599] Fix | Delete
$row_span = $child_layout['rowSpan'];
[600] Fix | Delete
$child_layout_declarations['grid-row'] = "span $row_span";
[601] Fix | Delete
}
[602] Fix | Delete
$child_layout_styles[] = array(
[603] Fix | Delete
'selector' => ".$container_content_class",
[604] Fix | Delete
'declarations' => $child_layout_declarations,
[605] Fix | Delete
);
[606] Fix | Delete
[607] Fix | Delete
/*
[608] Fix | Delete
* If columnSpan is set, and the parent grid is responsive, i.e. if it has a minimumColumnWidth set,
[609] Fix | Delete
* the columnSpan should be removed on small grids. If there's a minimumColumnWidth, the grid is responsive.
[610] Fix | Delete
* But if the minimumColumnWidth value wasn't changed, it won't be set. In that case, if columnCount doesn't
[611] Fix | Delete
* exist, we can assume that the grid is responsive.
[612] Fix | Delete
*/
[613] Fix | Delete
if ( isset( $child_layout['columnSpan'] ) && ( isset( $block['parentLayout']['minimumColumnWidth'] ) || ! isset( $block['parentLayout']['columnCount'] ) ) ) {
[614] Fix | Delete
$column_span_number = floatval( $child_layout['columnSpan'] );
[615] Fix | Delete
$parent_column_width = isset( $block['parentLayout']['minimumColumnWidth'] ) ? $block['parentLayout']['minimumColumnWidth'] : '12rem';
[616] Fix | Delete
$parent_column_value = floatval( $parent_column_width );
[617] Fix | Delete
$parent_column_unit = explode( $parent_column_value, $parent_column_width );
[618] Fix | Delete
[619] Fix | Delete
/*
[620] Fix | Delete
* If there is no unit, the width has somehow been mangled so we reset both unit and value
[621] Fix | Delete
* to defaults.
[622] Fix | Delete
* Additionally, the unit should be one of px, rem or em, so that also needs to be checked.
[623] Fix | Delete
*/
[624] Fix | Delete
if ( count( $parent_column_unit ) <= 1 ) {
[625] Fix | Delete
$parent_column_unit = 'rem';
[626] Fix | Delete
$parent_column_value = 12;
[627] Fix | Delete
} else {
[628] Fix | Delete
$parent_column_unit = $parent_column_unit[1];
[629] Fix | Delete
[630] Fix | Delete
if ( ! in_array( $parent_column_unit, array( 'px', 'rem', 'em' ), true ) ) {
[631] Fix | Delete
$parent_column_unit = 'rem';
[632] Fix | Delete
}
[633] Fix | Delete
}
[634] Fix | Delete
[635] Fix | Delete
/*
[636] Fix | Delete
* A default gap value is used for this computation because custom gap values may not be
[637] Fix | Delete
* viable to use in the computation of the container query value.
[638] Fix | Delete
*/
[639] Fix | Delete
$default_gap_value = 'px' === $parent_column_unit ? 24 : 1.5;
[640] Fix | Delete
$container_query_value = $column_span_number * $parent_column_value + ( $column_span_number - 1 ) * $default_gap_value;
[641] Fix | Delete
$container_query_value = $container_query_value . $parent_column_unit;
[642] Fix | Delete
[643] Fix | Delete
$child_layout_styles[] = array(
[644] Fix | Delete
'rules_group' => "@container (max-width: $container_query_value )",
[645] Fix | Delete
'selector' => ".$container_content_class",
[646] Fix | Delete
'declarations' => array(
[647] Fix | Delete
'grid-column' => '1/-1',
[648] Fix | Delete
),
[649] Fix | Delete
);
[650] Fix | Delete
}
[651] Fix | Delete
[652] Fix | Delete
/*
[653] Fix | Delete
* Add to the style engine store to enqueue and render layout styles.
[654] Fix | Delete
* Return styles here just to check if any exist.
[655] Fix | Delete
*/
[656] Fix | Delete
$child_css = wp_style_engine_get_stylesheet_from_css_rules(
[657] Fix | Delete
$child_layout_styles,
[658] Fix | Delete
array(
[659] Fix | Delete
'context' => 'block-supports',
[660] Fix | Delete
'prettify' => false,
[661] Fix | Delete
)
[662] Fix | Delete
);
[663] Fix | Delete
[664] Fix | Delete
if ( $child_css ) {
[665] Fix | Delete
$outer_class_names[] = $container_content_class;
[666] Fix | Delete
}
[667] Fix | Delete
}
[668] Fix | Delete
[669] Fix | Delete
// Prep the processor for modifying the block output.
[670] Fix | Delete
$processor = new WP_HTML_Tag_Processor( $block_content );
[671] Fix | Delete
[672] Fix | Delete
// Having no tags implies there are no tags onto which to add class names.
[673] Fix | Delete
if ( ! $processor->next_tag() ) {
[674] Fix | Delete
return $block_content;
[675] Fix | Delete
}
[676] Fix | Delete
[677] Fix | Delete
/*
[678] Fix | Delete
* A block may not support layout but still be affected by a parent block's layout.
[679] Fix | Delete
*
[680] Fix | Delete
* In these cases add the appropriate class names and then return early; there's
[681] Fix | Delete
* no need to investigate on this block whether additional layout constraints apply.
[682] Fix | Delete
*/
[683] Fix | Delete
if ( ! $block_supports_layout && ! empty( $outer_class_names ) ) {
[684] Fix | Delete
foreach ( $outer_class_names as $class_name ) {
[685] Fix | Delete
$processor->add_class( $class_name );
[686] Fix | Delete
}
[687] Fix | Delete
return $processor->get_updated_html();
[688] Fix | Delete
} elseif ( ! $block_supports_layout ) {
[689] Fix | Delete
// Ensure layout classnames are not injected if there is no layout support.
[690] Fix | Delete
return $block_content;
[691] Fix | Delete
}
[692] Fix | Delete
[693] Fix | Delete
$global_settings = wp_get_global_settings();
[694] Fix | Delete
$fallback_layout = isset( $block_type->supports['layout']['default'] )
[695] Fix | Delete
? $block_type->supports['layout']['default']
[696] Fix | Delete
: array();
[697] Fix | Delete
if ( empty( $fallback_layout ) ) {
[698] Fix | Delete
$fallback_layout = isset( $block_type->supports['__experimentalLayout']['default'] )
[699] Fix | Delete
? $block_type->supports['__experimentalLayout']['default']
[700] Fix | Delete
: array();
[701] Fix | Delete
}
[702] Fix | Delete
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
[703] Fix | Delete
[704] Fix | Delete
$class_names = array();
[705] Fix | Delete
$layout_definitions = wp_get_layout_definitions();
[706] Fix | Delete
[707] Fix | Delete
/*
[708] Fix | Delete
* Uses an incremental ID that is independent per prefix to make sure that
[709] Fix | Delete
* rendering different numbers of blocks doesn't affect the IDs of other
[710] Fix | Delete
* blocks. Makes the CSS class names stable across paginations
[711] Fix | Delete
* for features like the enhanced pagination of the Query block.
[712] Fix | Delete
*/
[713] Fix | Delete
$container_class = wp_unique_prefixed_id(
[714] Fix | Delete
'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-'
[715] Fix | Delete
);
[716] Fix | Delete
[717] Fix | Delete
// Set the correct layout type for blocks using legacy content width.
[718] Fix | Delete
if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) {
[719] Fix | Delete
$used_layout['type'] = 'constrained';
[720] Fix | Delete
}
[721] Fix | Delete
[722] Fix | Delete
$root_padding_aware_alignments = isset( $global_settings['useRootPaddingAwareAlignments'] )
[723] Fix | Delete
? $global_settings['useRootPaddingAwareAlignments']
[724] Fix | Delete
: false;
[725] Fix | Delete
[726] Fix | Delete
if (
[727] Fix | Delete
$root_padding_aware_alignments &&
[728] Fix | Delete
isset( $used_layout['type'] ) &&
[729] Fix | Delete
'constrained' === $used_layout['type']
[730] Fix | Delete
) {
[731] Fix | Delete
$class_names[] = 'has-global-padding';
[732] Fix | Delete
}
[733] Fix | Delete
[734] Fix | Delete
/*
[735] Fix | Delete
* The following section was added to reintroduce a small set of layout classnames that were
[736] Fix | Delete
* removed in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719). It is
[737] Fix | Delete
* not intended to provide an extended set of classes to match all block layout attributes
[738] Fix | Delete
* here.
[739] Fix | Delete
*/
[740] Fix | Delete
if ( ! empty( $block['attrs']['layout']['orientation'] ) ) {
[741] Fix | Delete
$class_names[] = 'is-' . sanitize_title( $block['attrs']['layout']['orientation'] );
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
if ( ! empty( $block['attrs']['layout']['justifyContent'] ) ) {
[745] Fix | Delete
$class_names[] = 'is-content-justification-' . sanitize_title( $block['attrs']['layout']['justifyContent'] );
[746] Fix | Delete
}
[747] Fix | Delete
[748] Fix | Delete
if ( ! empty( $block['attrs']['layout']['flexWrap'] ) && 'nowrap' === $block['attrs']['layout']['flexWrap'] ) {
[749] Fix | Delete
$class_names[] = 'is-nowrap';
[750] Fix | Delete
}
[751] Fix | Delete
[752] Fix | Delete
// Get classname for layout type.
[753] Fix | Delete
if ( isset( $used_layout['type'] ) ) {
[754] Fix | Delete
$layout_classname = isset( $layout_definitions[ $used_layout['type'] ]['className'] )
[755] Fix | Delete
? $layout_definitions[ $used_layout['type'] ]['className']
[756] Fix | Delete
: '';
[757] Fix | Delete
} else {
[758] Fix | Delete
$layout_classname = isset( $layout_definitions['default']['className'] )
[759] Fix | Delete
? $layout_definitions['default']['className']
[760] Fix | Delete
: '';
[761] Fix | Delete
}
[762] Fix | Delete
[763] Fix | Delete
if ( $layout_classname && is_string( $layout_classname ) ) {
[764] Fix | Delete
$class_names[] = sanitize_title( $layout_classname );
[765] Fix | Delete
}
[766] Fix | Delete
[767] Fix | Delete
/*
[768] Fix | Delete
* Only generate Layout styles if the theme has not opted-out.
[769] Fix | Delete
* Attribute-based Layout classnames are output in all cases.
[770] Fix | Delete
*/
[771] Fix | Delete
if ( ! current_theme_supports( 'disable-layout-styles' ) ) {
[772] Fix | Delete
[773] Fix | Delete
$gap_value = isset( $block['attrs']['style']['spacing']['blockGap'] )
[774] Fix | Delete
? $block['attrs']['style']['spacing']['blockGap']
[775] Fix | Delete
: null;
[776] Fix | Delete
/*
[777] Fix | Delete
* Skip if gap value contains unsupported characters.
[778] Fix | Delete
* Regex for CSS value borrowed from `safecss_filter_attr`, and used here
[779] Fix | Delete
* to only match against the value, not the CSS attribute.
[780] Fix | Delete
*/
[781] Fix | Delete
if ( is_array( $gap_value ) ) {
[782] Fix | Delete
foreach ( $gap_value as $key => $value ) {
[783] Fix | Delete
$gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
[784] Fix | Delete
}
[785] Fix | Delete
} else {
[786] Fix | Delete
$gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
[787] Fix | Delete
}
[788] Fix | Delete
[789] Fix | Delete
$fallback_gap_value = isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
[790] Fix | Delete
? $block_type->supports['spacing']['blockGap']['__experimentalDefault']
[791] Fix | Delete
: '0.5em';
[792] Fix | Delete
$block_spacing = isset( $block['attrs']['style']['spacing'] )
[793] Fix | Delete
? $block['attrs']['style']['spacing']
[794] Fix | Delete
: null;
[795] Fix | Delete
[796] Fix | Delete
/*
[797] Fix | Delete
* If a block's block.json skips serialization for spacing or spacing.blockGap,
[798] Fix | Delete
* don't apply the user-defined value to the styles.
[799] Fix | Delete
*/
[800] Fix | Delete
$should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
[801] Fix | Delete
[802] Fix | Delete
$block_gap = isset( $global_settings['spacing']['blockGap'] )
[803] Fix | Delete
? $global_settings['spacing']['blockGap']
[804] Fix | Delete
: null;
[805] Fix | Delete
$has_block_gap_support = isset( $block_gap );
[806] Fix | Delete
[807] Fix | Delete
$style = wp_get_layout_style(
[808] Fix | Delete
".$container_class",
[809] Fix | Delete
$used_layout,
[810] Fix | Delete
$has_block_gap_support,
[811] Fix | Delete
$gap_value,
[812] Fix | Delete
$should_skip_gap_serialization,
[813] Fix | Delete
$fallback_gap_value,
[814] Fix | Delete
$block_spacing
[815] Fix | Delete
);
[816] Fix | Delete
[817] Fix | Delete
// Only add container class and enqueue block support styles if unique styles were generated.
[818] Fix | Delete
if ( ! empty( $style ) ) {
[819] Fix | Delete
$class_names[] = $container_class;
[820] Fix | Delete
}
[821] Fix | Delete
}
[822] Fix | Delete
[823] Fix | Delete
// Add combined layout and block classname for global styles to hook onto.
[824] Fix | Delete
$block_name = explode( '/', $block['blockName'] );
[825] Fix | Delete
$class_names[] = 'wp-block-' . end( $block_name ) . '-' . $layout_classname;
[826] Fix | Delete
[827] Fix | Delete
// Add classes to the outermost HTML tag if necessary.
[828] Fix | Delete
if ( ! empty( $outer_class_names ) ) {
[829] Fix | Delete
foreach ( $outer_class_names as $outer_class_name ) {
[830] Fix | Delete
$processor->add_class( $outer_class_name );
[831] Fix | Delete
}
[832] Fix | Delete
}
[833] Fix | Delete
[834] Fix | Delete
/**
[835] Fix | Delete
* Attempts to refer to the inner-block wrapping element by its class attribute.
[836] Fix | Delete
*
[837] Fix | Delete
* When examining a block's inner content, if a block has inner blocks, then
[838] Fix | Delete
* the first content item will likely be a text (HTML) chunk immediately
[839] Fix | Delete
* preceding the inner blocks. The last HTML tag in that chunk would then be
[840] Fix | Delete
* an opening tag for an element that wraps the inner blocks.
[841] Fix | Delete
*
[842] Fix | Delete
* There's no reliable way to associate this wrapper in $block_content because
[843] Fix | Delete
* it may have changed during the rendering pipeline (as inner contents is
[844] Fix | Delete
* provided before rendering) and through previous filters. In many cases,
[845] Fix | Delete
* however, the `class` attribute will be a good-enough identifier, so this
[846] Fix | Delete
* code finds the last tag in that chunk and stores the `class` attribute
[847] Fix | Delete
* so that it can be used later when working through the rendered block output
[848] Fix | Delete
* to identify the wrapping element and add the remaining class names to it.
[849] Fix | Delete
*
[850] Fix | Delete
* It's also possible that no inner block wrapper even exists. If that's the
[851] Fix | Delete
* case this code could apply the class names to an invalid element.
[852] Fix | Delete
*
[853] Fix | Delete
* Example:
[854] Fix | Delete
*
[855] Fix | Delete
* $block['innerBlocks'] = array( $list_item );
[856] Fix | Delete
* $block['innerContent'] = array( '<ul class="list-wrapper is-unordered">', null, '</ul>' );
[857] Fix | Delete
*
[858] Fix | Delete
* // After rendering, the initial contents may have been modified by other renderers or filters.
[859] Fix | Delete
* $block_content = <<<HTML
[860] Fix | Delete
* <figure>
[861] Fix | Delete
* <ul class="annotated-list list-wrapper is-unordered">
[862] Fix | Delete
* <li>Code</li>
[863] Fix | Delete
* </ul><figcaption>It's a list!</figcaption>
[864] Fix | Delete
* </figure>
[865] Fix | Delete
* HTML;
[866] Fix | Delete
*
[867] Fix | Delete
* Although it is possible that the original block-wrapper classes are changed in $block_content
[868] Fix | Delete
* from how they appear in $block['innerContent'], it's likely that the original class attributes
[869] Fix | Delete
* are still present in the wrapper as they are in this example. Frequently, additional classes
[870] Fix | Delete
* will also be present; rarely should classes be removed.
[871] Fix | Delete
*
[872] Fix | Delete
* @todo Find a better way to match the first inner block. If it's possible to identify where the
[873] Fix | Delete
* first inner block starts, then it will be possible to find the last tag before it starts
[874] Fix | Delete
* and then that tag, if an opening tag, can be solidly identified as a wrapping element.
[875] Fix | Delete
* Can some unique value or class or ID be added to the inner blocks when they process
[876] Fix | Delete
* so that they can be extracted here safely without guessing? Can the block rendering function
[877] Fix | Delete
* return information about where the rendered inner blocks start?
[878] Fix | Delete
*
[879] Fix | Delete
* @var string|null
[880] Fix | Delete
*/
[881] Fix | Delete
$inner_block_wrapper_classes = null;
[882] Fix | Delete
$first_chunk = isset( $block['innerContent'][0] ) ? $block['innerContent'][0] : null;
[883] Fix | Delete
if ( is_string( $first_chunk ) && count( $block['innerContent'] ) > 1 ) {
[884] Fix | Delete
$first_chunk_processor = new WP_HTML_Tag_Processor( $first_chunk );
[885] Fix | Delete
while ( $first_chunk_processor->next_tag() ) {
[886] Fix | Delete
$class_attribute = $first_chunk_processor->get_attribute( 'class' );
[887] Fix | Delete
if ( is_string( $class_attribute ) && ! empty( $class_attribute ) ) {
[888] Fix | Delete
$inner_block_wrapper_classes = $class_attribute;
[889] Fix | Delete
}
[890] Fix | Delete
}
[891] Fix | Delete
}
[892] Fix | Delete
[893] Fix | Delete
/*
[894] Fix | Delete
* If necessary, advance to what is likely to be an inner block wrapper tag.
[895] Fix | Delete
*
[896] Fix | Delete
* This advances until it finds the first tag containing the original class
[897] Fix | Delete
* attribute from above. If none is found it will scan to the end of the block
[898] Fix | Delete
* and fail to add any class names.
[899] Fix | Delete
*
[900] Fix | Delete
* If there is no block wrapper it won't advance at all, in which case the
[901] Fix | Delete
* class names will be added to the first and outermost tag of the block.
[902] Fix | Delete
* For cases where this outermost tag is the only tag surrounding inner
[903] Fix | Delete
* blocks then the outer wrapper and inner wrapper are the same.
[904] Fix | Delete
*/
[905] Fix | Delete
do {
[906] Fix | Delete
if ( ! $inner_block_wrapper_classes ) {
[907] Fix | Delete
break;
[908] Fix | Delete
}
[909] Fix | Delete
[910] Fix | Delete
$class_attribute = $processor->get_attribute( 'class' );
[911] Fix | Delete
if ( is_string( $class_attribute ) && str_contains( $class_attribute, $inner_block_wrapper_classes ) ) {
[912] Fix | Delete
break;
[913] Fix | Delete
}
[914] Fix | Delete
} while ( $processor->next_tag() );
[915] Fix | Delete
[916] Fix | Delete
// Add the remaining class names.
[917] Fix | Delete
foreach ( $class_names as $class_name ) {
[918] Fix | Delete
$processor->add_class( $class_name );
[919] Fix | Delete
}
[920] Fix | Delete
[921] Fix | Delete
return $processor->get_updated_html();
[922] Fix | Delete
}
[923] Fix | Delete
[924] Fix | Delete
/**
[925] Fix | Delete
* Check if the parent block exists and if it has a layout attribute.
[926] Fix | Delete
* If it does, add the parent layout to the parsed block
[927] Fix | Delete
*
[928] Fix | Delete
* @since 6.6.0
[929] Fix | Delete
* @access private
[930] Fix | Delete
*
[931] Fix | Delete
* @param array $parsed_block The parsed block.
[932] Fix | Delete
* @param array $source_block The source block.
[933] Fix | Delete
* @param WP_Block $parent_block The parent block.
[934] Fix | Delete
* @return array The parsed block with parent layout attribute if it exists.
[935] Fix | Delete
*/
[936] Fix | Delete
function wp_add_parent_layout_to_parsed_block( $parsed_block, $source_block, $parent_block ) {
[937] Fix | Delete
if ( $parent_block && isset( $parent_block->parsed_block['attrs']['layout'] ) ) {
[938] Fix | Delete
$parsed_block['parentLayout'] = $parent_block->parsed_block['attrs']['layout'];
[939] Fix | Delete
}
[940] Fix | Delete
return $parsed_block;
[941] Fix | Delete
}
[942] Fix | Delete
[943] Fix | Delete
add_filter( 'render_block_data', 'wp_add_parent_layout_to_parsed_block', 10, 3 );
[944] Fix | Delete
[945] Fix | Delete
// Register the block support.
[946] Fix | Delete
WP_Block_Supports::get_instance()->register(
[947] Fix | Delete
'layout',
[948] Fix | Delete
array(
[949] Fix | Delete
'register_attribute' => 'wp_register_layout_support',
[950] Fix | Delete
)
[951] Fix | Delete
);
[952] Fix | Delete
add_filter( 'render_block', 'wp_render_layout_support_flag', 10, 2 );
[953] Fix | Delete
[954] Fix | Delete
/**
[955] Fix | Delete
* For themes without theme.json file, make sure
[956] Fix | Delete
* to restore the inner div for the group block
[957] Fix | Delete
* to avoid breaking styles relying on that div.
[958] Fix | Delete
*
[959] Fix | Delete
* @since 5.8.0
[960] Fix | Delete
* @access private
[961] Fix | Delete
*
[962] Fix | Delete
* @param string $block_content Rendered block content.
[963] Fix | Delete
* @param array $block Block object.
[964] Fix | Delete
* @return string Filtered block content.
[965] Fix | Delete
*/
[966] Fix | Delete
function wp_restore_group_inner_container( $block_content, $block ) {
[967] Fix | Delete
$tag_name = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : 'div';
[968] Fix | Delete
$group_with_inner_container_regex = sprintf(
[969] Fix | Delete
'/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U',
[970] Fix | Delete
preg_quote( $tag_name, '/' )
[971] Fix | Delete
);
[972] Fix | Delete
[973] Fix | Delete
if (
[974] Fix | Delete
wp_theme_has_theme_json() ||
[975] Fix | Delete
1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
[976] Fix | Delete
( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] )
[977] Fix | Delete
) {
[978] Fix | Delete
return $block_content;
[979] Fix | Delete
}
[980] Fix | Delete
[981] Fix | Delete
/*
[982] Fix | Delete
* This filter runs after the layout classnames have been added to the block, so they
[983] Fix | Delete
* have to be removed from the outer wrapper and then added to the inner.
[984] Fix | Delete
*/
[985] Fix | Delete
$layout_classes = array();
[986] Fix | Delete
$processor = new WP_HTML_Tag_Processor( $block_content );
[987] Fix | Delete
[988] Fix | Delete
if ( $processor->next_tag( array( 'class_name' => 'wp-block-group' ) ) ) {
[989] Fix | Delete
foreach ( $processor->class_list() as $class_name ) {
[990] Fix | Delete
if ( str_contains( $class_name, 'is-layout-' ) ) {
[991] Fix | Delete
$layout_classes[] = $class_name;
[992] Fix | Delete
$processor->remove_class( $class_name );
[993] Fix | Delete
}
[994] Fix | Delete
}
[995] Fix | Delete
}
[996] Fix | Delete
[997] Fix | Delete
$content_without_layout_classes = $processor->get_updated_html();
[998] Fix | Delete
$replace_regex = sprintf(
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function