Make WordPress Core

Changeset 55234

Timestamp:
02/06/2023 07:38:08 PM (18 months ago)
Author:
flixos90
Message:

Editor: Support the block_types and viewport_width props for remote patterns fetched from Pattern Directory.

Props ntsekouras, ironprogrammer, hellofromtonya, flixos90.
Fixes #57611.

Location:
trunk
Files:
6 edited

Legend:

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

    r55173 r55234  
    160160
    161161/**
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
    162187 * Register Core's official patterns from wordpress.org/patterns.
    163188 *
    164189 * @since 5.8.0
    165190 * @since 5.9.0 The $current_screen argument was removed.
     191
     192
    166193 *
    167194 * @param WP_Screen $deprecated Unused. Formerly the screen that the current request was triggered from.
     
    197224        $patterns = $response->get_data();
    198225
    199         foreach ( $patterns as $settings ) {
    200             $pattern_name = 'core/' . sanitize_title( $settings['title'] );
    201             register_block_pattern( $pattern_name, (array) $settings );
     226        foreach ( $patterns as $pattern ) {
     227            $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
     228            $pattern_name       = 'core/' . sanitize_title( $normalized_pattern['title'] );
     229            register_block_pattern( $pattern_name, $normalized_pattern );
    202230        }
    203231    }
     
    208236 *
    209237 * @since 5.9.0
     238
     239
    210240 */
    211241function _load_remote_featured_patterns() {
     
    227257    }
    228258    $patterns = $response->get_data();
    229 
     259    $registry = WP_Block_Patterns_Registry::get_instance();
    230260    foreach ( $patterns as $pattern ) {
    231         $pattern_name = sanitize_title( $pattern['title'] );
    232         $registry     = WP_Block_Patterns_Registry::get_instance();
     261        $ );
     262        $);
    233263        // Some patterns might be already registered as core patterns with the `core` prefix.
    234264        $is_registered = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name" );
    235265        if ( ! $is_registered ) {
    236             register_block_pattern( $pattern_name, (array) $pattern );
     266            register_block_pattern( $pattern_name, pattern );
    237267        }
    238268    }
     
    244274 *
    245275 * @since 6.0.0
     276
     277
    246278 * @access private
    247279 */
     
    270302    $patterns_registry = WP_Block_Patterns_Registry::get_instance();
    271303    foreach ( $patterns as $pattern ) {
    272         $pattern_name = sanitize_title( $pattern['title'] );
     304        $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
     305        $pattern_name       = sanitize_title( $normalized_pattern['title'] );
    273306        // Some patterns might be already registered as core patterns with the `core` prefix.
    274307        $is_registered = $patterns_registry->is_registered( $pattern_name ) || $patterns_registry->is_registered( "core/$pattern_name" );
    275308        if ( ! $is_registered ) {
    276             register_block_pattern( $pattern_name, (array) $pattern );
     309            register_block_pattern( $pattern_name, pattern );
    277310        }
    278311    }
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php

    r55132 r55234  
    104104            'slug'     => true,
    105105        );
    106         $query_args = array_intersect_key( $request->get_params(), $valid_query_args );
     106        $query_args = array_intersect_key( $request->get_params(), $valid_query_args );
    107107
    108108        $query_args['locale']             = get_user_locale();
     
    203203            'description'    => sanitize_text_field( $raw_pattern->meta->wpop_description ),
    204204            'viewport_width' => absint( $raw_pattern->meta->wpop_viewport_width ),
     205
    205206        );
    206207
     
    225226     *
    226227     * @since 5.8.0
     228
    227229     *
    228230     * @return array Item schema data.
     
    286288                    'type'        => 'integer',
    287289                    'context'     => array( 'view', 'edit', 'embed' ),
     290
     291
     292
     293
     294
     295
     296
     297
    288298                ),
    289299            ),
  • trunk/tests/phpunit/data/blocks/pattern-directory/browse-all.json

    r53665 r55234  
    1111            "wpop_description": "A heading preceded by a chapter number, and followed by a paragraph.",
    1212            "wpop_keywords": "blog post",
    13             "wpop_viewport_width": 1000
     13            "wpop_viewport_width": 1000,
     14            "wpop_block_types": [ "core/heading" ]
    1415        },
    1516        "category_slugs": [ "text" ],
     
    2829            "wpop_description": "A large hero section with an example background image and a heading in the center.",
    2930            "wpop_keywords": "header, hero",
    30             "wpop_viewport_width": 1000
     31            "wpop_viewport_width": 1000,
     32            "wpop_block_types": []
    3133        },
    3234        "category_slugs": [ "header" ],
     
    4547            "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.",
    4648            "wpop_keywords": "call to action, hero section",
    47             "wpop_viewport_width": 1000
     49            "wpop_viewport_width": 1000,
     50            "wpop_block_types": []
    4851        },
    4952        "category_slugs": [ "header" ],
  • trunk/tests/phpunit/data/blocks/pattern-directory/browse-category-2.json

    r53665 r55234  
    1111            "wpop_description": "Three filled buttons with rounded corners, side by side.",
    1212            "wpop_keywords": "",
    13             "wpop_viewport_width": 600
     13            "wpop_viewport_width": 600,
     14            "wpop_block_types": []
    1415        },
    1516        "category_slugs": [ "buttons" ],
     
    2829            "wpop_description": "Two buttons, one filled and one outlined, side by side.",
    2930            "wpop_keywords": "",
    30             "wpop_viewport_width": 500
     31            "wpop_viewport_width": 500,
     32            "wpop_block_types": []
    3133        },
    3234        "category_slugs": [ "buttons" ],
  • trunk/tests/phpunit/data/blocks/pattern-directory/browse-keyword-11.json

    r53665 r55234  
    1111            "wpop_description": "A heading preceded by a chapter number, and followed by a paragraph.",
    1212            "wpop_keywords": "",
    13             "wpop_viewport_width": 1000
     13            "wpop_viewport_width": 1000,
     14            "wpop_block_types": []
    1415        },
    1516        "category_slugs": [ "text" ],
     
    2829            "wpop_description": "A large hero section with an example background image and a heading in the center.",
    2930            "wpop_keywords": "",
    30             "wpop_viewport_width": 1000
     31            "wpop_viewport_width": 1000,
     32            "wpop_block_types": []
    3133        },
    3234        "category_slugs": [ "header" ],
     
    4547            "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.",
    4648            "wpop_keywords": "",
    47             "wpop_viewport_width": 1000
     49            "wpop_viewport_width": 1000,
     50            "wpop_block_types": []
    4851        },
    4952        "category_slugs": [ "header" ],
  • trunk/tests/phpunit/data/blocks/pattern-directory/search-button.json

    r53665 r55234  
    1111            "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.",
    1212            "wpop_keywords": "",
    13             "wpop_viewport_width": 1000
     13            "wpop_viewport_width": 1000,
     14            "wpop_block_types": []
    1415        },
    1516        "category_slugs": [ "header" ],
     
    2829            "wpop_description": "Three small columns of text, each with an outlined button with rounded corners at the bottom.",
    2930            "wpop_keywords": "",
    30             "wpop_viewport_width": 1000
     31            "wpop_viewport_width": 1000,
     32            "wpop_block_types": []
    3133        },
    3234        "category_slugs": [ "columns" ],
     
    4547            "wpop_description": "Three filled buttons with rounded corners, side by side.",
    4648            "wpop_keywords": "",
    47             "wpop_viewport_width": 600
     49            "wpop_viewport_width": 600,
     50            "wpop_block_types": []
    4851        },
    4952        "category_slugs": [ "buttons" ],
     
    6265            "wpop_description": "Two buttons, one filled and one outlined, side by side.",
    6366            "wpop_keywords": "",
    64             "wpop_viewport_width": 500
     67            "wpop_viewport_width": 500,
     68            "wpop_block_types": []
    6569        },
    6670        "category_slugs": [ "buttons" ],
Note: See TracChangeset for help on using the changeset viewer.