Make WordPress Core

Changeset 55697


Ignore:
Timestamp:
04/28/2023 03:04:19 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Bring some consistency to REST API revisions initialization.

The autosaves and revisions controllers used to set the same class properties in a slightly different order.

This commit makes the ::__construct() methods of both classes more consistent to simplify future maintenance.

Follow-up to [46272], [51962].

See #57839.

Location:
trunk/src/wp-includes/rest-api/endpoints
Files:
2 edited

Legend:

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

    r55154 r55697  
    6969        $this->revisions_controller = new WP_REST_Revisions_Controller( $parent_post_type );
    7070        $this->rest_base            = 'autosaves';
     71        $this->parent_base          = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
    7172        $this->namespace            = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
    72         $this->parent_base          = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
    7373    }
    7474
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    r55696 r55697  
    4949     */
    5050    public function __construct( $parent_post_type ) {
    51         $this->parent_post_type  = $parent_post_type;
     51        $this->parent_post_type = $parent_post_type;
     52        $post_type_object       = get_post_type_object( $parent_post_type );
     53        $parent_controller      = $post_type_object->get_rest_controller();
     54
     55        if ( ! $parent_controller ) {
     56            $parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
     57        }
     58
     59        $this->parent_controller = $parent_controller;
    5260        $this->rest_base         = 'revisions';
    53         $post_type_object        = get_post_type_object( $parent_post_type );
    5461        $this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
    5562        $this->namespace         = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
    56         $this->parent_controller = $post_type_object->get_rest_controller();
    57 
    58         if ( ! $this->parent_controller ) {
    59             $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
    60         }
    6163    }
    6264
Note: See TracChangeset for help on using the changeset viewer.