wp/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    47 	 *
    47 	 *
    48 	 * @param string $parent_post_type Post type of the parent.
    48 	 * @param string $parent_post_type Post type of the parent.
    49 	 */
    49 	 */
    50 	public function __construct( $parent_post_type ) {
    50 	public function __construct( $parent_post_type ) {
    51 		$this->parent_post_type  = $parent_post_type;
    51 		$this->parent_post_type  = $parent_post_type;
    52 		$this->namespace         = 'wp/v2';
       
    53 		$this->rest_base         = 'revisions';
    52 		$this->rest_base         = 'revisions';
    54 		$post_type_object        = get_post_type_object( $parent_post_type );
    53 		$post_type_object        = get_post_type_object( $parent_post_type );
    55 		$this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
    54 		$this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
       
    55 		$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();
    56 		$this->parent_controller = $post_type_object->get_rest_controller();
    57 
    57 
    58 		if ( ! $this->parent_controller ) {
    58 		if ( ! $this->parent_controller ) {
    59 			$this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
    59 			$this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
    60 		}
    60 		}
   533 
   533 
   534 	/**
   534 	/**
   535 	 * Prepares the revision for the REST response.
   535 	 * Prepares the revision for the REST response.
   536 	 *
   536 	 *
   537 	 * @since 4.7.0
   537 	 * @since 4.7.0
   538 	 *
   538 	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
   539 	 * @param WP_Post         $post    Post revision object.
   539 	 *
       
   540 	 * @param WP_Post         $item    Post revision object.
   540 	 * @param WP_REST_Request $request Request object.
   541 	 * @param WP_REST_Request $request Request object.
   541 	 * @return WP_REST_Response Response object.
   542 	 * @return WP_REST_Response Response object.
   542 	 */
   543 	 */
   543 	public function prepare_item_for_response( $post, $request ) {
   544 	public function prepare_item_for_response( $item, $request ) {
       
   545 		// Restores the more descriptive, specific name for use within this method.
       
   546 		$post            = $item;
   544 		$GLOBALS['post'] = $post;
   547 		$GLOBALS['post'] = $post;
   545 
   548 
   546 		setup_postdata( $post );
   549 		setup_postdata( $post );
   547 
   550 
   548 		$fields = $this->get_fields_for_response( $request );
   551 		$fields = $this->get_fields_for_response( $request );