Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41731 r42343  
    3636        public function register_routes() {
    3737
    38                 register_rest_route( $this->namespace, '/' . $this->rest_base, array(
    39                         array(
    40                                 'methods'             => WP_REST_Server::READABLE,
    41                                 'callback'            => array( $this, 'get_items' ),
    42                                 'permission_callback' => array( $this, 'get_items_permissions_check' ),
    43                                 'args'                => $this->get_collection_params(),
    44                         ),
    45                         'schema' => array( $this, 'get_public_item_schema' ),
    46                 ) );
    47 
    48                 register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<type>[\w-]+)', array(
    49                         'args' => array(
    50                                 'type' => array(
    51                                         'description' => __( 'An alphanumeric identifier for the post type.' ),
    52                                         'type'        => 'string',
    53                                 ),
    54                         ),
    55                         array(
    56                                 'methods'  => WP_REST_Server::READABLE,
    57                                 'callback' => array( $this, 'get_item' ),
    58                                 'args'     => array(
    59                                         'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    60                                 ),
    61                         ),
    62                         'schema' => array( $this, 'get_public_item_schema' ),
    63                 ) );
     38                register_rest_route(
     39                        $this->namespace, '/' . $this->rest_base, array(
     40                                array(
     41                                        'methods'             => WP_REST_Server::READABLE,
     42                                        'callback'            => array( $this, 'get_items' ),
     43                                        'permission_callback' => array( $this, 'get_items_permissions_check' ),
     44                                        'args'                => $this->get_collection_params(),
     45                                ),
     46                                'schema' => array( $this, 'get_public_item_schema' ),
     47                        )
     48                );
     49
     50                register_rest_route(
     51                        $this->namespace, '/' . $this->rest_base . '/(?P<type>[\w-]+)', array(
     52                                'args'   => array(
     53                                        'type' => array(
     54                                                'description' => __( 'An alphanumeric identifier for the post type.' ),
     55                                                'type'        => 'string',
     56                                        ),
     57                                ),
     58                                array(
     59                                        'methods'  => WP_REST_Server::READABLE,
     60                                        'callback' => array( $this, 'get_item' ),
     61                                        'args'     => array(
     62                                                'context' => $this->get_context_param( array( 'default' => 'view' ) ),
     63                                        ),
     64                                ),
     65                                'schema' => array( $this, 'get_public_item_schema' ),
     66                        )
     67                );
    6468        }
    6569
     
    102106                        }
    103107
    104                         $post_type = $this->prepare_item_for_response( $obj, $request );
     108                        $post_type          = $this->prepare_item_for_response( $obj, $request );
    105109                        $data[ $obj->name ] = $this->prepare_response_for_collection( $post_type );
    106110                }
     
    149153                $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
    150154                $taxonomies = wp_list_pluck( $taxonomies, 'name' );
    151                 $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
    152                 $supports = get_all_post_type_supports( $post_type->name );
    153 
    154                 $data = array(
     155                $base       = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
     156                $supports   = get_all_post_type_supports( $post_type->name );
     157
     158                $data    = array(
    155159                        'capabilities' => $post_type->cap,
    156160                        'description'  => $post_type->description,
     
    170174                $response = rest_ensure_response( $data );
    171175
    172                 $response->add_links( array(
    173                         'collection' => array(
    174                                 'href'   => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
    175                         ),
    176                         'https://api.w.org/items' => array(
    177                                 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ),
    178                         ),
    179                 ) );
     176                $response->add_links(
     177                        array(
     178                                'collection'              => array(
     179                                        'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
     180                                ),
     181                                'https://api.w.org/items' => array(
     182                                        'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ),
     183                                ),
     184                        )
     185                );
    180186
    181187                /**
     
    202208        public function get_item_schema() {
    203209                $schema = array(
    204                         '$schema'              => 'http://json-schema.org/draft-04/schema#',
    205                         'title'                => 'type',
    206                         'type'                 => 'object',
    207                         'properties'           => array(
    208                                 'capabilities'     => array(
    209                                         'description'  => __( 'All capabilities used by the post type.' ),
    210                                         'type'         => 'object',
    211                                         'context'      => array( 'edit' ),
    212                                         'readonly'     => true,
    213                                 ),
    214                                 'description'      => array(
    215                                         'description'  => __( 'A human-readable description of the post type.' ),
    216                                         'type'         => 'string',
    217                                         'context'      => array( 'view', 'edit' ),
    218                                         'readonly'     => true,
    219                                 ),
    220                                 'hierarchical'     => array(
    221                                         'description'  => __( 'Whether or not the post type should have children.' ),
    222                                         'type'         => 'boolean',
    223                                         'context'      => array( 'view', 'edit' ),
    224                                         'readonly'     => true,
    225                                 ),
    226                                 'labels'           => array(
    227                                         'description'  => __( 'Human-readable labels for the post type for various contexts.' ),
    228                                         'type'         => 'object',
    229                                         'context'      => array( 'edit' ),
    230                                         'readonly'     => true,
    231                                 ),
    232                                 'name'             => array(
    233                                         'description'  => __( 'The title for the post type.' ),
    234                                         'type'         => 'string',
    235                                         'context'      => array( 'view', 'edit', 'embed' ),
    236                                         'readonly'     => true,
    237                                 ),
    238                                 'slug'             => array(
    239                                         'description'  => __( 'An alphanumeric identifier for the post type.' ),
    240                                         'type'         => 'string',
    241                                         'context'      => array( 'view', 'edit', 'embed' ),
    242                                         'readonly'     => true,
    243                                 ),
    244                                 'supports'         => array(
    245                                         'description'  => __( 'All features, supported by the post type.' ),
    246                                         'type'         => 'object',
    247                                         'context'      => array( 'edit' ),
    248                                         'readonly'     => true,
    249                                 ),
    250                                 'taxonomies'       => array(
    251                                         'description'  => __( 'Taxonomies associated with post type.' ),
    252                                         'type'         => 'array',
    253                                         'items'        => array(
     210                        '$schema'    => 'http://json-schema.org/draft-04/schema#',
     211                        'title'      => 'type',
     212                        'type'       => 'object',
     213                        'properties' => array(
     214                                'capabilities' => array(
     215                                        'description' => __( 'All capabilities used by the post type.' ),
     216                                        'type'        => 'object',
     217                                        'context'     => array( 'edit' ),
     218                                        'readonly'    => true,
     219                                ),
     220                                'description'  => array(
     221                                        'description' => __( 'A human-readable description of the post type.' ),
     222                                        'type'        => 'string',
     223                                        'context'     => array( 'view', 'edit' ),
     224                                        'readonly'    => true,
     225                                ),
     226                                'hierarchical' => array(
     227                                        'description' => __( 'Whether or not the post type should have children.' ),
     228                                        'type'        => 'boolean',
     229                                        'context'     => array( 'view', 'edit' ),
     230                                        'readonly'    => true,
     231                                ),
     232                                'labels'       => array(
     233                                        'description' => __( 'Human-readable labels for the post type for various contexts.' ),
     234                                        'type'        => 'object',
     235                                        'context'     => array( 'edit' ),
     236                                        'readonly'    => true,
     237                                ),
     238                                'name'         => array(
     239                                        'description' => __( 'The title for the post type.' ),
     240                                        'type'        => 'string',
     241                                        'context'     => array( 'view', 'edit', 'embed' ),
     242                                        'readonly'    => true,
     243                                ),
     244                                'slug'         => array(
     245                                        'description' => __( 'An alphanumeric identifier for the post type.' ),
     246                                        'type'        => 'string',
     247                                        'context'     => array( 'view', 'edit', 'embed' ),
     248                                        'readonly'    => true,
     249                                ),
     250                                'supports'     => array(
     251                                        'description' => __( 'All features, supported by the post type.' ),
     252                                        'type'        => 'object',
     253                                        'context'     => array( 'edit' ),
     254                                        'readonly'    => true,
     255                                ),
     256                                'taxonomies'   => array(
     257                                        'description' => __( 'Taxonomies associated with post type.' ),
     258                                        'type'        => 'array',
     259                                        'items'       => array(
    254260                                                'type' => 'string',
    255261                                        ),
    256                                         'context'      => array( 'view', 'edit' ),
    257                                         'readonly'     => true,
    258                                 ),
    259                                 'rest_base'            => array(
    260                                         'description'  => __( 'REST base route for the post type.' ),
    261                                         'type'         => 'string',
    262                                         'context'      => array( 'view', 'edit', 'embed' ),
    263                                         'readonly'     => true,
     262                                        'context'     => array( 'view', 'edit' ),
     263                                        'readonly'    => true,
     264                                ),
     265                                'rest_base'    => array(
     266                                        'description' => __( 'REST base route for the post type.' ),
     267                                        'type'        => 'string',
     268                                        'context'     => array( 'view', 'edit', 'embed' ),
     269                                        'readonly'    => true,
    264270                                ),
    265271                        ),
Note: See TracChangeset for help on using the changeset viewer.