Make WordPress Core


Ignore:
Timestamp:
06/27/2023 11:11:02 AM (12 months ago)
Author:
isabel_brison
Message:

Editor: allow filtering block patterns by source.

Extends the REST API endpoint for block patterns to provide a source attribute that can be used to filter patterns.

Props aaronrobertshaw, mukesh27, talldanwp, ramonopoly.
Fixes 58622.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-patterns.php

    r55983 r56063  
    1313 *
    1414 * @since 5.5.0
     15 * @since 6.3.0 Added source to core block patterns.
    1516 * @access private
    1617 */
     
    3031
    3132        foreach ( $core_block_patterns as $core_block_pattern ) {
    32             register_block_pattern(
    33                 'core/' . $core_block_pattern,
    34                 require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php'
    35             );
     33            $pattern           = require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php';
     34            $pattern['source'] = 'core';
     35            register_block_pattern( 'core/' . $core_block_pattern, $pattern );
    3636        }
    3737    }
     
    191191 * @since 6.2.0 Normalize the pattern from the API (snake_case) to the
    192192 *              format expected by `register_block_pattern` (camelCase).
     193 * @since 6.3.0 Add 'pattern-directory/core' to the pattern's 'source'.
    193194 *
    194195 * @param WP_Screen $deprecated Unused. Formerly the screen that the current request was triggered from.
     
    225226
    226227        foreach ( $patterns as $pattern ) {
     228            $pattern['source']  = 'pattern-directory/core';
    227229            $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
    228230            $pattern_name       = 'core/' . sanitize_title( $normalized_pattern['title'] );
     
    238240 * @since 6.2.0 Normalized the pattern from the API (snake_case) to the
    239241 *              format expected by `register_block_pattern()` (camelCase).
     242 * @since 6.3.0 Add 'pattern-directory/featured' to the pattern's 'source'.
    240243 */
    241244function _load_remote_featured_patterns() {
     
    259262    $registry = WP_Block_Patterns_Registry::get_instance();
    260263    foreach ( $patterns as $pattern ) {
     264        $pattern['source']  = 'pattern-directory/featured';
    261265        $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
    262266        $pattern_name       = sanitize_title( $normalized_pattern['title'] );
     
    276280 * @since 6.2.0 Normalized the pattern from the API (snake_case) to the
    277281 *              format expected by `register_block_pattern()` (camelCase).
     282 * @since 6.3.0 Add 'pattern-directory/theme' to the pattern's 'source'.
    278283 * @access private
    279284 */
     
    302307    $patterns_registry = WP_Block_Patterns_Registry::get_instance();
    303308    foreach ( $patterns as $pattern ) {
     309        $pattern['source']  = 'pattern-directory/theme';
    304310        $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
    305311        $pattern_name       = sanitize_title( $normalized_pattern['title'] );
Note: See TracChangeset for help on using the changeset viewer.