Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Blocks/Template...
File: SingleProductTemplateCompatibility.php
<?php
[0] Fix | Delete
declare(strict_types=1);
[1] Fix | Delete
[2] Fix | Delete
namespace Automattic\WooCommerce\Blocks\Templates;
[3] Fix | Delete
[4] Fix | Delete
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* SingleProductTemplateCompatibility class.
[8] Fix | Delete
*
[9] Fix | Delete
* To bridge the gap on compatibility with PHP hooks and Single Product templates.
[10] Fix | Delete
*
[11] Fix | Delete
* @internal
[12] Fix | Delete
*/
[13] Fix | Delete
class SingleProductTemplateCompatibility extends AbstractTemplateCompatibility {
[14] Fix | Delete
const IS_FIRST_BLOCK = '__wooCommerceIsFirstBlock';
[15] Fix | Delete
const IS_LAST_BLOCK = '__wooCommerceIsLastBlock';
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Inject hooks to rendered content of corresponding blocks.
[19] Fix | Delete
*
[20] Fix | Delete
* @param mixed $block_content The rendered block content.
[21] Fix | Delete
* @param mixed $block The parsed block data.
[22] Fix | Delete
*
[23] Fix | Delete
* @return string
[24] Fix | Delete
*/
[25] Fix | Delete
public function inject_hooks( $block_content, $block ) {
[26] Fix | Delete
if ( ! is_product() ) {
[27] Fix | Delete
return $block_content;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
$this->remove_default_hooks();
[31] Fix | Delete
[32] Fix | Delete
$block_name = $block['blockName'];
[33] Fix | Delete
[34] Fix | Delete
$block_hooks = array_filter(
[35] Fix | Delete
$this->hook_data,
[36] Fix | Delete
function ( $hook ) use ( $block_name ) {
[37] Fix | Delete
return in_array( $block_name, $hook['block_names'], true );
[38] Fix | Delete
}
[39] Fix | Delete
);
[40] Fix | Delete
[41] Fix | Delete
$first_or_last_block_content = $this->inject_hook_to_first_and_last_blocks( $block_content, $block, $block_hooks );
[42] Fix | Delete
[43] Fix | Delete
if ( isset( $first_or_last_block_content ) ) {
[44] Fix | Delete
return $first_or_last_block_content;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return sprintf(
[48] Fix | Delete
'%1$s%2$s%3$s',
[49] Fix | Delete
$this->get_hooks_buffer( $block_hooks, 'before' ),
[50] Fix | Delete
$block_content,
[51] Fix | Delete
$this->get_hooks_buffer( $block_hooks, 'after' )
[52] Fix | Delete
);
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Inject custom hooks to the first and last blocks.
[57] Fix | Delete
* Since that there is a custom logic for the first and last block, we have to inject the hooks manually.
[58] Fix | Delete
* The first block supports the following hooks:
[59] Fix | Delete
* woocommerce_before_single_product
[60] Fix | Delete
* woocommerce_before_single_product_summary
[61] Fix | Delete
*
[62] Fix | Delete
* The last block supports the following hooks:
[63] Fix | Delete
* woocommerce_after_single_product
[64] Fix | Delete
*
[65] Fix | Delete
* @param mixed $block_content The rendered block content.
[66] Fix | Delete
* @param mixed $block The parsed block data.
[67] Fix | Delete
* @param array $block_hooks The hooks that should be injected to the block.
[68] Fix | Delete
*
[69] Fix | Delete
* @return string
[70] Fix | Delete
*/
[71] Fix | Delete
private function inject_hook_to_first_and_last_blocks( $block_content, $block, $block_hooks ) {
[72] Fix | Delete
$first_block_hook = array(
[73] Fix | Delete
'before' => array(
[74] Fix | Delete
'woocommerce_before_main_content' => $this->hook_data['woocommerce_before_main_content'],
[75] Fix | Delete
'woocommerce_before_single_product' => $this->hook_data['woocommerce_before_single_product'],
[76] Fix | Delete
'woocommerce_before_single_product_summary' => $this->hook_data['woocommerce_before_single_product_summary'],
[77] Fix | Delete
),
[78] Fix | Delete
'after' => array(),
[79] Fix | Delete
);
[80] Fix | Delete
[81] Fix | Delete
$last_block_hook = array(
[82] Fix | Delete
'before' => array(),
[83] Fix | Delete
'after' => array(
[84] Fix | Delete
'woocommerce_after_single_product' => $this->hook_data['woocommerce_after_single_product'],
[85] Fix | Delete
'woocommerce_after_main_content' => $this->hook_data['woocommerce_after_main_content'],
[86] Fix | Delete
'woocommerce_sidebar' => $this->hook_data['woocommerce_sidebar'],
[87] Fix | Delete
),
[88] Fix | Delete
);
[89] Fix | Delete
[90] Fix | Delete
if ( isset( $block['attrs'][ self::IS_FIRST_BLOCK ] ) && isset( $block['attrs'][ self::IS_LAST_BLOCK ] ) ) {
[91] Fix | Delete
return sprintf(
[92] Fix | Delete
'%1$s%2$s',
[93] Fix | Delete
$this->inject_hooks_after_the_wrapper(
[94] Fix | Delete
$block_content,
[95] Fix | Delete
array_merge(
[96] Fix | Delete
$first_block_hook['before'],
[97] Fix | Delete
$block_hooks,
[98] Fix | Delete
$last_block_hook['before']
[99] Fix | Delete
)
[100] Fix | Delete
),
[101] Fix | Delete
$this->get_hooks_buffer(
[102] Fix | Delete
array_merge(
[103] Fix | Delete
$first_block_hook['after'],
[104] Fix | Delete
$block_hooks,
[105] Fix | Delete
$last_block_hook['after']
[106] Fix | Delete
),
[107] Fix | Delete
'after'
[108] Fix | Delete
)
[109] Fix | Delete
);
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
if ( isset( $block['attrs'][ self::IS_FIRST_BLOCK ] ) ) {
[113] Fix | Delete
return sprintf(
[114] Fix | Delete
'%1$s%2$s',
[115] Fix | Delete
$this->inject_hooks_after_the_wrapper(
[116] Fix | Delete
$block_content,
[117] Fix | Delete
array_merge(
[118] Fix | Delete
$first_block_hook['before'],
[119] Fix | Delete
$block_hooks
[120] Fix | Delete
)
[121] Fix | Delete
),
[122] Fix | Delete
$this->get_hooks_buffer(
[123] Fix | Delete
array_merge(
[124] Fix | Delete
$first_block_hook['after'],
[125] Fix | Delete
$block_hooks
[126] Fix | Delete
),
[127] Fix | Delete
'after'
[128] Fix | Delete
)
[129] Fix | Delete
);
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
if ( isset( $block['attrs'][ self::IS_LAST_BLOCK ] ) ) {
[133] Fix | Delete
return sprintf(
[134] Fix | Delete
'%1$s%2$s%3$s',
[135] Fix | Delete
$this->get_hooks_buffer(
[136] Fix | Delete
array_merge(
[137] Fix | Delete
$last_block_hook['before'],
[138] Fix | Delete
$block_hooks
[139] Fix | Delete
),
[140] Fix | Delete
'before'
[141] Fix | Delete
),
[142] Fix | Delete
$block_content,
[143] Fix | Delete
$this->get_hooks_buffer(
[144] Fix | Delete
array_merge(
[145] Fix | Delete
$block_hooks,
[146] Fix | Delete
$last_block_hook['after']
[147] Fix | Delete
),
[148] Fix | Delete
'after'
[149] Fix | Delete
)
[150] Fix | Delete
);
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Update the render block data to inject our custom attribute needed to
[156] Fix | Delete
* determine which is the first block of the Single Product Template.
[157] Fix | Delete
*
[158] Fix | Delete
* @param array $parsed_block The block being rendered.
[159] Fix | Delete
* @param array $source_block An un-modified copy of $parsed_block, as it appeared in the source content.
[160] Fix | Delete
* @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block.
[161] Fix | Delete
*
[162] Fix | Delete
* @return array
[163] Fix | Delete
*/
[164] Fix | Delete
public function update_render_block_data( $parsed_block, $source_block, $parent_block ) {
[165] Fix | Delete
return $parsed_block;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Set supported hooks.
[170] Fix | Delete
*/
[171] Fix | Delete
protected function set_hook_data() {
[172] Fix | Delete
$this->hook_data = array(
[173] Fix | Delete
'woocommerce_before_main_content' => array(
[174] Fix | Delete
'block_names' => array(),
[175] Fix | Delete
'position' => 'before',
[176] Fix | Delete
'hooked' => array(
[177] Fix | Delete
'woocommerce_output_content_wrapper' => 10,
[178] Fix | Delete
'woocommerce_breadcrumb' => 20,
[179] Fix | Delete
),
[180] Fix | Delete
),
[181] Fix | Delete
'woocommerce_after_main_content' => array(
[182] Fix | Delete
'block_names' => array(),
[183] Fix | Delete
'position' => 'after',
[184] Fix | Delete
'hooked' => array(
[185] Fix | Delete
'woocommerce_output_content_wrapper_end' => 10,
[186] Fix | Delete
),
[187] Fix | Delete
),
[188] Fix | Delete
'woocommerce_sidebar' => array(
[189] Fix | Delete
'block_names' => array(),
[190] Fix | Delete
'position' => 'after',
[191] Fix | Delete
'hooked' => array(
[192] Fix | Delete
'woocommerce_get_sidebar' => 10,
[193] Fix | Delete
),
[194] Fix | Delete
),
[195] Fix | Delete
'woocommerce_before_single_product' => array(
[196] Fix | Delete
'block_names' => array(),
[197] Fix | Delete
'position' => 'before',
[198] Fix | Delete
'hooked' => array(
[199] Fix | Delete
'woocommerce_output_all_notices' => 10,
[200] Fix | Delete
),
[201] Fix | Delete
),
[202] Fix | Delete
'woocommerce_before_single_product_summary' => array(
[203] Fix | Delete
'block_names' => array(),
[204] Fix | Delete
'position' => 'before',
[205] Fix | Delete
'hooked' => array(
[206] Fix | Delete
'woocommerce_show_product_sale_flash' => 10,
[207] Fix | Delete
'woocommerce_show_product_images' => 20,
[208] Fix | Delete
),
[209] Fix | Delete
),
[210] Fix | Delete
'woocommerce_single_product_summary' => array(
[211] Fix | Delete
'block_names' => array( 'core/post-excerpt', 'woocommerce/product-summary' ),
[212] Fix | Delete
'position' => 'before',
[213] Fix | Delete
'hooked' => array(
[214] Fix | Delete
'woocommerce_template_single_title' => 5,
[215] Fix | Delete
'woocommerce_template_single_rating' => 10,
[216] Fix | Delete
'woocommerce_template_single_price' => 10,
[217] Fix | Delete
'woocommerce_template_single_excerpt' => 20,
[218] Fix | Delete
'woocommerce_template_single_add_to_cart' => 30,
[219] Fix | Delete
'woocommerce_template_single_meta' => 40,
[220] Fix | Delete
'woocommerce_template_single_sharing' => 50,
[221] Fix | Delete
),
[222] Fix | Delete
),
[223] Fix | Delete
'woocommerce_after_single_product' => array(
[224] Fix | Delete
'block_names' => array(),
[225] Fix | Delete
'position' => 'after',
[226] Fix | Delete
'hooked' => array(),
[227] Fix | Delete
),
[228] Fix | Delete
'woocommerce_product_meta_start' => array(
[229] Fix | Delete
'block_names' => array( 'woocommerce/product-meta' ),
[230] Fix | Delete
'position' => 'before',
[231] Fix | Delete
'hooked' => array(),
[232] Fix | Delete
),
[233] Fix | Delete
'woocommerce_product_meta_end' => array(
[234] Fix | Delete
'block_names' => array( 'woocommerce/product-meta' ),
[235] Fix | Delete
'position' => 'after',
[236] Fix | Delete
'hooked' => array(),
[237] Fix | Delete
),
[238] Fix | Delete
'woocommerce_share' => array(
[239] Fix | Delete
'block_names' => array( 'woocommerce/product-details' ),
[240] Fix | Delete
'position' => 'before',
[241] Fix | Delete
'hooked' => array(),
[242] Fix | Delete
),
[243] Fix | Delete
'woocommerce_after_single_product_summary' => array(
[244] Fix | Delete
'block_names' => array( 'woocommerce/product-details' ),
[245] Fix | Delete
'position' => 'after',
[246] Fix | Delete
'hooked' => array(
[247] Fix | Delete
'woocommerce_output_product_data_tabs' => 10,
[248] Fix | Delete
// We want to display the upsell products after the last block that belongs to the Single Product.
[249] Fix | Delete
// 'woocommerce_upsell_display' => 15.
[250] Fix | Delete
'woocommerce_output_related_products' => 20,
[251] Fix | Delete
),
[252] Fix | Delete
),
[253] Fix | Delete
);
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Add compatibility layer to the first and last block of the Single Product Template.
[258] Fix | Delete
*
[259] Fix | Delete
* @param string $template_content Template.
[260] Fix | Delete
* @return string
[261] Fix | Delete
*/
[262] Fix | Delete
public static function add_compatibility_layer( $template_content ) {
[263] Fix | Delete
$blocks = parse_blocks( $template_content );
[264] Fix | Delete
if ( self::has_single_product_template_blocks( $blocks ) ) {
[265] Fix | Delete
$blocks = self::wrap_single_product_template( $template_content );
[266] Fix | Delete
}
[267] Fix | Delete
$template = self::inject_custom_attributes_to_first_and_last_block_single_product_template( $blocks );
[268] Fix | Delete
return self::serialize_blocks( $template );
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* For compatibility reason, we need to wrap the Single Product template in a div with specific class.
[273] Fix | Delete
* For more details, see https://github.com/woocommerce/woocommerce-blocks/issues/8314.
[274] Fix | Delete
*
[275] Fix | Delete
* @param string $template_content Template Content.
[276] Fix | Delete
* @return array Wrapped template content inside a div.
[277] Fix | Delete
*/
[278] Fix | Delete
private static function wrap_single_product_template( $template_content ) {
[279] Fix | Delete
$parsed_blocks = parse_blocks( $template_content );
[280] Fix | Delete
$grouped_blocks = self::group_blocks( $parsed_blocks );
[281] Fix | Delete
[282] Fix | Delete
$wrapped_blocks = array_map(
[283] Fix | Delete
function ( $blocks ) {
[284] Fix | Delete
if ( 'core/template-part' === $blocks[0]['blockName'] ) {
[285] Fix | Delete
return $blocks;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
$has_single_product_template_blocks = self::has_single_product_template_blocks( $blocks );
[289] Fix | Delete
[290] Fix | Delete
if ( $has_single_product_template_blocks ) {
[291] Fix | Delete
$wrapped_block = self::create_wrap_block_group( $blocks );
[292] Fix | Delete
return array( $wrapped_block[0] );
[293] Fix | Delete
}
[294] Fix | Delete
return $blocks;
[295] Fix | Delete
},
[296] Fix | Delete
$grouped_blocks
[297] Fix | Delete
);
[298] Fix | Delete
return $wrapped_blocks;
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
/**
[302] Fix | Delete
* Add custom attributes to the first group block and last group block that wrap Single Product Template blocks.
[303] Fix | Delete
*
[304] Fix | Delete
* @param array $wrapped_blocks Wrapped blocks.
[305] Fix | Delete
* @return array
[306] Fix | Delete
*/
[307] Fix | Delete
private static function inject_custom_attributes_to_first_and_last_block_single_product_template( $wrapped_blocks ) {
[308] Fix | Delete
$template_with_custom_attributes = array_reduce(
[309] Fix | Delete
$wrapped_blocks,
[310] Fix | Delete
function ( $carry, $item ) {
[311] Fix | Delete
[312] Fix | Delete
$index = $carry['index'];
[313] Fix | Delete
$carry['index'] = $carry['index'] + 1;
[314] Fix | Delete
// If the block is a child of a group block, we need to get the first block of the group.
[315] Fix | Delete
$block = isset( $item[0] ) ? $item[0] : $item;
[316] Fix | Delete
[317] Fix | Delete
if ( 'core/template-part' === $block['blockName'] || self::is_custom_html( $block ) ) {
[318] Fix | Delete
$carry['template'][] = $block;
[319] Fix | Delete
return $carry;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
if ( '' === $carry['first_block']['index'] ) {
[323] Fix | Delete
$block['attrs'][ self::IS_FIRST_BLOCK ] = true;
[324] Fix | Delete
$carry['first_block']['index'] = $index;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
if ( '' !== $carry['last_block']['index'] ) {
[328] Fix | Delete
$index_element = $carry['last_block']['index'];
[329] Fix | Delete
$carry['last_block']['index'] = $index;
[330] Fix | Delete
$block['attrs'][ self::IS_LAST_BLOCK ] = true;
[331] Fix | Delete
unset( $carry['template'][ $index_element ]['attrs'][ self::IS_LAST_BLOCK ] );
[332] Fix | Delete
[333] Fix | Delete
$carry['template'][] = $block;
[334] Fix | Delete
[335] Fix | Delete
return $carry;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
$block['attrs'][ self::IS_LAST_BLOCK ] = true;
[339] Fix | Delete
$carry['last_block']['index'] = $index;
[340] Fix | Delete
[341] Fix | Delete
$carry['template'][] = $block;
[342] Fix | Delete
[343] Fix | Delete
return $carry;
[344] Fix | Delete
},
[345] Fix | Delete
array(
[346] Fix | Delete
'template' => array(),
[347] Fix | Delete
'first_block' => array(
[348] Fix | Delete
'index' => '',
[349] Fix | Delete
),
[350] Fix | Delete
'last_block' => array(
[351] Fix | Delete
'index' => '',
[352] Fix | Delete
),
[353] Fix | Delete
'index' => 0,
[354] Fix | Delete
)
[355] Fix | Delete
);
[356] Fix | Delete
[357] Fix | Delete
return array( $template_with_custom_attributes['template'] );
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Wrap all the blocks inside the template in a group block.
[362] Fix | Delete
*
[363] Fix | Delete
* @param array $blocks Array of parsed block objects.
[364] Fix | Delete
* @return array Group block with the blocks inside.
[365] Fix | Delete
*/
[366] Fix | Delete
private static function create_wrap_block_group( $blocks ) {
[367] Fix | Delete
$serialized_blocks = serialize_blocks( $blocks );
[368] Fix | Delete
[369] Fix | Delete
$new_block = parse_blocks(
[370] Fix | Delete
sprintf(
[371] Fix | Delete
'<!-- wp:group {"className":"woocommerce product"} -->
[372] Fix | Delete
<div class="wp-block-group woocommerce product">
[373] Fix | Delete
%1$s
[374] Fix | Delete
</div>
[375] Fix | Delete
<!-- /wp:group -->',
[376] Fix | Delete
$serialized_blocks
[377] Fix | Delete
)
[378] Fix | Delete
);
[379] Fix | Delete
[380] Fix | Delete
$new_block['innerBlocks'] = $blocks;
[381] Fix | Delete
[382] Fix | Delete
return $new_block;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Check if the Single Product template has a single product template block:
[387] Fix | Delete
* woocommerce/product-gallery-image, woocommerce/product-details, woocommerce/add-to-cart-form, etc.
[388] Fix | Delete
*
[389] Fix | Delete
* @param array $parsed_blocks Array of parsed block objects.
[390] Fix | Delete
* @return bool True if the template has a single product template block, false otherwise.
[391] Fix | Delete
*/
[392] Fix | Delete
private static function has_single_product_template_blocks( $parsed_blocks ) {
[393] Fix | Delete
$single_product_template_blocks = array( 'woocommerce/product-image-gallery', 'woocommerce/product-gallery', 'woocommerce/product-details', 'woocommerce/add-to-cart-form', 'woocommerce/add-to-cart-with-options', 'woocommerce/product-meta', 'woocommerce/product-price', 'woocommerce/breadcrumbs' );
[394] Fix | Delete
[395] Fix | Delete
return BlockTemplateUtils::has_block_including_patterns( $single_product_template_blocks, $parsed_blocks );
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Group blocks in this way:
[401] Fix | Delete
* B1 + TP1 + B2 + B3 + B4 + TP2 + B5
[402] Fix | Delete
* (B = Block, TP = Template Part)
[403] Fix | Delete
* becomes:
[404] Fix | Delete
* [[B1], [TP1], [B2, B3, B4], [TP2], [B5]]
[405] Fix | Delete
*
[406] Fix | Delete
* @param array $parsed_blocks Array of parsed block objects.
[407] Fix | Delete
* @return array Array of blocks grouped by template part.
[408] Fix | Delete
*/
[409] Fix | Delete
private static function group_blocks( $parsed_blocks ) {
[410] Fix | Delete
return array_reduce(
[411] Fix | Delete
$parsed_blocks,
[412] Fix | Delete
function ( array $carry, array $block ) {
[413] Fix | Delete
if ( 'core/template-part' === $block['blockName'] ) {
[414] Fix | Delete
$carry[] = array( $block );
[415] Fix | Delete
return $carry;
[416] Fix | Delete
}
[417] Fix | Delete
$last_element_index = count( $carry ) - 1;
[418] Fix | Delete
if ( isset( $carry[ $last_element_index ][0]['blockName'] ) && 'core/template-part' !== $carry[ $last_element_index ][0]['blockName'] ) {
[419] Fix | Delete
$carry[ $last_element_index ][] = $block;
[420] Fix | Delete
return $carry;
[421] Fix | Delete
}
[422] Fix | Delete
$carry[] = array( $block );
[423] Fix | Delete
return $carry;
[424] Fix | Delete
},
[425] Fix | Delete
array()
[426] Fix | Delete
);
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
/**
[430] Fix | Delete
* Inject the hooks after the div wrapper.
[431] Fix | Delete
*
[432] Fix | Delete
* @param string $block_content Block Content.
[433] Fix | Delete
* @param array $hooks Hooks to inject.
[434] Fix | Delete
* @return array
[435] Fix | Delete
*/
[436] Fix | Delete
private function inject_hooks_after_the_wrapper( $block_content, $hooks ) {
[437] Fix | Delete
$closing_tag_position = strpos( $block_content, '>' );
[438] Fix | Delete
[439] Fix | Delete
return substr_replace(
[440] Fix | Delete
$block_content,
[441] Fix | Delete
$this->get_hooks_buffer(
[442] Fix | Delete
$hooks,
[443] Fix | Delete
'before'
[444] Fix | Delete
),
[445] Fix | Delete
// Add 1 to the position to inject the content after the closing tag.
[446] Fix | Delete
$closing_tag_position + 1,
[447] Fix | Delete
0
[448] Fix | Delete
);
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
[452] Fix | Delete
/**
[453] Fix | Delete
* Plain custom HTML block is parsed as block with an empty blockName with a filled innerHTML.
[454] Fix | Delete
*
[455] Fix | Delete
* @param array $block Parse block.
[456] Fix | Delete
* @return bool
[457] Fix | Delete
*/
[458] Fix | Delete
private static function is_custom_html( $block ) {
[459] Fix | Delete
return empty( $block['blockName'] ) && ! empty( $block['innerHTML'] );
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
/**
[463] Fix | Delete
* Serialize template.
[464] Fix | Delete
*
[465] Fix | Delete
* @param array $parsed_blocks Parsed blocks.
[466] Fix | Delete
* @return string
[467] Fix | Delete
*/
[468] Fix | Delete
private static function serialize_blocks( $parsed_blocks ) {
[469] Fix | Delete
return array_reduce(
[470] Fix | Delete
$parsed_blocks,
[471] Fix | Delete
function ( $carry, $item ) {
[472] Fix | Delete
if ( is_array( $item ) ) {
[473] Fix | Delete
return $carry . serialize_blocks( $item );
[474] Fix | Delete
}
[475] Fix | Delete
return $carry . serialize_block( $item );
[476] Fix | Delete
},
[477] Fix | Delete
''
[478] Fix | Delete
);
[479] Fix | Delete
}
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function