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/wp-inclu...
File: blocks.php
dirname( $metadata['file'] ) . '/' .
[500] Fix | Delete
remove_block_asset_path_prefix( $metadata['render'] )
[501] Fix | Delete
)
[502] Fix | Delete
);
[503] Fix | Delete
if ( $template_path ) {
[504] Fix | Delete
/**
[505] Fix | Delete
* Renders the block on the server.
[506] Fix | Delete
*
[507] Fix | Delete
* @since 6.1.0
[508] Fix | Delete
*
[509] Fix | Delete
* @param array $attributes Block attributes.
[510] Fix | Delete
* @param string $content Block default content.
[511] Fix | Delete
* @param WP_Block $block Block instance.
[512] Fix | Delete
*
[513] Fix | Delete
* @return string Returns the block content.
[514] Fix | Delete
*/
[515] Fix | Delete
$settings['render_callback'] = static function ( $attributes, $content, $block ) use ( $template_path ) {
[516] Fix | Delete
ob_start();
[517] Fix | Delete
require $template_path;
[518] Fix | Delete
return ob_get_clean();
[519] Fix | Delete
};
[520] Fix | Delete
}
[521] Fix | Delete
}
[522] Fix | Delete
[523] Fix | Delete
$settings = array_merge( $settings, $args );
[524] Fix | Delete
[525] Fix | Delete
$script_fields = array(
[526] Fix | Delete
'editorScript' => 'editor_script_handles',
[527] Fix | Delete
'script' => 'script_handles',
[528] Fix | Delete
'viewScript' => 'view_script_handles',
[529] Fix | Delete
);
[530] Fix | Delete
foreach ( $script_fields as $metadata_field_name => $settings_field_name ) {
[531] Fix | Delete
if ( ! empty( $settings[ $metadata_field_name ] ) ) {
[532] Fix | Delete
$metadata[ $metadata_field_name ] = $settings[ $metadata_field_name ];
[533] Fix | Delete
}
[534] Fix | Delete
if ( ! empty( $metadata[ $metadata_field_name ] ) ) {
[535] Fix | Delete
$scripts = $metadata[ $metadata_field_name ];
[536] Fix | Delete
$processed_scripts = array();
[537] Fix | Delete
if ( is_array( $scripts ) ) {
[538] Fix | Delete
for ( $index = 0; $index < count( $scripts ); $index++ ) {
[539] Fix | Delete
$result = register_block_script_handle(
[540] Fix | Delete
$metadata,
[541] Fix | Delete
$metadata_field_name,
[542] Fix | Delete
$index
[543] Fix | Delete
);
[544] Fix | Delete
if ( $result ) {
[545] Fix | Delete
$processed_scripts[] = $result;
[546] Fix | Delete
}
[547] Fix | Delete
}
[548] Fix | Delete
} else {
[549] Fix | Delete
$result = register_block_script_handle(
[550] Fix | Delete
$metadata,
[551] Fix | Delete
$metadata_field_name
[552] Fix | Delete
);
[553] Fix | Delete
if ( $result ) {
[554] Fix | Delete
$processed_scripts[] = $result;
[555] Fix | Delete
}
[556] Fix | Delete
}
[557] Fix | Delete
$settings[ $settings_field_name ] = $processed_scripts;
[558] Fix | Delete
}
[559] Fix | Delete
}
[560] Fix | Delete
[561] Fix | Delete
$module_fields = array(
[562] Fix | Delete
'viewScriptModule' => 'view_script_module_ids',
[563] Fix | Delete
);
[564] Fix | Delete
foreach ( $module_fields as $metadata_field_name => $settings_field_name ) {
[565] Fix | Delete
if ( ! empty( $settings[ $metadata_field_name ] ) ) {
[566] Fix | Delete
$metadata[ $metadata_field_name ] = $settings[ $metadata_field_name ];
[567] Fix | Delete
}
[568] Fix | Delete
if ( ! empty( $metadata[ $metadata_field_name ] ) ) {
[569] Fix | Delete
$modules = $metadata[ $metadata_field_name ];
[570] Fix | Delete
$processed_modules = array();
[571] Fix | Delete
if ( is_array( $modules ) ) {
[572] Fix | Delete
for ( $index = 0; $index < count( $modules ); $index++ ) {
[573] Fix | Delete
$result = register_block_script_module_id(
[574] Fix | Delete
$metadata,
[575] Fix | Delete
$metadata_field_name,
[576] Fix | Delete
$index
[577] Fix | Delete
);
[578] Fix | Delete
if ( $result ) {
[579] Fix | Delete
$processed_modules[] = $result;
[580] Fix | Delete
}
[581] Fix | Delete
}
[582] Fix | Delete
} else {
[583] Fix | Delete
$result = register_block_script_module_id(
[584] Fix | Delete
$metadata,
[585] Fix | Delete
$metadata_field_name
[586] Fix | Delete
);
[587] Fix | Delete
if ( $result ) {
[588] Fix | Delete
$processed_modules[] = $result;
[589] Fix | Delete
}
[590] Fix | Delete
}
[591] Fix | Delete
$settings[ $settings_field_name ] = $processed_modules;
[592] Fix | Delete
}
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
$style_fields = array(
[596] Fix | Delete
'editorStyle' => 'editor_style_handles',
[597] Fix | Delete
'style' => 'style_handles',
[598] Fix | Delete
'viewStyle' => 'view_style_handles',
[599] Fix | Delete
);
[600] Fix | Delete
foreach ( $style_fields as $metadata_field_name => $settings_field_name ) {
[601] Fix | Delete
if ( ! empty( $settings[ $metadata_field_name ] ) ) {
[602] Fix | Delete
$metadata[ $metadata_field_name ] = $settings[ $metadata_field_name ];
[603] Fix | Delete
}
[604] Fix | Delete
if ( ! empty( $metadata[ $metadata_field_name ] ) ) {
[605] Fix | Delete
$styles = $metadata[ $metadata_field_name ];
[606] Fix | Delete
$processed_styles = array();
[607] Fix | Delete
if ( is_array( $styles ) ) {
[608] Fix | Delete
for ( $index = 0; $index < count( $styles ); $index++ ) {
[609] Fix | Delete
$result = register_block_style_handle(
[610] Fix | Delete
$metadata,
[611] Fix | Delete
$metadata_field_name,
[612] Fix | Delete
$index
[613] Fix | Delete
);
[614] Fix | Delete
if ( $result ) {
[615] Fix | Delete
$processed_styles[] = $result;
[616] Fix | Delete
}
[617] Fix | Delete
}
[618] Fix | Delete
} else {
[619] Fix | Delete
$result = register_block_style_handle(
[620] Fix | Delete
$metadata,
[621] Fix | Delete
$metadata_field_name
[622] Fix | Delete
);
[623] Fix | Delete
if ( $result ) {
[624] Fix | Delete
$processed_styles[] = $result;
[625] Fix | Delete
}
[626] Fix | Delete
}
[627] Fix | Delete
$settings[ $settings_field_name ] = $processed_styles;
[628] Fix | Delete
}
[629] Fix | Delete
}
[630] Fix | Delete
[631] Fix | Delete
if ( ! empty( $metadata['blockHooks'] ) ) {
[632] Fix | Delete
/**
[633] Fix | Delete
* Map camelCased position string (from block.json) to snake_cased block type position.
[634] Fix | Delete
*
[635] Fix | Delete
* @var array
[636] Fix | Delete
*/
[637] Fix | Delete
$position_mappings = array(
[638] Fix | Delete
'before' => 'before',
[639] Fix | Delete
'after' => 'after',
[640] Fix | Delete
'firstChild' => 'first_child',
[641] Fix | Delete
'lastChild' => 'last_child',
[642] Fix | Delete
);
[643] Fix | Delete
[644] Fix | Delete
$settings['block_hooks'] = array();
[645] Fix | Delete
foreach ( $metadata['blockHooks'] as $anchor_block_name => $position ) {
[646] Fix | Delete
// Avoid infinite recursion (hooking to itself).
[647] Fix | Delete
if ( $metadata['name'] === $anchor_block_name ) {
[648] Fix | Delete
_doing_it_wrong(
[649] Fix | Delete
__METHOD__,
[650] Fix | Delete
__( 'Cannot hook block to itself.' ),
[651] Fix | Delete
'6.4.0'
[652] Fix | Delete
);
[653] Fix | Delete
continue;
[654] Fix | Delete
}
[655] Fix | Delete
[656] Fix | Delete
if ( ! isset( $position_mappings[ $position ] ) ) {
[657] Fix | Delete
continue;
[658] Fix | Delete
}
[659] Fix | Delete
[660] Fix | Delete
$settings['block_hooks'][ $anchor_block_name ] = $position_mappings[ $position ];
[661] Fix | Delete
}
[662] Fix | Delete
}
[663] Fix | Delete
[664] Fix | Delete
/**
[665] Fix | Delete
* Filters the settings determined from the block type metadata.
[666] Fix | Delete
*
[667] Fix | Delete
* @since 5.7.0
[668] Fix | Delete
*
[669] Fix | Delete
* @param array $settings Array of determined settings for registering a block type.
[670] Fix | Delete
* @param array $metadata Metadata provided for registering a block type.
[671] Fix | Delete
*/
[672] Fix | Delete
$settings = apply_filters( 'block_type_metadata_settings', $settings, $metadata );
[673] Fix | Delete
[674] Fix | Delete
$metadata['name'] = ! empty( $settings['name'] ) ? $settings['name'] : $metadata['name'];
[675] Fix | Delete
[676] Fix | Delete
return WP_Block_Type_Registry::get_instance()->register(
[677] Fix | Delete
$metadata['name'],
[678] Fix | Delete
$settings
[679] Fix | Delete
);
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
/**
[683] Fix | Delete
* Registers a block type. The recommended way is to register a block type using
[684] Fix | Delete
* the metadata stored in the `block.json` file.
[685] Fix | Delete
*
[686] Fix | Delete
* @since 5.0.0
[687] Fix | Delete
* @since 5.8.0 First parameter now accepts a path to the `block.json` file.
[688] Fix | Delete
*
[689] Fix | Delete
* @param string|WP_Block_Type $block_type Block type name including namespace, or alternatively
[690] Fix | Delete
* a path to the JSON file with metadata definition for the block,
[691] Fix | Delete
* or a path to the folder where the `block.json` file is located,
[692] Fix | Delete
* or a complete WP_Block_Type instance.
[693] Fix | Delete
* In case a WP_Block_Type is provided, the $args parameter will be ignored.
[694] Fix | Delete
* @param array $args Optional. Array of block type arguments. Accepts any public property
[695] Fix | Delete
* of `WP_Block_Type`. See WP_Block_Type::__construct() for information
[696] Fix | Delete
* on accepted arguments. Default empty array.
[697] Fix | Delete
*
[698] Fix | Delete
* @return WP_Block_Type|false The registered block type on success, or false on failure.
[699] Fix | Delete
*/
[700] Fix | Delete
function register_block_type( $block_type, $args = array() ) {
[701] Fix | Delete
if ( is_string( $block_type ) && file_exists( $block_type ) ) {
[702] Fix | Delete
return register_block_type_from_metadata( $block_type, $args );
[703] Fix | Delete
}
[704] Fix | Delete
[705] Fix | Delete
return WP_Block_Type_Registry::get_instance()->register( $block_type, $args );
[706] Fix | Delete
}
[707] Fix | Delete
[708] Fix | Delete
/**
[709] Fix | Delete
* Unregisters a block type.
[710] Fix | Delete
*
[711] Fix | Delete
* @since 5.0.0
[712] Fix | Delete
*
[713] Fix | Delete
* @param string|WP_Block_Type $name Block type name including namespace, or alternatively
[714] Fix | Delete
* a complete WP_Block_Type instance.
[715] Fix | Delete
* @return WP_Block_Type|false The unregistered block type on success, or false on failure.
[716] Fix | Delete
*/
[717] Fix | Delete
function unregister_block_type( $name ) {
[718] Fix | Delete
return WP_Block_Type_Registry::get_instance()->unregister( $name );
[719] Fix | Delete
}
[720] Fix | Delete
[721] Fix | Delete
/**
[722] Fix | Delete
* Determines whether a post or content string has blocks.
[723] Fix | Delete
*
[724] Fix | Delete
* This test optimizes for performance rather than strict accuracy, detecting
[725] Fix | Delete
* the pattern of a block but not validating its structure. For strict accuracy,
[726] Fix | Delete
* you should use the block parser on post content.
[727] Fix | Delete
*
[728] Fix | Delete
* @since 5.0.0
[729] Fix | Delete
*
[730] Fix | Delete
* @see parse_blocks()
[731] Fix | Delete
*
[732] Fix | Delete
* @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object.
[733] Fix | Delete
* Defaults to global $post.
[734] Fix | Delete
* @return bool Whether the post has blocks.
[735] Fix | Delete
*/
[736] Fix | Delete
function has_blocks( $post = null ) {
[737] Fix | Delete
if ( ! is_string( $post ) ) {
[738] Fix | Delete
$wp_post = get_post( $post );
[739] Fix | Delete
[740] Fix | Delete
if ( ! $wp_post instanceof WP_Post ) {
[741] Fix | Delete
return false;
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
$post = $wp_post->post_content;
[745] Fix | Delete
}
[746] Fix | Delete
[747] Fix | Delete
return str_contains( (string) $post, '<!-- wp:' );
[748] Fix | Delete
}
[749] Fix | Delete
[750] Fix | Delete
/**
[751] Fix | Delete
* Determines whether a $post or a string contains a specific block type.
[752] Fix | Delete
*
[753] Fix | Delete
* This test optimizes for performance rather than strict accuracy, detecting
[754] Fix | Delete
* whether the block type exists but not validating its structure and not checking
[755] Fix | Delete
* synced patterns (formerly called reusable blocks). For strict accuracy,
[756] Fix | Delete
* you should use the block parser on post content.
[757] Fix | Delete
*
[758] Fix | Delete
* @since 5.0.0
[759] Fix | Delete
*
[760] Fix | Delete
* @see parse_blocks()
[761] Fix | Delete
*
[762] Fix | Delete
* @param string $block_name Full block type to look for.
[763] Fix | Delete
* @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object.
[764] Fix | Delete
* Defaults to global $post.
[765] Fix | Delete
* @return bool Whether the post content contains the specified block.
[766] Fix | Delete
*/
[767] Fix | Delete
function has_block( $block_name, $post = null ) {
[768] Fix | Delete
if ( ! has_blocks( $post ) ) {
[769] Fix | Delete
return false;
[770] Fix | Delete
}
[771] Fix | Delete
[772] Fix | Delete
if ( ! is_string( $post ) ) {
[773] Fix | Delete
$wp_post = get_post( $post );
[774] Fix | Delete
if ( $wp_post instanceof WP_Post ) {
[775] Fix | Delete
$post = $wp_post->post_content;
[776] Fix | Delete
}
[777] Fix | Delete
}
[778] Fix | Delete
[779] Fix | Delete
/*
[780] Fix | Delete
* Normalize block name to include namespace, if provided as non-namespaced.
[781] Fix | Delete
* This matches behavior for WordPress 5.0.0 - 5.3.0 in matching blocks by
[782] Fix | Delete
* their serialized names.
[783] Fix | Delete
*/
[784] Fix | Delete
if ( ! str_contains( $block_name, '/' ) ) {
[785] Fix | Delete
$block_name = 'core/' . $block_name;
[786] Fix | Delete
}
[787] Fix | Delete
[788] Fix | Delete
// Test for existence of block by its fully qualified name.
[789] Fix | Delete
$has_block = str_contains( $post, '<!-- wp:' . $block_name . ' ' );
[790] Fix | Delete
[791] Fix | Delete
if ( ! $has_block ) {
[792] Fix | Delete
/*
[793] Fix | Delete
* If the given block name would serialize to a different name, test for
[794] Fix | Delete
* existence by the serialized form.
[795] Fix | Delete
*/
[796] Fix | Delete
$serialized_block_name = strip_core_block_namespace( $block_name );
[797] Fix | Delete
if ( $serialized_block_name !== $block_name ) {
[798] Fix | Delete
$has_block = str_contains( $post, '<!-- wp:' . $serialized_block_name . ' ' );
[799] Fix | Delete
}
[800] Fix | Delete
}
[801] Fix | Delete
[802] Fix | Delete
return $has_block;
[803] Fix | Delete
}
[804] Fix | Delete
[805] Fix | Delete
/**
[806] Fix | Delete
* Returns an array of the names of all registered dynamic block types.
[807] Fix | Delete
*
[808] Fix | Delete
* @since 5.0.0
[809] Fix | Delete
*
[810] Fix | Delete
* @return string[] Array of dynamic block names.
[811] Fix | Delete
*/
[812] Fix | Delete
function get_dynamic_block_names() {
[813] Fix | Delete
$dynamic_block_names = array();
[814] Fix | Delete
[815] Fix | Delete
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
[816] Fix | Delete
foreach ( $block_types as $block_type ) {
[817] Fix | Delete
if ( $block_type->is_dynamic() ) {
[818] Fix | Delete
$dynamic_block_names[] = $block_type->name;
[819] Fix | Delete
}
[820] Fix | Delete
}
[821] Fix | Delete
[822] Fix | Delete
return $dynamic_block_names;
[823] Fix | Delete
}
[824] Fix | Delete
[825] Fix | Delete
/**
[826] Fix | Delete
* Retrieves block types hooked into the given block, grouped by anchor block type and the relative position.
[827] Fix | Delete
*
[828] Fix | Delete
* @since 6.4.0
[829] Fix | Delete
*
[830] Fix | Delete
* @return array[] Array of block types grouped by anchor block type and the relative position.
[831] Fix | Delete
*/
[832] Fix | Delete
function get_hooked_blocks() {
[833] Fix | Delete
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
[834] Fix | Delete
$hooked_blocks = array();
[835] Fix | Delete
foreach ( $block_types as $block_type ) {
[836] Fix | Delete
if ( ! ( $block_type instanceof WP_Block_Type ) || ! is_array( $block_type->block_hooks ) ) {
[837] Fix | Delete
continue;
[838] Fix | Delete
}
[839] Fix | Delete
foreach ( $block_type->block_hooks as $anchor_block_type => $relative_position ) {
[840] Fix | Delete
if ( ! isset( $hooked_blocks[ $anchor_block_type ] ) ) {
[841] Fix | Delete
$hooked_blocks[ $anchor_block_type ] = array();
[842] Fix | Delete
}
[843] Fix | Delete
if ( ! isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) ) {
[844] Fix | Delete
$hooked_blocks[ $anchor_block_type ][ $relative_position ] = array();
[845] Fix | Delete
}
[846] Fix | Delete
$hooked_blocks[ $anchor_block_type ][ $relative_position ][] = $block_type->name;
[847] Fix | Delete
}
[848] Fix | Delete
}
[849] Fix | Delete
[850] Fix | Delete
return $hooked_blocks;
[851] Fix | Delete
}
[852] Fix | Delete
[853] Fix | Delete
/**
[854] Fix | Delete
* Returns the markup for blocks hooked to the given anchor block in a specific relative position.
[855] Fix | Delete
*
[856] Fix | Delete
* @since 6.5.0
[857] Fix | Delete
* @access private
[858] Fix | Delete
*
[859] Fix | Delete
* @param array $parsed_anchor_block The anchor block, in parsed block array format.
[860] Fix | Delete
* @param string $relative_position The relative position of the hooked blocks.
[861] Fix | Delete
* Can be one of 'before', 'after', 'first_child', or 'last_child'.
[862] Fix | Delete
* @param array $hooked_blocks An array of hooked block types, grouped by anchor block and relative position.
[863] Fix | Delete
* @param WP_Block_Template|WP_Post|array $context The block template, template part, or pattern that the anchor block belongs to.
[864] Fix | Delete
* @return string
[865] Fix | Delete
*/
[866] Fix | Delete
function insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) {
[867] Fix | Delete
$anchor_block_type = $parsed_anchor_block['blockName'];
[868] Fix | Delete
$hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
[869] Fix | Delete
? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
[870] Fix | Delete
: array();
[871] Fix | Delete
[872] Fix | Delete
/**
[873] Fix | Delete
* Filters the list of hooked block types for a given anchor block type and relative position.
[874] Fix | Delete
*
[875] Fix | Delete
* @since 6.4.0
[876] Fix | Delete
*
[877] Fix | Delete
* @param string[] $hooked_block_types The list of hooked block types.
[878] Fix | Delete
* @param string $relative_position The relative position of the hooked blocks.
[879] Fix | Delete
* Can be one of 'before', 'after', 'first_child', or 'last_child'.
[880] Fix | Delete
* @param string $anchor_block_type The anchor block type.
[881] Fix | Delete
* @param WP_Block_Template|WP_Post|array $context The block template, template part, `wp_navigation` post type,
[882] Fix | Delete
* or pattern that the anchor block belongs to.
[883] Fix | Delete
*/
[884] Fix | Delete
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
[885] Fix | Delete
[886] Fix | Delete
$markup = '';
[887] Fix | Delete
foreach ( $hooked_block_types as $hooked_block_type ) {
[888] Fix | Delete
$parsed_hooked_block = array(
[889] Fix | Delete
'blockName' => $hooked_block_type,
[890] Fix | Delete
'attrs' => array(),
[891] Fix | Delete
'innerBlocks' => array(),
[892] Fix | Delete
'innerContent' => array(),
[893] Fix | Delete
);
[894] Fix | Delete
[895] Fix | Delete
/**
[896] Fix | Delete
* Filters the parsed block array for a given hooked block.
[897] Fix | Delete
*
[898] Fix | Delete
* @since 6.5.0
[899] Fix | Delete
*
[900] Fix | Delete
* @param array|null $parsed_hooked_block The parsed block array for the given hooked block type, or null to suppress the block.
[901] Fix | Delete
* @param string $hooked_block_type The hooked block type name.
[902] Fix | Delete
* @param string $relative_position The relative position of the hooked block.
[903] Fix | Delete
* @param array $parsed_anchor_block The anchor block, in parsed block array format.
[904] Fix | Delete
* @param WP_Block_Template|WP_Post|array $context The block template, template part, `wp_navigation` post type,
[905] Fix | Delete
* or pattern that the anchor block belongs to.
[906] Fix | Delete
*/
[907] Fix | Delete
$parsed_hooked_block = apply_filters( 'hooked_block', $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
[908] Fix | Delete
[909] Fix | Delete
/**
[910] Fix | Delete
* Filters the parsed block array for a given hooked block.
[911] Fix | Delete
*
[912] Fix | Delete
* The dynamic portion of the hook name, `$hooked_block_type`, refers to the block type name of the specific hooked block.
[913] Fix | Delete
*
[914] Fix | Delete
* @since 6.5.0
[915] Fix | Delete
*
[916] Fix | Delete
* @param array|null $parsed_hooked_block The parsed block array for the given hooked block type, or null to suppress the block.
[917] Fix | Delete
* @param string $hooked_block_type The hooked block type name.
[918] Fix | Delete
* @param string $relative_position The relative position of the hooked block.
[919] Fix | Delete
* @param array $parsed_anchor_block The anchor block, in parsed block array format.
[920] Fix | Delete
* @param WP_Block_Template|WP_Post|array $context The block template, template part, `wp_navigation` post type,
[921] Fix | Delete
* or pattern that the anchor block belongs to.
[922] Fix | Delete
*/
[923] Fix | Delete
$parsed_hooked_block = apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
[924] Fix | Delete
[925] Fix | Delete
if ( null === $parsed_hooked_block ) {
[926] Fix | Delete
continue;
[927] Fix | Delete
}
[928] Fix | Delete
[929] Fix | Delete
// It's possible that the filter returned a block of a different type, so we explicitly
[930] Fix | Delete
// look for the original `$hooked_block_type` in the `ignoredHookedBlocks` metadata.
[931] Fix | Delete
if (
[932] Fix | Delete
! isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ||
[933] Fix | Delete
! in_array( $hooked_block_type, $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'], true )
[934] Fix | Delete
) {
[935] Fix | Delete
$markup .= serialize_block( $parsed_hooked_block );
[936] Fix | Delete
}
[937] Fix | Delete
}
[938] Fix | Delete
[939] Fix | Delete
return $markup;
[940] Fix | Delete
}
[941] Fix | Delete
[942] Fix | Delete
/**
[943] Fix | Delete
* Adds a list of hooked block types to an anchor block's ignored hooked block types.
[944] Fix | Delete
*
[945] Fix | Delete
* This function is meant for internal use only.
[946] Fix | Delete
*
[947] Fix | Delete
* @since 6.5.0
[948] Fix | Delete
* @access private
[949] Fix | Delete
*
[950] Fix | Delete
* @param array $parsed_anchor_block The anchor block, in parsed block array format.
[951] Fix | Delete
* @param string $relative_position The relative position of the hooked blocks.
[952] Fix | Delete
* Can be one of 'before', 'after', 'first_child', or 'last_child'.
[953] Fix | Delete
* @param array $hooked_blocks An array of hooked block types, grouped by anchor block and relative position.
[954] Fix | Delete
* @param WP_Block_Template|WP_Post|array $context The block template, template part, or pattern that the anchor block belongs to.
[955] Fix | Delete
* @return string Empty string.
[956] Fix | Delete
*/
[957] Fix | Delete
function set_ignored_hooked_blocks_metadata( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) {
[958] Fix | Delete
$anchor_block_type = $parsed_anchor_block['blockName'];
[959] Fix | Delete
$hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
[960] Fix | Delete
? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
[961] Fix | Delete
: array();
[962] Fix | Delete
[963] Fix | Delete
/** This filter is documented in wp-includes/blocks.php */
[964] Fix | Delete
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
[965] Fix | Delete
if ( empty( $hooked_block_types ) ) {
[966] Fix | Delete
return '';
[967] Fix | Delete
}
[968] Fix | Delete
[969] Fix | Delete
foreach ( $hooked_block_types as $index => $hooked_block_type ) {
[970] Fix | Delete
$parsed_hooked_block = array(
[971] Fix | Delete
'blockName' => $hooked_block_type,
[972] Fix | Delete
'attrs' => array(),
[973] Fix | Delete
'innerBlocks' => array(),
[974] Fix | Delete
'innerContent' => array(),
[975] Fix | Delete
);
[976] Fix | Delete
[977] Fix | Delete
/** This filter is documented in wp-includes/blocks.php */
[978] Fix | Delete
$parsed_hooked_block = apply_filters( 'hooked_block', $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
[979] Fix | Delete
[980] Fix | Delete
/** This filter is documented in wp-includes/blocks.php */
[981] Fix | Delete
$parsed_hooked_block = apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
[982] Fix | Delete
[983] Fix | Delete
if ( null === $parsed_hooked_block ) {
[984] Fix | Delete
unset( $hooked_block_types[ $index ] );
[985] Fix | Delete
}
[986] Fix | Delete
}
[987] Fix | Delete
[988] Fix | Delete
$previously_ignored_hooked_blocks = isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] )
[989] Fix | Delete
? $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks']
[990] Fix | Delete
: array();
[991] Fix | Delete
[992] Fix | Delete
$parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array_unique(
[993] Fix | Delete
array_merge(
[994] Fix | Delete
$previously_ignored_hooked_blocks,
[995] Fix | Delete
$hooked_block_types
[996] Fix | Delete
)
[997] Fix | Delete
);
[998] Fix | Delete
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function