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 = array();
[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
* An associative 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
$this->refresh_context_dependents();
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Updates the context for the current block and its inner blocks.
[146] Fix | Delete
*
[147] Fix | Delete
* The method updates the context of inner blocks, if any, by passing down
[148] Fix | Delete
* any context values the block provides (`provides_context`).
[149] Fix | Delete
*
[150] Fix | Delete
* If the block has inner blocks, the method recursively processes them by creating new instances of `WP_Block`
[151] Fix | Delete
* for each inner block and updating their context based on the block's `provides_context` property.
[152] Fix | Delete
*
[153] Fix | Delete
* @since 6.8.0
[154] Fix | Delete
*/
[155] Fix | Delete
public function refresh_context_dependents() {
[156] Fix | Delete
/*
[157] Fix | Delete
* Merging the `$context` property here is not ideal, but for now needs to happen because of backward compatibility.
[158] Fix | Delete
* Ideally, the `$context` property itself would not be filterable directly and only the `$available_context` would be filterable.
[159] Fix | Delete
* However, this needs to be separately explored whether it's possible without breakage.
[160] Fix | Delete
*/
[161] Fix | Delete
$this->available_context = array_merge( $this->available_context, $this->context );
[162] Fix | Delete
[163] Fix | Delete
if ( ! empty( $this->block_type->uses_context ) ) {
[164] Fix | Delete
foreach ( $this->block_type->uses_context as $context_name ) {
[165] Fix | Delete
if ( array_key_exists( $context_name, $this->available_context ) ) {
[166] Fix | Delete
$this->context[ $context_name ] = $this->available_context[ $context_name ];
[167] Fix | Delete
}
[168] Fix | Delete
}
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
$this->refresh_parsed_block_dependents();
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Updates the parsed block content for the current block and its inner blocks.
[176] Fix | Delete
*
[177] Fix | Delete
* This method sets the `inner_html` and `inner_content` properties of the block based on the parsed
[178] Fix | Delete
* block content provided during initialization. It ensures that the block instance reflects the
[179] Fix | Delete
* most up-to-date content for both the inner HTML and any string fragments around inner blocks.
[180] Fix | Delete
*
[181] Fix | Delete
* If the block has inner blocks, this method initializes a new `WP_Block_List` for them, ensuring the
[182] Fix | Delete
* correct content and context are updated for each nested block.
[183] Fix | Delete
*
[184] Fix | Delete
* @since 6.8.0
[185] Fix | Delete
*/
[186] Fix | Delete
public function refresh_parsed_block_dependents() {
[187] Fix | Delete
if ( ! empty( $this->parsed_block['innerBlocks'] ) ) {
[188] Fix | Delete
$child_context = $this->available_context;
[189] Fix | Delete
[190] Fix | Delete
if ( ! empty( $this->block_type->provides_context ) ) {
[191] Fix | Delete
foreach ( $this->block_type->provides_context as $context_name => $attribute_name ) {
[192] Fix | Delete
if ( array_key_exists( $attribute_name, $this->attributes ) ) {
[193] Fix | Delete
$child_context[ $context_name ] = $this->attributes[ $attribute_name ];
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$this->inner_blocks = new WP_Block_List( $this->parsed_block['innerBlocks'], $child_context, $this->registry );
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
if ( ! empty( $this->parsed_block['innerHTML'] ) ) {
[202] Fix | Delete
$this->inner_html = $this->parsed_block['innerHTML'];
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
if ( ! empty( $this->parsed_block['innerContent'] ) ) {
[206] Fix | Delete
$this->inner_content = $this->parsed_block['innerContent'];
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Returns a value from an inaccessible property.
[212] Fix | Delete
*
[213] Fix | Delete
* This is used to lazily initialize the `attributes` property of a block,
[214] Fix | Delete
* such that it is only prepared with default attributes at the time that
[215] Fix | Delete
* the property is accessed. For all other inaccessible properties, a `null`
[216] Fix | Delete
* value is returned.
[217] Fix | Delete
*
[218] Fix | Delete
* @since 5.5.0
[219] Fix | Delete
*
[220] Fix | Delete
* @param string $name Property name.
[221] Fix | Delete
* @return array|null Prepared attributes, or null.
[222] Fix | Delete
*/
[223] Fix | Delete
public function __get( $name ) {
[224] Fix | Delete
if ( 'attributes' === $name ) {
[225] Fix | Delete
$this->attributes = isset( $this->parsed_block['attrs'] ) ?
[226] Fix | Delete
$this->parsed_block['attrs'] :
[227] Fix | Delete
array();
[228] Fix | Delete
[229] Fix | Delete
if ( ! is_null( $this->block_type ) ) {
[230] Fix | Delete
$this->attributes = $this->block_type->prepare_attributes_for_render( $this->attributes );
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
return $this->attributes;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
return null;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
/**
[240] Fix | Delete
* Processes the block bindings and updates the block attributes with the values from the sources.
[241] Fix | Delete
*
[242] Fix | Delete
* A block might contain bindings in its attributes. Bindings are mappings
[243] Fix | Delete
* between an attribute of the block and a source. A "source" is a function
[244] Fix | Delete
* registered with `register_block_bindings_source()` that defines how to
[245] Fix | Delete
* retrieve a value from outside the block, e.g. from post meta.
[246] Fix | Delete
*
[247] Fix | Delete
* This function will process those bindings and update the block's attributes
[248] Fix | Delete
* with the values coming from the bindings.
[249] Fix | Delete
*
[250] Fix | Delete
* ### Example
[251] Fix | Delete
*
[252] Fix | Delete
* The "bindings" property for an Image block might look like this:
[253] Fix | Delete
*
[254] Fix | Delete
* ```json
[255] Fix | Delete
* {
[256] Fix | Delete
* "metadata": {
[257] Fix | Delete
* "bindings": {
[258] Fix | Delete
* "title": {
[259] Fix | Delete
* "source": "core/post-meta",
[260] Fix | Delete
* "args": { "key": "text_custom_field" }
[261] Fix | Delete
* },
[262] Fix | Delete
* "url": {
[263] Fix | Delete
* "source": "core/post-meta",
[264] Fix | Delete
* "args": { "key": "url_custom_field" }
[265] Fix | Delete
* }
[266] Fix | Delete
* }
[267] Fix | Delete
* }
[268] Fix | Delete
* }
[269] Fix | Delete
* ```
[270] Fix | Delete
*
[271] Fix | Delete
* The above example will replace the `title` and `url` attributes of the Image
[272] Fix | Delete
* block with the values of the `text_custom_field` and `url_custom_field` post meta.
[273] Fix | Delete
*
[274] Fix | Delete
* @since 6.5.0
[275] Fix | Delete
* @since 6.6.0 Handle the `__default` attribute for pattern overrides.
[276] Fix | Delete
* @since 6.7.0 Return any updated bindings metadata in the computed attributes.
[277] Fix | Delete
*
[278] Fix | Delete
* @return array The computed block attributes for the provided block bindings.
[279] Fix | Delete
*/
[280] Fix | Delete
private function process_block_bindings() {
[281] Fix | Delete
$parsed_block = $this->parsed_block;
[282] Fix | Delete
$computed_attributes = array();
[283] Fix | Delete
$supported_block_attributes = array(
[284] Fix | Delete
'core/paragraph' => array( 'content' ),
[285] Fix | Delete
'core/heading' => array( 'content' ),
[286] Fix | Delete
'core/image' => array( 'id', 'url', 'title', 'alt' ),
[287] Fix | Delete
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
[288] Fix | Delete
);
[289] Fix | Delete
[290] Fix | Delete
// If the block doesn't have the bindings property, isn't one of the supported
[291] Fix | Delete
// block types, or the bindings property is not an array, return the block content.
[292] Fix | Delete
if (
[293] Fix | Delete
! isset( $supported_block_attributes[ $this->name ] ) ||
[294] Fix | Delete
empty( $parsed_block['attrs']['metadata']['bindings'] ) ||
[295] Fix | Delete
! is_array( $parsed_block['attrs']['metadata']['bindings'] )
[296] Fix | Delete
) {
[297] Fix | Delete
return $computed_attributes;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$bindings = $parsed_block['attrs']['metadata']['bindings'];
[301] Fix | Delete
[302] Fix | Delete
/*
[303] Fix | Delete
* If the default binding is set for pattern overrides, replace it
[304] Fix | Delete
* with a pattern override binding for all supported attributes.
[305] Fix | Delete
*/
[306] Fix | Delete
if (
[307] Fix | Delete
isset( $bindings['__default']['source'] ) &&
[308] Fix | Delete
'core/pattern-overrides' === $bindings['__default']['source']
[309] Fix | Delete
) {
[310] Fix | Delete
$updated_bindings = array();
[311] Fix | Delete
[312] Fix | Delete
/*
[313] Fix | Delete
* Build a binding array of all supported attributes.
[314] Fix | Delete
* Note that this also omits the `__default` attribute from the
[315] Fix | Delete
* resulting array.
[316] Fix | Delete
*/
[317] Fix | Delete
foreach ( $supported_block_attributes[ $parsed_block['blockName'] ] as $attribute_name ) {
[318] Fix | Delete
// Retain any non-pattern override bindings that might be present.
[319] Fix | Delete
$updated_bindings[ $attribute_name ] = isset( $bindings[ $attribute_name ] )
[320] Fix | Delete
? $bindings[ $attribute_name ]
[321] Fix | Delete
: array( 'source' => 'core/pattern-overrides' );
[322] Fix | Delete
}
[323] Fix | Delete
$bindings = $updated_bindings;
[324] Fix | Delete
/*
[325] Fix | Delete
* Update the bindings metadata of the computed attributes.
[326] Fix | Delete
* This ensures the block receives the expanded __default binding metadata when it renders.
[327] Fix | Delete
*/
[328] Fix | Delete
$computed_attributes['metadata'] = array_merge(
[329] Fix | Delete
$parsed_block['attrs']['metadata'],
[330] Fix | Delete
array( 'bindings' => $bindings )
[331] Fix | Delete
);
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
foreach ( $bindings as $attribute_name => $block_binding ) {
[335] Fix | Delete
// If the attribute is not in the supported list, process next attribute.
[336] Fix | Delete
if ( ! in_array( $attribute_name, $supported_block_attributes[ $this->name ], true ) ) {
[337] Fix | Delete
continue;
[338] Fix | Delete
}
[339] Fix | Delete
// If no source is provided, or that source is not registered, process next attribute.
[340] Fix | Delete
if ( ! isset( $block_binding['source'] ) || ! is_string( $block_binding['source'] ) ) {
[341] Fix | Delete
continue;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
$block_binding_source = get_block_bindings_source( $block_binding['source'] );
[345] Fix | Delete
if ( null === $block_binding_source ) {
[346] Fix | Delete
continue;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
// Adds the necessary context defined by the source.
[350] Fix | Delete
if ( ! empty( $block_binding_source->uses_context ) ) {
[351] Fix | Delete
foreach ( $block_binding_source->uses_context as $context_name ) {
[352] Fix | Delete
if ( array_key_exists( $context_name, $this->available_context ) ) {
[353] Fix | Delete
$this->context[ $context_name ] = $this->available_context[ $context_name ];
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
$source_args = ! empty( $block_binding['args'] ) && is_array( $block_binding['args'] ) ? $block_binding['args'] : array();
[359] Fix | Delete
$source_value = $block_binding_source->get_value( $source_args, $this, $attribute_name );
[360] Fix | Delete
[361] Fix | Delete
// If the value is not null, process the HTML based on the block and the attribute.
[362] Fix | Delete
if ( ! is_null( $source_value ) ) {
[363] Fix | Delete
$computed_attributes[ $attribute_name ] = $source_value;
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
return $computed_attributes;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* Depending on the block attribute name, replace its value in the HTML based on the value provided.
[372] Fix | Delete
*
[373] Fix | Delete
* @since 6.5.0
[374] Fix | Delete
*
[375] Fix | Delete
* @param string $block_content Block content.
[376] Fix | Delete
* @param string $attribute_name The attribute name to replace.
[377] Fix | Delete
* @param mixed $source_value The value used to replace in the HTML.
[378] Fix | Delete
* @return string The modified block content.
[379] Fix | Delete
*/
[380] Fix | Delete
private function replace_html( string $block_content, string $attribute_name, $source_value ) {
[381] Fix | Delete
$block_type = $this->block_type;
[382] Fix | Delete
if ( ! isset( $block_type->attributes[ $attribute_name ]['source'] ) ) {
[383] Fix | Delete
return $block_content;
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
// Depending on the attribute source, the processing will be different.
[387] Fix | Delete
switch ( $block_type->attributes[ $attribute_name ]['source'] ) {
[388] Fix | Delete
case 'html':
[389] Fix | Delete
case 'rich-text':
[390] Fix | Delete
$block_reader = new WP_HTML_Tag_Processor( $block_content );
[391] Fix | Delete
[392] Fix | Delete
// TODO: Support for CSS selectors whenever they are ready in the HTML API.
[393] Fix | Delete
// In the meantime, support comma-separated selectors by exploding them into an array.
[394] Fix | Delete
$selectors = explode( ',', $block_type->attributes[ $attribute_name ]['selector'] );
[395] Fix | Delete
// Add a bookmark to the first tag to be able to iterate over the selectors.
[396] Fix | Delete
$block_reader->next_tag();
[397] Fix | Delete
$block_reader->set_bookmark( 'iterate-selectors' );
[398] Fix | Delete
[399] Fix | Delete
// TODO: This shouldn't be needed when the `set_inner_html` function is ready.
[400] Fix | Delete
// Store the parent tag and its attributes to be able to restore them later in the button.
[401] Fix | Delete
// The button block has a wrapper while the paragraph and heading blocks don't.
[402] Fix | Delete
if ( 'core/button' === $this->name ) {
[403] Fix | Delete
$button_wrapper = $block_reader->get_tag();
[404] Fix | Delete
$button_wrapper_attribute_names = $block_reader->get_attribute_names_with_prefix( '' );
[405] Fix | Delete
$button_wrapper_attrs = array();
[406] Fix | Delete
foreach ( $button_wrapper_attribute_names as $name ) {
[407] Fix | Delete
$button_wrapper_attrs[ $name ] = $block_reader->get_attribute( $name );
[408] Fix | Delete
}
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
foreach ( $selectors as $selector ) {
[412] Fix | Delete
// If the parent tag, or any of its children, matches the selector, replace the HTML.
[413] Fix | Delete
if ( strcasecmp( $block_reader->get_tag(), $selector ) === 0 || $block_reader->next_tag(
[414] Fix | Delete
array(
[415] Fix | Delete
'tag_name' => $selector,
[416] Fix | Delete
)
[417] Fix | Delete
) ) {
[418] Fix | Delete
$block_reader->release_bookmark( 'iterate-selectors' );
[419] Fix | Delete
[420] Fix | Delete
// TODO: Use `set_inner_html` method whenever it's ready in the HTML API.
[421] Fix | Delete
// Until then, it is hardcoded for the paragraph, heading, and button blocks.
[422] Fix | Delete
// Store the tag and its attributes to be able to restore them later.
[423] Fix | Delete
$selector_attribute_names = $block_reader->get_attribute_names_with_prefix( '' );
[424] Fix | Delete
$selector_attrs = array();
[425] Fix | Delete
foreach ( $selector_attribute_names as $name ) {
[426] Fix | Delete
$selector_attrs[ $name ] = $block_reader->get_attribute( $name );
[427] Fix | Delete
}
[428] Fix | Delete
$selector_markup = "<$selector>" . wp_kses_post( $source_value ) . "</$selector>";
[429] Fix | Delete
$amended_content = new WP_HTML_Tag_Processor( $selector_markup );
[430] Fix | Delete
$amended_content->next_tag();
[431] Fix | Delete
foreach ( $selector_attrs as $attribute_key => $attribute_value ) {
[432] Fix | Delete
$amended_content->set_attribute( $attribute_key, $attribute_value );
[433] Fix | Delete
}
[434] Fix | Delete
if ( 'core/paragraph' === $this->name || 'core/heading' === $this->name ) {
[435] Fix | Delete
return $amended_content->get_updated_html();
[436] Fix | Delete
}
[437] Fix | Delete
if ( 'core/button' === $this->name ) {
[438] Fix | Delete
$button_markup = "<$button_wrapper>{$amended_content->get_updated_html()}</$button_wrapper>";
[439] Fix | Delete
$amended_button = new WP_HTML_Tag_Processor( $button_markup );
[440] Fix | Delete
$amended_button->next_tag();
[441] Fix | Delete
foreach ( $button_wrapper_attrs as $attribute_key => $attribute_value ) {
[442] Fix | Delete
$amended_button->set_attribute( $attribute_key, $attribute_value );
[443] Fix | Delete
}
[444] Fix | Delete
return $amended_button->get_updated_html();
[445] Fix | Delete
}
[446] Fix | Delete
} else {
[447] Fix | Delete
$block_reader->seek( 'iterate-selectors' );
[448] Fix | Delete
}
[449] Fix | Delete
}
[450] Fix | Delete
$block_reader->release_bookmark( 'iterate-selectors' );
[451] Fix | Delete
return $block_content;
[452] Fix | Delete
[453] Fix | Delete
case 'attribute':
[454] Fix | Delete
$amended_content = new WP_HTML_Tag_Processor( $block_content );
[455] Fix | Delete
if ( ! $amended_content->next_tag(
[456] Fix | Delete
array(
[457] Fix | Delete
// TODO: build the query from CSS selector.
[458] Fix | Delete
'tag_name' => $block_type->attributes[ $attribute_name ]['selector'],
[459] Fix | Delete
)
[460] Fix | Delete
) ) {
[461] Fix | Delete
return $block_content;
[462] Fix | Delete
}
[463] Fix | Delete
$amended_content->set_attribute( $block_type->attributes[ $attribute_name ]['attribute'], $source_value );
[464] Fix | Delete
return $amended_content->get_updated_html();
[465] Fix | Delete
[466] Fix | Delete
default:
[467] Fix | Delete
return $block_content;
[468] Fix | Delete
}
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
[472] Fix | Delete
/**
[473] Fix | Delete
* Generates the render output for the block.
[474] Fix | Delete
*
[475] Fix | Delete
* @since 5.5.0
[476] Fix | Delete
* @since 6.5.0 Added block bindings processing.
[477] Fix | Delete
*
[478] Fix | Delete
* @global WP_Post $post Global post object.
[479] Fix | Delete
*
[480] Fix | Delete
* @param array $options {
[481] Fix | Delete
* Optional options object.
[482] Fix | Delete
*
[483] Fix | Delete
* @type bool $dynamic Defaults to 'true'. Optionally set to false to avoid using the block's render_callback.
[484] Fix | Delete
* }
[485] Fix | Delete
* @return string Rendered block output.
[486] Fix | Delete
*/
[487] Fix | Delete
public function render( $options = array() ) {
[488] Fix | Delete
global $post;
[489] Fix | Delete
[490] Fix | Delete
/*
[491] Fix | Delete
* There can be only one root interactive block at a time because the rendered HTML of that block contains
[492] Fix | Delete
* the rendered HTML of all its inner blocks, including any interactive block.
[493] Fix | Delete
*/
[494] Fix | Delete
static $root_interactive_block = null;
[495] Fix | Delete
/**
[496] Fix | Delete
* Filters whether Interactivity API should process directives.
[497] Fix | Delete
*
[498] Fix | Delete
* @since 6.6.0
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function