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.../blocks
File: navigation.php
* Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object,
[1500] Fix | Delete
* this function inserts hooked blocks into it, and returns the serialized inner blocks in a
[1501] Fix | Delete
* mock Navigation block wrapper.
[1502] Fix | Delete
*
[1503] Fix | Delete
* If there are any hooked blocks that need to be inserted as the Navigation block's first or last
[1504] Fix | Delete
* children, the `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is checked to see if any
[1505] Fix | Delete
* of those hooked blocks should be exempted from insertion.
[1506] Fix | Delete
*
[1507] Fix | Delete
* @since 6.5.0
[1508] Fix | Delete
*
[1509] Fix | Delete
* @param array $inner_blocks Parsed inner blocks of a Navigation block.
[1510] Fix | Delete
* @param WP_Post $post `wp_navigation` post object corresponding to the block.
[1511] Fix | Delete
* @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any.
[1512] Fix | Delete
*/
[1513] Fix | Delete
function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
[1514] Fix | Delete
$mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );
[1515] Fix | Delete
$hooked_blocks = get_hooked_blocks();
[1516] Fix | Delete
$before_block_visitor = null;
[1517] Fix | Delete
$after_block_visitor = null;
[1518] Fix | Delete
[1519] Fix | Delete
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
[1520] Fix | Delete
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
[1521] Fix | Delete
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
[1522] Fix | Delete
}
[1523] Fix | Delete
[1524] Fix | Delete
return traverse_and_serialize_block( $mock_navigation_block, $before_block_visitor, $after_block_visitor );
[1525] Fix | Delete
}
[1526] Fix | Delete
[1527] Fix | Delete
/**
[1528] Fix | Delete
* Insert ignoredHookedBlocks meta into the Navigation block and its inner blocks.
[1529] Fix | Delete
*
[1530] Fix | Delete
* Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object,
[1531] Fix | Delete
* this function inserts ignoredHookedBlocks meta into it, and returns the serialized inner blocks in a
[1532] Fix | Delete
* mock Navigation block wrapper.
[1533] Fix | Delete
*
[1534] Fix | Delete
* @since 6.5.0
[1535] Fix | Delete
*
[1536] Fix | Delete
* @param array $inner_blocks Parsed inner blocks of a Navigation block.
[1537] Fix | Delete
* @param WP_Post $post `wp_navigation` post object corresponding to the block.
[1538] Fix | Delete
* @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any.
[1539] Fix | Delete
*/
[1540] Fix | Delete
function block_core_navigation_set_ignored_hooked_blocks_metadata( $inner_blocks, $post ) {
[1541] Fix | Delete
$mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );
[1542] Fix | Delete
$hooked_blocks = get_hooked_blocks();
[1543] Fix | Delete
$before_block_visitor = null;
[1544] Fix | Delete
$after_block_visitor = null;
[1545] Fix | Delete
[1546] Fix | Delete
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
[1547] Fix | Delete
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $post, 'set_ignored_hooked_blocks_metadata' );
[1548] Fix | Delete
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $post, 'set_ignored_hooked_blocks_metadata' );
[1549] Fix | Delete
}
[1550] Fix | Delete
[1551] Fix | Delete
return traverse_and_serialize_block( $mock_navigation_block, $before_block_visitor, $after_block_visitor );
[1552] Fix | Delete
}
[1553] Fix | Delete
[1554] Fix | Delete
/**
[1555] Fix | Delete
* Updates the post meta with the list of ignored hooked blocks when the navigation is created or updated via the REST API.
[1556] Fix | Delete
*
[1557] Fix | Delete
* @access private
[1558] Fix | Delete
* @since 6.5.0
[1559] Fix | Delete
*
[1560] Fix | Delete
* @param stdClass $post Post object.
[1561] Fix | Delete
* @return stdClass The updated post object.
[1562] Fix | Delete
*/
[1563] Fix | Delete
function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
[1564] Fix | Delete
/*
[1565] Fix | Delete
* In this scenario the user has likely tried to create a navigation via the REST API.
[1566] Fix | Delete
* In which case we won't have a post ID to work with and store meta against.
[1567] Fix | Delete
*/
[1568] Fix | Delete
if ( empty( $post->ID ) ) {
[1569] Fix | Delete
return $post;
[1570] Fix | Delete
}
[1571] Fix | Delete
[1572] Fix | Delete
/**
[1573] Fix | Delete
* Skip meta generation when consumers intentionally update specific Navigation fields
[1574] Fix | Delete
* and omit the content update.
[1575] Fix | Delete
*/
[1576] Fix | Delete
if ( ! isset( $post->post_content ) ) {
[1577] Fix | Delete
return $post;
[1578] Fix | Delete
}
[1579] Fix | Delete
[1580] Fix | Delete
/*
[1581] Fix | Delete
* We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
[1582] Fix | Delete
* all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
[1583] Fix | Delete
*/
[1584] Fix | Delete
$blocks = parse_blocks( $post->post_content );
[1585] Fix | Delete
[1586] Fix | Delete
/*
[1587] Fix | Delete
* Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that
[1588] Fix | Delete
* we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be
[1589] Fix | Delete
* used as context for hooked blocks insertion).
[1590] Fix | Delete
* We thus have to look it up from the DB,based on `$post->ID`.
[1591] Fix | Delete
*/
[1592] Fix | Delete
$markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, get_post( $post->ID ) );
[1593] Fix | Delete
[1594] Fix | Delete
$root_nav_block = parse_blocks( $markup )[0];
[1595] Fix | Delete
$ignored_hooked_blocks = isset( $root_nav_block['attrs']['metadata']['ignoredHookedBlocks'] )
[1596] Fix | Delete
? $root_nav_block['attrs']['metadata']['ignoredHookedBlocks']
[1597] Fix | Delete
: array();
[1598] Fix | Delete
[1599] Fix | Delete
if ( ! empty( $ignored_hooked_blocks ) ) {
[1600] Fix | Delete
$existing_ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true );
[1601] Fix | Delete
if ( ! empty( $existing_ignored_hooked_blocks ) ) {
[1602] Fix | Delete
$existing_ignored_hooked_blocks = json_decode( $existing_ignored_hooked_blocks, true );
[1603] Fix | Delete
$ignored_hooked_blocks = array_unique( array_merge( $ignored_hooked_blocks, $existing_ignored_hooked_blocks ) );
[1604] Fix | Delete
}
[1605] Fix | Delete
update_post_meta( $post->ID, '_wp_ignored_hooked_blocks', json_encode( $ignored_hooked_blocks ) );
[1606] Fix | Delete
}
[1607] Fix | Delete
[1608] Fix | Delete
$post->post_content = block_core_navigation_remove_serialized_parent_block( $markup );
[1609] Fix | Delete
return $post;
[1610] Fix | Delete
}
[1611] Fix | Delete
[1612] Fix | Delete
/*
[1613] Fix | Delete
* Before adding our filter, we verify if it's already added in Core.
[1614] Fix | Delete
* However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
[1615] Fix | Delete
* Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
[1616] Fix | Delete
*/
[1617] Fix | Delete
$rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found
[1618] Fix | Delete
[1619] Fix | Delete
/*
[1620] Fix | Delete
* Do not add the `block_core_navigation_update_ignore_hooked_blocks_meta` filter in the following cases:
[1621] Fix | Delete
* - If Core has added the `update_ignored_hooked_blocks_postmeta` filter already (WP >= 6.6);
[1622] Fix | Delete
* - or if the `set_ignored_hooked_blocks_metadata` function is unavailable (which is required for the filter to work. It was introduced by WP 6.5 but is not present in Gutenberg's WP 6.5 compatibility layer);
[1623] Fix | Delete
* - or if the `$rest_insert_wp_navigation_core_callback` filter has already been added.
[1624] Fix | Delete
*/
[1625] Fix | Delete
if (
[1626] Fix | Delete
! has_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' ) &&
[1627] Fix | Delete
function_exists( 'set_ignored_hooked_blocks_metadata' ) &&
[1628] Fix | Delete
! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback )
[1629] Fix | Delete
) {
[1630] Fix | Delete
add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta' );
[1631] Fix | Delete
}
[1632] Fix | Delete
[1633] Fix | Delete
/*
[1634] Fix | Delete
* Previous versions of Gutenberg were attaching the block_core_navigation_update_ignore_hooked_blocks_meta
[1635] Fix | Delete
* function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_).
[1636] Fix | Delete
* To avoid collisions, we need to remove the filter from that action if it's present.
[1637] Fix | Delete
*/
[1638] Fix | Delete
if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
[1639] Fix | Delete
remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback );
[1640] Fix | Delete
}
[1641] Fix | Delete
[1642] Fix | Delete
/**
[1643] Fix | Delete
* Hooks into the REST API response for the core/navigation block and adds the first and last inner blocks.
[1644] Fix | Delete
*
[1645] Fix | Delete
* @since 6.5.0
[1646] Fix | Delete
*
[1647] Fix | Delete
* @param WP_REST_Response $response The response object.
[1648] Fix | Delete
* @param WP_Post $post Post object.
[1649] Fix | Delete
* @return WP_REST_Response The response object.
[1650] Fix | Delete
*/
[1651] Fix | Delete
function block_core_navigation_insert_hooked_blocks_into_rest_response( $response, $post ) {
[1652] Fix | Delete
if ( ! isset( $response->data['content']['raw'] ) || ! isset( $response->data['content']['rendered'] ) ) {
[1653] Fix | Delete
return $response;
[1654] Fix | Delete
}
[1655] Fix | Delete
$parsed_blocks = parse_blocks( $response->data['content']['raw'] );
[1656] Fix | Delete
$content = block_core_navigation_insert_hooked_blocks( $parsed_blocks, $post );
[1657] Fix | Delete
[1658] Fix | Delete
// Remove mock Navigation block wrapper.
[1659] Fix | Delete
$content = block_core_navigation_remove_serialized_parent_block( $content );
[1660] Fix | Delete
[1661] Fix | Delete
$response->data['content']['raw'] = $content;
[1662] Fix | Delete
[1663] Fix | Delete
/** This filter is documented in wp-includes/post-template.php */
[1664] Fix | Delete
$response->data['content']['rendered'] = apply_filters( 'the_content', $content );
[1665] Fix | Delete
[1666] Fix | Delete
return $response;
[1667] Fix | Delete
}
[1668] Fix | Delete
[1669] Fix | Delete
/*
[1670] Fix | Delete
* Before adding our filter, we verify if it's already added in Core.
[1671] Fix | Delete
* However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
[1672] Fix | Delete
* Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
[1673] Fix | Delete
*/
[1674] Fix | Delete
$rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response';
[1675] Fix | Delete
[1676] Fix | Delete
/*
[1677] Fix | Delete
* Do not add the `block_core_navigation_insert_hooked_blocks_into_rest_response` filter in the following cases:
[1678] Fix | Delete
* - If Core has added the `insert_hooked_blocks_into_rest_response` filter already (WP >= 6.6);
[1679] Fix | Delete
* - or if the `set_ignored_hooked_blocks_metadata` function is unavailable (which is required for the filter to work. It was introduced by WP 6.5 but is not present in Gutenberg's WP 6.5 compatibility layer);
[1680] Fix | Delete
* - or if the `$rest_prepare_wp_navigation_core_callback` filter has already been added.
[1681] Fix | Delete
*/
[1682] Fix | Delete
if (
[1683] Fix | Delete
! has_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response' ) &&
[1684] Fix | Delete
function_exists( 'set_ignored_hooked_blocks_metadata' ) &&
[1685] Fix | Delete
! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback )
[1686] Fix | Delete
) {
[1687] Fix | Delete
add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
[1688] Fix | Delete
}
[1689] Fix | Delete
[1690] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function