Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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-revisions-controller.php

    r41731 r42343  
    4949     */
    5050    public function __construct( $parent_post_type ) {
    51         $this->parent_post_type = $parent_post_type;
     51        $this->parent_post_type  = $parent_post_type;
    5252        $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
    53         $this->namespace = 'wp/v2';
    54         $this->rest_base = 'revisions';
    55         $post_type_object = get_post_type_object( $parent_post_type );
    56         $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
     53        $this->namespace         = 'wp/v2';
     54        $this->rest_base         = 'revisions';
     55        $post_type_object        = get_post_type_object( $parent_post_type );
     56        $this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
    5757    }
    5858
     
    6666    public function register_routes() {
    6767
    68         register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array(
    69             'args' => array(
    70                 'parent' => array(
    71                     'description' => __( 'The ID for the parent of the object.' ),
    72                     'type'        => 'integer',
    73                 ),
    74             ),
    75             array(
    76                 'methods'             => WP_REST_Server::READABLE,
    77                 'callback'            => array( $this, 'get_items' ),
    78                 'permission_callback' => array( $this, 'get_items_permissions_check' ),
    79                 'args'                => $this->get_collection_params(),
    80             ),
    81             'schema' => array( $this, 'get_public_item_schema' ),
    82         ) );
    83 
    84         register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array(
    85             'args' => array(
    86                 'parent' => array(
    87                     'description' => __( 'The ID for the parent of the object.' ),
    88                     'type'        => 'integer',
    89                 ),
    90                 'id' => array(
    91                     'description' => __( 'Unique identifier for the object.' ),
    92                     'type'        => 'integer',
    93                 ),
    94             ),
    95             array(
    96                 'methods'             => WP_REST_Server::READABLE,
    97                 'callback'            => array( $this, 'get_item' ),
    98                 'permission_callback' => array( $this, 'get_item_permissions_check' ),
    99                 'args'                => array(
    100                     'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    101                 ),
    102             ),
    103             array(
    104                 'methods'             => WP_REST_Server::DELETABLE,
    105                 'callback'            => array( $this, 'delete_item' ),
    106                 'permission_callback' => array( $this, 'delete_item_permissions_check' ),
    107                 'args'                => array(
    108                     'force' => array(
    109                         'type'        => 'boolean',
    110                         'default'     => false,
    111                         'description' => __( 'Required to be true, as revisions do not support trashing.' ),
     68        register_rest_route(
     69            $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array(
     70                'args'   => array(
     71                    'parent' => array(
     72                        'description' => __( 'The ID for the parent of the object.' ),
     73                        'type'        => 'integer',
    11274                    ),
    11375                ),
    114             ),
    115             'schema' => array( $this, 'get_public_item_schema' ),
    116         ));
     76                array(
     77                    'methods'             => WP_REST_Server::READABLE,
     78                    'callback'            => array( $this, 'get_items' ),
     79                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
     80                    'args'                => $this->get_collection_params(),
     81                ),
     82                'schema' => array( $this, 'get_public_item_schema' ),
     83            )
     84        );
     85
     86        register_rest_route(
     87            $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array(
     88                'args'   => array(
     89                    'parent' => array(
     90                        'description' => __( 'The ID for the parent of the object.' ),
     91                        'type'        => 'integer',
     92                    ),
     93                    'id'     => array(
     94                        'description' => __( 'Unique identifier for the object.' ),
     95                        'type'        => 'integer',
     96                    ),
     97                ),
     98                array(
     99                    'methods'             => WP_REST_Server::READABLE,
     100                    'callback'            => array( $this, 'get_item' ),
     101                    'permission_callback' => array( $this, 'get_item_permissions_check' ),
     102                    'args'                => array(
     103                        'context' => $this->get_context_param( array( 'default' => 'view' ) ),
     104                    ),
     105                ),
     106                array(
     107                    'methods'             => WP_REST_Server::DELETABLE,
     108                    'callback'            => array( $this, 'delete_item' ),
     109                    'permission_callback' => array( $this, 'delete_item_permissions_check' ),
     110                    'args'                => array(
     111                        'force' => array(
     112                            'type'        => 'boolean',
     113                            'default'     => false,
     114                            'description' => __( 'Required to be true, as revisions do not support trashing.' ),
     115                        ),
     116                    ),
     117                ),
     118                'schema' => array( $this, 'get_public_item_schema' ),
     119            )
     120        );
    117121
    118122    }
     
    202206        $response = array();
    203207        foreach ( $revisions as $revision ) {
    204             $data = $this->prepare_item_for_response( $revision, $request );
     208            $data       = $this->prepare_item_for_response( $revision, $request );
    205209            $response[] = $this->prepare_response_for_collection( $data );
    206210        }
     
    314318
    315319        $response = new WP_REST_Response();
    316         $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
     320        $response->set_data(
     321            array(
     322                'deleted'  => true,
     323                'previous' => $previous->get_data(),
     324            )
     325        );
    317326        return $response;
    318327    }
     
    399408        }
    400409
    401         $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
    402         $data = $this->add_additional_fields_to_object( $data, $request );
    403         $data = $this->filter_response_by_context( $data, $context );
     410        $context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
     411        $data     = $this->add_additional_fields_to_object( $data, $request );
     412        $data     = $this->filter_response_by_context( $data, $context );
    404413        $response = rest_ensure_response( $data );
    405414
     
    458467            // Base properties for every Revision.
    459468            'properties' => array(
    460                 'author'          => array(
     469                'author'       => array(
    461470                    'description' => __( 'The ID for the author of the object.' ),
    462471                    'type'        => 'integer',
    463472                    'context'     => array( 'view', 'edit', 'embed' ),
    464473                ),
    465                 'date'            => array(
     474                'date'         => array(
    466475                    'description' => __( "The date the object was published, in the site's timezone." ),
    467476                    'type'        => 'string',
     
    469478                    'context'     => array( 'view', 'edit', 'embed' ),
    470479                ),
    471                 'date_gmt'        => array(
     480                'date_gmt'     => array(
    472481                    'description' => __( 'The date the object was published, as GMT.' ),
    473482                    'type'        => 'string',
     
    475484                    'context'     => array( 'view', 'edit' ),
    476485                ),
    477                 'guid'            => array(
     486                'guid'         => array(
    478487                    'description' => __( 'GUID for the object, as it exists in the database.' ),
    479488                    'type'        => 'string',
    480489                    'context'     => array( 'view', 'edit' ),
    481490                ),
    482                 'id'              => array(
     491                'id'           => array(
    483492                    'description' => __( 'Unique identifier for the object.' ),
    484493                    'type'        => 'integer',
    485494                    'context'     => array( 'view', 'edit', 'embed' ),
    486495                ),
    487                 'modified'        => array(
     496                'modified'     => array(
    488497                    'description' => __( "The date the object was last modified, in the site's timezone." ),
    489498                    'type'        => 'string',
     
    491500                    'context'     => array( 'view', 'edit' ),
    492501                ),
    493                 'modified_gmt'    => array(
     502                'modified_gmt' => array(
    494503                    'description' => __( 'The date the object was last modified, as GMT.' ),
    495504                    'type'        => 'string',
     
    497506                    'context'     => array( 'view', 'edit' ),
    498507                ),
    499                 'parent'          => array(
     508                'parent'       => array(
    500509                    'description' => __( 'The ID for the parent of the object.' ),
    501510                    'type'        => 'integer',
    502511                    'context'     => array( 'view', 'edit', 'embed' ),
    503                     ),
    504                 'slug'            => array(
     512                ),
     513                'slug'         => array(
    505514                    'description' => __( 'An alphanumeric identifier for the object unique to its type.' ),
    506515                    'type'        => 'string',
Note: See TracChangeset for help on using the changeset viewer.