Make WordPress Core


Ignore:
Timestamp:
04/12/2022 12:46:08 PM (4 years ago)
Author:
gziolo
Message:

REST API: Use snake case convention for field names in Block Patterns

Backports the same changes applied in Gutenberg: https://github.com/WordPress/gutenberg/pull/40254.

Follow-up for [53152].

Props jsnajdr, timothyblynjacobs.
See #55505.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php

    r53152 r53154  
    108108                $fields = $this->get_fields_for_response( $request );
    109109                $keys   = array(
    110                         'name',
    111                         'title',
    112                         'description',
    113                         'viewportWidth',
    114                         'blockTypes',
    115                         'categories',
    116                         'keywords',
    117                         'content',
     110                        'name'          => 'name',
     111                        'title'         => 'title',
     112                        'description'   => 'description',
     113                        'viewportWidth' => 'viewport_width',
     114                        'blockTypes'    => 'block_types',
     115                        'categories'    => 'categories',
     116                        'keywords'      => 'keywords',
     117                        'content'       => 'content',
    118118                );
    119119                $data   = array();
    120                 foreach ( $keys as $key ) {
    121                         if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) {
    122                                 $data[ $key ] = $item[ $key ];
     120                foreach ( $keys as $item_key => $rest_key ) {
     121                        if ( isset( $item[ $item_key ] ) && rest_is_field_included( $rest_key, $fields ) ) {
     122                                $data[ $rest_key ] = $item[ $item_key ];
    123123                        }
    124124                }
     
    143143                        'type'       => 'object',
    144144                        'properties' => array(
    145                                 'name'          => array(
     145                                'name'           => array(
    146146                                        'description' => __( 'The pattern name.' ),
    147147                                        'type'        => 'string',
     
    149149                                        'context'     => array( 'view', 'edit', 'embed' ),
    150150                                ),
    151                                 'title'         => array(
     151                                'title'          => array(
    152152                                        'description' => __( 'The pattern title, in human readable format.' ),
    153153                                        'type'        => 'string',
     
    155155                                        'context'     => array( 'view', 'edit', 'embed' ),
    156156                                ),
    157                                 'description'   => array(
     157                                'description'    => array(
    158158                                        'description' => __( 'The pattern detailed description.' ),
    159159                                        'type'        => 'string',
     
    161161                                        'context'     => array( 'view', 'edit', 'embed' ),
    162162                                ),
    163                                 'viewportWidth' => array(
     163                                'viewport_Width' => array(
    164164                                        'description' => __( 'The pattern viewport width for inserter preview.' ),
    165165                                        'type'        => 'number',
     
    167167                                        'context'     => array( 'view', 'edit', 'embed' ),
    168168                                ),
    169                                 'blockTypes'    => array(
     169                                'block_Types'    => array(
    170170                                        'description' => __( 'Block types that the pattern is intended to be used with.' ),
    171171                                        'type'        => 'array',
     
    173173                                        'context'     => array( 'view', 'edit', 'embed' ),
    174174                                ),
    175                                 'categories'    => array(
     175                                'categories'     => array(
    176176                                        'description' => __( 'The pattern category slugs.' ),
    177177                                        'type'        => 'array',
     
    179179                                        'context'     => array( 'view', 'edit', 'embed' ),
    180180                                ),
    181                                 'keywords'      => array(
     181                                'keywords'       => array(
    182182                                        'description' => __( 'The pattern keywords.' ),
    183183                                        'type'        => 'array',
     
    185185                                        'context'     => array( 'view', 'edit', 'embed' ),
    186186                                ),
    187                                 'content'       => array(
     187                                'content'        => array(
    188188                                        'description' => __( 'The pattern content.' ),
    189189                                        'type'        => 'string',
Note: See TracChangeset for help on using the changeset viewer.