Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: class-wp-block.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Blocks API: WP_Block class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.5.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class representing a parsed instance of a block.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 5.5.0
[11] Fix | Delete
* @property array $attributes
[12] Fix | Delete
*/
[13] Fix | Delete
#[AllowDynamicProperties]
[14] Fix | Delete
class WP_Block {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Original parsed array representation of block.
[18] Fix | Delete
*
[19] Fix | Delete
* @since 5.5.0
[20] Fix | Delete
* @var array
[21] Fix | Delete
*/
[22] Fix | Delete
public $parsed_block;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Name of block.
[26] Fix | Delete
*
[27] Fix | Delete
* @example "core/paragraph"
[28] Fix | Delete
*
[29] Fix | Delete
* @since 5.5.0
[30] Fix | Delete
* @var string
[31] Fix | Delete
*/
[32] Fix | Delete
public $name;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Block type associated with the instance.
[36] Fix | Delete
*
[37] Fix | Delete
* @since 5.5.0
[38] Fix | Delete
* @var WP_Block_Type
[39] Fix | Delete
*/
[40] Fix | Delete
public $block_type;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Block context values.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 5.5.0
[46] Fix | Delete
* @var array
[47] Fix | Delete
*/
[48] Fix | Delete
public $context = array();
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* All available context of the current hierarchy.
[52] Fix | Delete
*
[53] Fix | Delete
* @since 5.5.0
[54] Fix | Delete
* @var array
[55] Fix | Delete
* @access protected
[56] Fix | Delete
*/
[57] Fix | Delete
protected $available_context;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Block type registry.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 5.9.0
[63] Fix | Delete
* @var WP_Block_Type_Registry
[64] Fix | Delete
* @access protected
[65] Fix | Delete
*/
[66] Fix | Delete
protected $registry;
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* List of inner blocks (of this same class)
[70] Fix | Delete
*
[71] Fix | Delete
* @since 5.5.0
[72] Fix | Delete
* @var WP_Block_List
[73] Fix | Delete
*/
[74] Fix | Delete
public $inner_blocks = array();
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Resultant HTML from inside block comment delimiters after removing inner
[78] Fix | Delete
* blocks.
[79] Fix | Delete
*
[80] Fix | Delete
* @example "...Just <!-- wp:test /--> testing..." -> "Just testing..."
[81] Fix | Delete
*
[82] Fix | Delete
* @since 5.5.0
[83] Fix | Delete
* @var string
[84] Fix | Delete
*/
[85] Fix | Delete
public $inner_html = '';
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* List of string fragments and null markers where inner blocks were found
[89] Fix | Delete
*
[90] Fix | Delete
* @example array(
[91] Fix | Delete
* 'inner_html' => 'BeforeInnerAfter',
[92] Fix | Delete
* 'inner_blocks' => array( block, block ),
[93] Fix | Delete
* 'inner_content' => array( 'Before', null, 'Inner', null, 'After' ),
[94] Fix | Delete
* )
[95] Fix | Delete
*
[96] Fix | Delete
* @since 5.5.0
[97] Fix | Delete
* @var array
[98] Fix | Delete
*/
[99] Fix | Delete
public $inner_content = array();
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Constructor.
[103] Fix | Delete
*
[104] Fix | Delete
* Populates object properties from the provided block instance argument.
[105] Fix | Delete
*
[106] Fix | Delete
* The given array of context values will not necessarily be available on
[107] Fix | Delete
* the instance itself, but is treated as the full set of values provided by
[108] Fix | Delete
* the block's ancestry. This is assigned to the private `available_context`
[109] Fix | Delete
* property. Only values which are configured to consumed by the block via
[110] Fix | Delete
* its registered type will be assigned to the block's `context` property.
[111] Fix | Delete
*
[112] Fix | Delete
* @since 5.5.0
[113] Fix | Delete
*
[114] Fix | Delete
* @param array $block {
[115] Fix | Delete
* A representative array of a single parsed block object. See WP_Block_Parser_Block.
[116] Fix | Delete
*
[117] Fix | Delete
* @type string $blockName Name of block.
[118] Fix | Delete
* @type array $attrs Attributes from block comment delimiters.
[119] Fix | Delete
* @type array $innerBlocks List of inner blocks. An array of arrays that
[120] Fix | Delete
* have the same structure as this one.
[121] Fix | Delete
* @type string $innerHTML HTML from inside block comment delimiters.
[122] Fix | Delete
* @type array $innerContent List of string fragments and null markers where inner blocks were found.
[123] Fix | Delete
* }
[124] Fix | Delete
* @param array $available_context Optional array of ancestry context values.
[125] Fix | Delete
* @param WP_Block_Type_Registry $registry Optional block type registry.
[126] Fix | Delete
*/
[127] Fix | Delete
public function __construct( $block, $available_context = array(), $registry = null ) {
[128] Fix | Delete
$this->parsed_block = $block;
[129] Fix | Delete
$this->name = $block['blockName'];
[130] Fix | Delete
[131] Fix | Delete
if ( is_null( $registry ) ) {
[132] Fix | Delete
$registry = WP_Block_Type_Registry::get_instance();
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
$this->registry = $registry;
[136] Fix | Delete
[137] Fix | Delete
$this->block_type = $registry->get_registered( $this->name );
[138] Fix | Delete
[139] Fix | Delete
$this->available_context = $available_context;
[140] Fix | Delete
[141] Fix | Delete
if ( ! empty( $this->block_type->uses_context ) ) {
[142] Fix | Delete
foreach ( $this->block_type->uses_context as $context_name ) {
[143] Fix | Delete
if ( array_key_exists( $context_name, $this->available_context ) ) {
[144] Fix | Delete
$this->context[ $context_name ] = $this->available_context[ $context_name ];
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
if ( ! empty( $block['innerBlocks'] ) ) {
[150] Fix | Delete
$child_context = $this->available_context;
[151] Fix | Delete
[152] Fix | Delete
if ( ! empty( $this->block_type->provides_context ) ) {
[153] Fix | Delete
foreach ( $this->block_type->provides_context as $context_name => $attribute_name ) {
[154] Fix | Delete
if ( array_key_exists( $attribute_name, $this->attributes ) ) {
[155] Fix | Delete
$child_context[ $context_name ] = $this->attributes[ $attribute_name ];
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$this->inner_blocks = new WP_Block_List( $block['innerBlocks'], $child_context, $registry );
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
if ( ! empty( $block['innerHTML'] ) ) {
[164] Fix | Delete
$this->inner_html = $block['innerHTML'];
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
if ( ! empty( $block['innerContent'] ) ) {
[168] Fix | Delete
$this->inner_content = $block['innerContent'];
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Returns a value from an inaccessible property.
[174] Fix | Delete
*
[175] Fix | Delete
* This is used to lazily initialize the `attributes` property of a block,
[176] Fix | Delete
* such that it is only prepared with default attributes at the time that
[177] Fix | Delete
* the property is accessed. For all other inaccessible properties, a `null`
[178] Fix | Delete
* value is returned.
[179] Fix | Delete
*
[180] Fix | Delete
* @since 5.5.0
[181] Fix | Delete
*
[182] Fix | Delete
* @param string $name Property name.
[183] Fix | Delete
* @return array|null Prepared attributes, or null.
[184] Fix | Delete
*/
[185] Fix | Delete
public function __get( $name ) {
[186] Fix | Delete
if ( 'attributes' === $name ) {
[187] Fix | Delete
$this->attributes = isset( $this->parsed_block['attrs'] ) ?
[188] Fix | Delete
$this->parsed_block['attrs'] :
[189] Fix | Delete
array();
[190] Fix | Delete
[191] Fix | Delete
if ( ! is_null( $this->block_type ) ) {
[192] Fix | Delete
$this->attributes = $this->block_type->prepare_attributes_for_render( $this->attributes );
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
return $this->attributes;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
return null;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Processes the block bindings and updates the block attributes with the values from the sources.
[203] Fix | Delete
*
[204] Fix | Delete
* A block might contain bindings in its attributes. Bindings are mappings
[205] Fix | Delete
* between an attribute of the block and a source. A "source" is a function
[206] Fix | Delete
* registered with `register_block_bindings_source()` that defines how to
[207] Fix | Delete
* retrieve a value from outside the block, e.g. from post meta.
[208] Fix | Delete
*
[209] Fix | Delete
* This function will process those bindings and update the block's attributes
[210] Fix | Delete
* with the values coming from the bindings.
[211] Fix | Delete
*
[212] Fix | Delete
* ### Example
[213] Fix | Delete
*
[214] Fix | Delete
* The "bindings" property for an Image block might look like this:
[215] Fix | Delete
*
[216] Fix | Delete
* ```json
[217] Fix | Delete
* {
[218] Fix | Delete
* "metadata": {
[219] Fix | Delete
* "bindings": {
[220] Fix | Delete
* "title": {
[221] Fix | Delete
* "source": "core/post-meta",
[222] Fix | Delete
* "args": { "key": "text_custom_field" }
[223] Fix | Delete
* },
[224] Fix | Delete
* "url": {
[225] Fix | Delete
* "source": "core/post-meta",
[226] Fix | Delete
* "args": { "key": "url_custom_field" }
[227] Fix | Delete
* }
[228] Fix | Delete
* }
[229] Fix | Delete
* }
[230] Fix | Delete
* }
[231] Fix | Delete
* ```
[232] Fix | Delete
*
[233] Fix | Delete
* The above example will replace the `title` and `url` attributes of the Image
[234] Fix | Delete
* block with the values of the `text_custom_field` and `url_custom_field` post meta.
[235] Fix | Delete
*
[236] Fix | Delete
* @since 6.5.0
[237] Fix | Delete
* @since 6.6.0 Handle the `__default` attribute for pattern overrides.
[238] Fix | Delete
*
[239] Fix | Delete
* @return array The computed block attributes for the provided block bindings.
[240] Fix | Delete
*/
[241] Fix | Delete
private function process_block_bindings() {
[242] Fix | Delete
$parsed_block = $this->parsed_block;
[243] Fix | Delete
$computed_attributes = array();
[244] Fix | Delete
$supported_block_attributes = array(
[245] Fix | Delete
'core/paragraph' => array( 'content' ),
[246] Fix | Delete
'core/heading' => array( 'content' ),
[247] Fix | Delete
'core/image' => array( 'id', 'url', 'title', 'alt' ),
[248] Fix | Delete
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
[249] Fix | Delete
);
[250] Fix | Delete
[251] Fix | Delete
// If the block doesn't have the bindings property, isn't one of the supported
[252] Fix | Delete
// block types, or the bindings property is not an array, return the block content.
[253] Fix | Delete
if (
[254] Fix | Delete
! isset( $supported_block_attributes[ $this->name ] ) ||
[255] Fix | Delete
empty( $parsed_block['attrs']['metadata']['bindings'] ) ||
[256] Fix | Delete
! is_array( $parsed_block['attrs']['metadata']['bindings'] )
[257] Fix | Delete
) {
[258] Fix | Delete
return $computed_attributes;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
$bindings = $parsed_block['attrs']['metadata']['bindings'];
[262] Fix | Delete
[263] Fix | Delete
/*
[264] Fix | Delete
* If the default binding is set for pattern overrides, replace it
[265] Fix | Delete
* with a pattern override binding for all supported attributes.
[266] Fix | Delete
*/
[267] Fix | Delete
if (
[268] Fix | Delete
isset( $bindings['__default']['source'] ) &&
[269] Fix | Delete
'core/pattern-overrides' === $bindings['__default']['source']
[270] Fix | Delete
) {
[271] Fix | Delete
$updated_bindings = array();
[272] Fix | Delete
[273] Fix | Delete
/*
[274] Fix | Delete
* Build a binding array of all supported attributes.
[275] Fix | Delete
* Note that this also omits the `__default` attribute from the
[276] Fix | Delete
* resulting array.
[277] Fix | Delete
*/
[278] Fix | Delete
foreach ( $supported_block_attributes[ $parsed_block['blockName'] ] as $attribute_name ) {
[279] Fix | Delete
// Retain any non-pattern override bindings that might be present.
[280] Fix | Delete
$updated_bindings[ $attribute_name ] = isset( $bindings[ $attribute_name ] )
[281] Fix | Delete
? $bindings[ $attribute_name ]
[282] Fix | Delete
: array( 'source' => 'core/pattern-overrides' );
[283] Fix | Delete
}
[284] Fix | Delete
$bindings = $updated_bindings;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
foreach ( $bindings as $attribute_name => $block_binding ) {
[288] Fix | Delete
// If the attribute is not in the supported list, process next attribute.
[289] Fix | Delete
if ( ! in_array( $attribute_name, $supported_block_attributes[ $this->name ], true ) ) {
[290] Fix | Delete
continue;
[291] Fix | Delete
}
[292] Fix | Delete
// If no source is provided, or that source is not registered, process next attribute.
[293] Fix | Delete
if ( ! isset( $block_binding['source'] ) || ! is_string( $block_binding['source'] ) ) {
[294] Fix | Delete
continue;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
$block_binding_source = get_block_bindings_source( $block_binding['source'] );
[298] Fix | Delete
if ( null === $block_binding_source ) {
[299] Fix | Delete
continue;
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
$source_args = ! empty( $block_binding['args'] ) && is_array( $block_binding['args'] ) ? $block_binding['args'] : array();
[303] Fix | Delete
$source_value = $block_binding_source->get_value( $source_args, $this, $attribute_name );
[304] Fix | Delete
[305] Fix | Delete
// If the value is not null, process the HTML based on the block and the attribute.
[306] Fix | Delete
if ( ! is_null( $source_value ) ) {
[307] Fix | Delete
$computed_attributes[ $attribute_name ] = $source_value;
[308] Fix | Delete
}
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
return $computed_attributes;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Depending on the block attribute name, replace its value in the HTML based on the value provided.
[316] Fix | Delete
*
[317] Fix | Delete
* @since 6.5.0
[318] Fix | Delete
*
[319] Fix | Delete
* @param string $block_content Block content.
[320] Fix | Delete
* @param string $attribute_name The attribute name to replace.
[321] Fix | Delete
* @param mixed $source_value The value used to replace in the HTML.
[322] Fix | Delete
* @return string The modified block content.
[323] Fix | Delete
*/
[324] Fix | Delete
private function replace_html( string $block_content, string $attribute_name, $source_value ) {
[325] Fix | Delete
$block_type = $this->block_type;
[326] Fix | Delete
if ( ! isset( $block_type->attributes[ $attribute_name ]['source'] ) ) {
[327] Fix | Delete
return $block_content;
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
// Depending on the attribute source, the processing will be different.
[331] Fix | Delete
switch ( $block_type->attributes[ $attribute_name ]['source'] ) {
[332] Fix | Delete
case 'html':
[333] Fix | Delete
case 'rich-text':
[334] Fix | Delete
$block_reader = new WP_HTML_Tag_Processor( $block_content );
[335] Fix | Delete
[336] Fix | Delete
// TODO: Support for CSS selectors whenever they are ready in the HTML API.
[337] Fix | Delete
// In the meantime, support comma-separated selectors by exploding them into an array.
[338] Fix | Delete
$selectors = explode( ',', $block_type->attributes[ $attribute_name ]['selector'] );
[339] Fix | Delete
// Add a bookmark to the first tag to be able to iterate over the selectors.
[340] Fix | Delete
$block_reader->next_tag();
[341] Fix | Delete
$block_reader->set_bookmark( 'iterate-selectors' );
[342] Fix | Delete
[343] Fix | Delete
// TODO: This shouldn't be needed when the `set_inner_html` function is ready.
[344] Fix | Delete
// Store the parent tag and its attributes to be able to restore them later in the button.
[345] Fix | Delete
// The button block has a wrapper while the paragraph and heading blocks don't.
[346] Fix | Delete
if ( 'core/button' === $this->name ) {
[347] Fix | Delete
$button_wrapper = $block_reader->get_tag();
[348] Fix | Delete
$button_wrapper_attribute_names = $block_reader->get_attribute_names_with_prefix( '' );
[349] Fix | Delete
$button_wrapper_attrs = array();
[350] Fix | Delete
foreach ( $button_wrapper_attribute_names as $name ) {
[351] Fix | Delete
$button_wrapper_attrs[ $name ] = $block_reader->get_attribute( $name );
[352] Fix | Delete
}
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
foreach ( $selectors as $selector ) {
[356] Fix | Delete
// If the parent tag, or any of its children, matches the selector, replace the HTML.
[357] Fix | Delete
if ( strcasecmp( $block_reader->get_tag( $selector ), $selector ) === 0 || $block_reader->next_tag(
[358] Fix | Delete
array(
[359] Fix | Delete
'tag_name' => $selector,
[360] Fix | Delete
)
[361] Fix | Delete
) ) {
[362] Fix | Delete
$block_reader->release_bookmark( 'iterate-selectors' );
[363] Fix | Delete
[364] Fix | Delete
// TODO: Use `set_inner_html` method whenever it's ready in the HTML API.
[365] Fix | Delete
// Until then, it is hardcoded for the paragraph, heading, and button blocks.
[366] Fix | Delete
// Store the tag and its attributes to be able to restore them later.
[367] Fix | Delete
$selector_attribute_names = $block_reader->get_attribute_names_with_prefix( '' );
[368] Fix | Delete
$selector_attrs = array();
[369] Fix | Delete
foreach ( $selector_attribute_names as $name ) {
[370] Fix | Delete
$selector_attrs[ $name ] = $block_reader->get_attribute( $name );
[371] Fix | Delete
}
[372] Fix | Delete
$selector_markup = "<$selector>" . wp_kses_post( $source_value ) . "</$selector>";
[373] Fix | Delete
$amended_content = new WP_HTML_Tag_Processor( $selector_markup );
[374] Fix | Delete
$amended_content->next_tag();
[375] Fix | Delete
foreach ( $selector_attrs as $attribute_key => $attribute_value ) {
[376] Fix | Delete
$amended_content->set_attribute( $attribute_key, $attribute_value );
[377] Fix | Delete
}
[378] Fix | Delete
if ( 'core/paragraph' === $this->name || 'core/heading' === $this->name ) {
[379] Fix | Delete
return $amended_content->get_updated_html();
[380] Fix | Delete
}
[381] Fix | Delete
if ( 'core/button' === $this->name ) {
[382] Fix | Delete
$button_markup = "<$button_wrapper>{$amended_content->get_updated_html()}</$button_wrapper>";
[383] Fix | Delete
$amended_button = new WP_HTML_Tag_Processor( $button_markup );
[384] Fix | Delete
$amended_button->next_tag();
[385] Fix | Delete
foreach ( $button_wrapper_attrs as $attribute_key => $attribute_value ) {
[386] Fix | Delete
$amended_button->set_attribute( $attribute_key, $attribute_value );
[387] Fix | Delete
}
[388] Fix | Delete
return $amended_button->get_updated_html();
[389] Fix | Delete
}
[390] Fix | Delete
} else {
[391] Fix | Delete
$block_reader->seek( 'iterate-selectors' );
[392] Fix | Delete
}
[393] Fix | Delete
}
[394] Fix | Delete
$block_reader->release_bookmark( 'iterate-selectors' );
[395] Fix | Delete
return $block_content;
[396] Fix | Delete
[397] Fix | Delete
case 'attribute':
[398] Fix | Delete
$amended_content = new WP_HTML_Tag_Processor( $block_content );
[399] Fix | Delete
if ( ! $amended_content->next_tag(
[400] Fix | Delete
array(
[401] Fix | Delete
// TODO: build the query from CSS selector.
[402] Fix | Delete
'tag_name' => $block_type->attributes[ $attribute_name ]['selector'],
[403] Fix | Delete
)
[404] Fix | Delete
) ) {
[405] Fix | Delete
return $block_content;
[406] Fix | Delete
}
[407] Fix | Delete
$amended_content->set_attribute( $block_type->attributes[ $attribute_name ]['attribute'], $source_value );
[408] Fix | Delete
return $amended_content->get_updated_html();
[409] Fix | Delete
[410] Fix | Delete
default:
[411] Fix | Delete
return $block_content;
[412] Fix | Delete
}
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
[416] Fix | Delete
/**
[417] Fix | Delete
* Generates the render output for the block.
[418] Fix | Delete
*
[419] Fix | Delete
* @since 5.5.0
[420] Fix | Delete
* @since 6.5.0 Added block bindings processing.
[421] Fix | Delete
*
[422] Fix | Delete
* @global WP_Post $post Global post object.
[423] Fix | Delete
*
[424] Fix | Delete
* @param array $options {
[425] Fix | Delete
* Optional options object.
[426] Fix | Delete
*
[427] Fix | Delete
* @type bool $dynamic Defaults to 'true'. Optionally set to false to avoid using the block's render_callback.
[428] Fix | Delete
* }
[429] Fix | Delete
* @return string Rendered block output.
[430] Fix | Delete
*/
[431] Fix | Delete
public function render( $options = array() ) {
[432] Fix | Delete
global $post;
[433] Fix | Delete
[434] Fix | Delete
/*
[435] Fix | Delete
* There can be only one root interactive block at a time because the rendered HTML of that block contains
[436] Fix | Delete
* the rendered HTML of all its inner blocks, including any interactive block.
[437] Fix | Delete
*/
[438] Fix | Delete
static $root_interactive_block = null;
[439] Fix | Delete
/**
[440] Fix | Delete
* Filters whether Interactivity API should process directives.
[441] Fix | Delete
*
[442] Fix | Delete
* @since 6.6.0
[443] Fix | Delete
*
[444] Fix | Delete
* @param bool $enabled Whether the directives processing is enabled.
[445] Fix | Delete
*/
[446] Fix | Delete
$interactivity_process_directives_enabled = apply_filters( 'interactivity_process_directives', true );
[447] Fix | Delete
if (
[448] Fix | Delete
$interactivity_process_directives_enabled && null === $root_interactive_block && (
[449] Fix | Delete
( isset( $this->block_type->supports['interactivity'] ) && true === $this->block_type->supports['interactivity'] ) ||
[450] Fix | Delete
! empty( $this->block_type->supports['interactivity']['interactive'] )
[451] Fix | Delete
)
[452] Fix | Delete
) {
[453] Fix | Delete
$root_interactive_block = $this;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
$options = wp_parse_args(
[457] Fix | Delete
$options,
[458] Fix | Delete
array(
[459] Fix | Delete
'dynamic' => true,
[460] Fix | Delete
)
[461] Fix | Delete
);
[462] Fix | Delete
[463] Fix | Delete
// Process the block bindings and get attributes updated with the values from the sources.
[464] Fix | Delete
$computed_attributes = $this->process_block_bindings();
[465] Fix | Delete
if ( ! empty( $computed_attributes ) ) {
[466] Fix | Delete
// Merge the computed attributes with the original attributes.
[467] Fix | Delete
$this->attributes = array_merge( $this->attributes, $computed_attributes );
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
$is_dynamic = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic();
[471] Fix | Delete
$block_content = '';
[472] Fix | Delete
[473] Fix | Delete
if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
[474] Fix | Delete
$index = 0;
[475] Fix | Delete
[476] Fix | Delete
foreach ( $this->inner_content as $chunk ) {
[477] Fix | Delete
if ( is_string( $chunk ) ) {
[478] Fix | Delete
$block_content .= $chunk;
[479] Fix | Delete
} else {
[480] Fix | Delete
$inner_block = $this->inner_blocks[ $index ];
[481] Fix | Delete
$parent_block = $this;
[482] Fix | Delete
[483] Fix | Delete
/** This filter is documented in wp-includes/blocks.php */
[484] Fix | Delete
$pre_render = apply_filters( 'pre_render_block', null, $inner_block->parsed_block, $parent_block );
[485] Fix | Delete
[486] Fix | Delete
if ( ! is_null( $pre_render ) ) {
[487] Fix | Delete
$block_content .= $pre_render;
[488] Fix | Delete
} else {
[489] Fix | Delete
$source_block = $inner_block->parsed_block;
[490] Fix | Delete
[491] Fix | Delete
/** This filter is documented in wp-includes/blocks.php */
[492] Fix | Delete
$inner_block->parsed_block = apply_filters( 'render_block_data', $inner_block->parsed_block, $source_block, $parent_block );
[493] Fix | Delete
[494] Fix | Delete
/** This filter is documented in wp-includes/blocks.php */
[495] Fix | Delete
$inner_block->context = apply_filters( 'render_block_context', $inner_block->context, $inner_block->parsed_block, $parent_block );
[496] Fix | Delete
[497] Fix | Delete
$block_content .= $inner_block->render();
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function