Make WordPress Core


Ignore:
Timestamp:
01/29/2024 09:04:18 PM (7 months ago)
Author:
youknowriad
Message:

Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.

This patch, somewhat small brings a lot to WordPress.
This includes features like:

  • DataViews.
  • Customization tools like box shadow, background size and repeat.
  • UI improvements in the site editor.
  • Preferences sharing between the post and site editors.
  • Unified panels and editors between post and site editors.
  • Improved template mode in the post editor.
  • Iterations to multiple interactive blocks.
  • Preparing the blocks and UI for pattern overrides.
  • and a lot more.

Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.

File:
1 edited

Legend:

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

    r56065 r57377  
    11<?php
    22/**
    3  * Server-side rendering of the `core/navigation-link` block.
     3 * Server-side registering and rendering of the `core/navigation-link` block.
    44 *
    55 * @package WordPress
     
    324324
    325325/**
     326 * Register a variation for a post type / taxonomy for the navigation link block.
     327 *
     328 * @param array $variation Variation array from build_variation_for_navigation_link.
     329 * @return void
     330 */
     331function block_core_navigation_link_register_variation( $variation ) {
     332    // Directly set the variations on the registered block type
     333    // because there's no server side registration for variations (see #47170).
     334    $navigation_block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' );
     335    // If the block is not registered yet, bail early.
     336    // Variation will be registered in register_block_core_navigation_link then.
     337    if ( ! $navigation_block_type ) {
     338        return;
     339    }
     340
     341    $navigation_block_type->variations = array_merge(
     342        $navigation_block_type->variations,
     343        array( $variation )
     344    );
     345}
     346
     347/**
     348 * Unregister a variation for a post type / taxonomy for the navigation link block.
     349 *
     350 * @param string $name Name of the post type / taxonomy (which was used as variation name).
     351 * @return void
     352 */
     353function block_core_navigation_link_unregister_variation( $name ) {
     354    // Directly get the variations from the registered block type
     355    // because there's no server side (un)registration for variations (see #47170).
     356    $navigation_block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' );
     357    // If the block is not registered (yet), there's no need to remove a variation.
     358    if ( ! $navigation_block_type || empty( $navigation_block_type->variations ) ) {
     359        return;
     360    }
     361    $variations = $navigation_block_type->variations;
     362    // Search for the variation and remove it from the array.
     363    foreach ( $variations as $i => $variation ) {
     364        if ( $variation['name'] === $name ) {
     365            unset( $variations[ $i ] );
     366            break;
     367        }
     368    }
     369    // Reindex array after removing one variation.
     370    $navigation_block_type->variations = array_values( $variations );
     371}
     372
     373/**
    326374 * Register the navigation link block.
    327  *
    328  * @uses render_block_core_navigation()
    329  * @throws WP_Error An WP_Error exception parsing the block definition.
    330  */
    331 function register_block_core_navigation_link() {
     375 * Returns an array of variations for the navigation link block.
     376 *
     377 * @return array
     378 */
     379function build_navigation_link_block_variations() {
     380    // This will only handle post types and taxonomies registered until this point (init on priority 9).
     381    // See action hooks below for other post types and taxonomies.
     382    // See https://github.com/WordPress/gutenberg/issues/53826 for details.
    332383    $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
    333384    $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' );
     
    361412    }
    362413
     414    return array_merge( $built_ins, $variations );
     415}
     416
     417/**
     418 * Register the navigation link block.
     419 *
     420 * @uses render_block_core_navigation()
     421 * @throws WP_Error An WP_Error exception parsing the block definition.
     422 */
     423function register_block_core_navigation_link() {
    363424    register_block_type_from_metadata(
    364425        __DIR__ . '/navigation-link',
    365426        array(
    366             'render_callback' => 'render_block_core_navigation_link',
    367             'variations'      => array_merge( $built_ins, $variations ),
     427            'render_callback'    => 'render_block_core_navigation_link',
     428            'variation_callback' => 'build_navigation_link_block_variations',
    368429        )
    369430    );
    370431}
    371432add_action( 'init', 'register_block_core_navigation_link' );
     433// Register actions for all post types and taxonomies, to add variations when they are registered.
     434// All post types/taxonomies registered before register_block_core_navigation_link, will be handled by that function.
     435add_action( 'registered_post_type', 'block_core_navigation_link_register_post_type_variation', 10, 2 );
     436add_action( 'registered_taxonomy', 'block_core_navigation_link_register_taxonomy_variation', 10, 3 );
     437// Handle unregistering of post types and taxonomies and remove the variations.
     438add_action( 'unregistered_post_type', 'block_core_navigation_link_unregister_post_type_variation' );
     439add_action( 'unregistered_taxonomy', 'block_core_navigation_link_unregister_taxonomy_variation' );
     440
     441/**
     442 * Register custom post type variations for navigation link on post type registration
     443 * Handles all post types registered after the block is registered in register_navigation_link_post_type_variations
     444 *
     445 * @param string       $post_type The post type name passed from registered_post_type action hook.
     446 * @param WP_Post_Type $post_type_object The post type object passed from registered_post_type.
     447 * @return void
     448 */
     449function block_core_navigation_link_register_post_type_variation( $post_type, $post_type_object ) {
     450    if ( $post_type_object->show_in_nav_menus ) {
     451        $variation = build_variation_for_navigation_link( $post_type_object, 'post-type' );
     452        block_core_navigation_link_register_variation( $variation );
     453    }
     454}
     455
     456/**
     457 * Register a custom taxonomy variation for navigation link on taxonomy registration
     458 * Handles all taxonomies registered after the block is registered in register_navigation_link_post_type_variations
     459 *
     460 * @param string       $taxonomy Taxonomy slug.
     461 * @param array|string $object_type Object type or array of object types.
     462 * @param array        $args Array of taxonomy registration arguments.
     463 * @return void
     464 */
     465function block_core_navigation_link_register_taxonomy_variation( $taxonomy, $object_type, $args ) {
     466    if ( isset( $args['show_in_nav_menus'] ) && $args['show_in_nav_menus'] ) {
     467        $variation = build_variation_for_navigation_link( (object) $args, 'post-type' );
     468        block_core_navigation_link_register_variation( $variation );
     469    }
     470}
     471
     472/**
     473 * Unregisters a custom post type variation for navigation link on post type unregistration.
     474 *
     475 * @param string $post_type The post type name passed from unregistered_post_type action hook.
     476 * @return void
     477 */
     478function block_core_navigation_link_unregister_post_type_variation( $post_type ) {
     479    block_core_navigation_link_unregister_variation( $post_type );
     480}
     481
     482/**
     483 * Unregisters a custom taxonomy variation for navigation link on taxonomy unregistration.
     484 *
     485 * @param string $taxonomy The taxonomy name passed from unregistered_taxonomy action hook.
     486 * @return void
     487 */
     488function block_core_navigation_link_unregister_taxonomy_variation( $taxonomy ) {
     489    block_core_navigation_link_unregister_variation( $taxonomy );
     490}
Note: See TracChangeset for help on using the changeset viewer.