Make WordPress Core


Ignore:
Timestamp:
09/10/2022 12:37:00 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Editor: Backport Elements API updates.

This commit backports the original PRs from Gutenberg repository:

Props onemaggie, bernhard-reiter, cbravobernal, mmaattiiaass, scruffian, andraganescu, dpcalhoun, get_dave, Mamaduka, SergeyBiryukov.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r54079 r54118  
    23552355
    23562356/**
     2357 * Applies a filter to the list of style nodes that comes from WP_Theme_JSON::get_style_nodes().
     2358 *
     2359 * This particular filter removes all of the blocks from the array.
     2360 *
     2361 * We want WP_Theme_JSON to be ignorant of the implementation details of how the CSS is being used.
     2362 * This filter allows us to modify the output of WP_Theme_JSON depending on whether or not we are
     2363 * loading separate assets, without making the class aware of that detail.
     2364 *
     2365 * @since 6.1.0
     2366 *
     2367 * @param array $nodes The nodes to filter.
     2368 * @return array A filtered array of style nodes.
     2369 */
     2370function wp_filter_out_block_nodes( $nodes ) {
     2371    return array_filter(
     2372        $nodes,
     2373        function( $node ) {
     2374            return ! in_array( 'blocks', $node['path'], true );
     2375        },
     2376        ARRAY_FILTER_USE_BOTH
     2377    );
     2378}
     2379
     2380/**
    23572381 * Enqueues the global styles defined via theme.json.
    23582382 *
     
    23762400    ) {
    23772401        return;
     2402    }
     2403
     2404    /*
     2405     * If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally.
     2406     * This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
     2407     */
     2408    if ( $separate_assets ) {
     2409        add_filter( 'get_style_nodes', 'wp_filter_out_block_nodes' );
     2410        // Add each block as an inline css.
     2411        wp_add_global_styles_for_blocks();
    23782412    }
    23792413
Note: See TracChangeset for help on using the changeset viewer.