Make WordPress Core


Ignore:
Timestamp:
03/12/2024 02:06:51 PM (15 months ago)
Author:
youknowriad
Message:

Editor: Update Packages with the latest bug fixes for 6.5 RC 2

It includes all the backports from this Gutenberg PR https://github.com/WordPress/gutenberg/pull/59756/

Props get_dave, swissspidy, bernhard-reiter, youknowriad.
See #60315.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/navigation.php

    r57760 r57814  
    544544     * Gets the nav element directives.
    545545     *
    546      * @param bool  $is_interactive Whether the block is interactive.
    547      * @param array $attributes     The block attributes.
     546     * @param bool $is_interactive Whether the block is interactive.
    548547     * @return string the directives for the navigation element.
    549548     */
     
    14591458 * Updates the post meta with the list of ignored hooked blocks when the navigation is created or updated via the REST API.
    14601459 *
    1461  * @param WP_Post $post Post object.
     1460 * @access private
     1461 * @since 6.5.0
     1462 *
     1463 * @param stdClass $post Post object.
     1464 * @return stdClass The updated post object.
    14621465 */
    14631466function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
    1464     // We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
    1465     // all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
     1467    /*
     1468     * We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
     1469     * all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
     1470     */
    14661471    $blocks = parse_blocks( $post->post_content );
    1467     $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, $post );
     1472
     1473    /*
     1474     * Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that
     1475     * we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be
     1476     * used as context for hooked blocks insertion).
     1477     * We thus have to look it up from the DB,based on `$post->ID`.
     1478     */
     1479    $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, get_post( $post->ID ) );
    14681480
    14691481    $root_nav_block        = parse_blocks( $markup )[0];
     
    14811493    }
    14821494
    1483     $serialized_inner_blocks = block_core_navigation_remove_serialized_parent_block( $markup );
    1484 
    1485     wp_update_post(
    1486         array(
    1487             'ID'           => $post->ID,
    1488             'post_content' => $serialized_inner_blocks,
    1489         )
    1490     );
    1491 }
    1492 
    1493 // Before adding our filter, we verify if it's already added in Core.
    1494 // However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
    1495 // Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
    1496 $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta';
    1497 
    1498 // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
    1499 // that are not present in Gutenberg's WP 6.5 compatibility layer.
    1500 if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
    1501     add_action( 'rest_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10, 3 );
     1495    $post->post_content = block_core_navigation_remove_serialized_parent_block( $markup );
     1496    return $post;
     1497}
     1498
     1499/*
     1500 * Before adding our filter, we verify if it's already added in Core.
     1501 * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
     1502 * Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
     1503 */
     1504$rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found
     1505
     1506/*
     1507 * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
     1508 * that are not present in Gutenberg's WP 6.5 compatibility layer.
     1509 */
     1510if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
     1511    add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta' );
     1512}
     1513
     1514/*
     1515 * Previous versions of Gutenberg were attaching the block_core_navigation_update_ignore_hooked_blocks_meta
     1516 * function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_).
     1517 * To avoid collisions, we need to remove the filter from that action if it's present.
     1518 */
     1519if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
     1520    remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback );
    15021521}
    15031522
     
    15071526 * @param WP_REST_Response $response The response object.
    15081527 * @param WP_Post          $post     Post object.
    1509  * @param WP_REST_Request  $request  Request object.
    15101528 * @return WP_REST_Response The response object.
    15111529 */
     
    15261544}
    15271545
    1528 // Before adding our filter, we verify if it's already added in Core.
    1529 // However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
    1530 // Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
     1546/*
     1547 *  Before adding our filter, we verify if it's already added in Core.
     1548 * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
     1549 * Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
     1550 */
    15311551$rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response';
    15321552
    1533 // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
    1534 // that are not present in Gutenberg's WP 6.5 compatibility layer.
     1553/*
     1554 * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
     1555 * that are not present in Gutenberg's WP 6.5 compatibility layer.
     1556 */
    15351557if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) {
    15361558    add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.