WordPress.org

Make WordPress Core

Opened 21 months ago

Closed 20 months ago

Last modified 18 months ago

#44437 closed defect (bug) (fixed)

Invocation parameter types are not compatible with declared

Reported by: subrataemfluence Owned by: johnbillion
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch
Focuses: docs Cc:

Description

In class-wp-rest-post-types-controller.php the type of parameter $post_type in function prepare_item_for_response is declared as stdClass.

<?php
* @param stdClass $post_type Post type data.
...
public function prepare_item_for_response( $post_type, $request ) {
   ...
}

The function has been called twice in the class file:

<?php
public function get_item( $request ) {
   $obj = get_post_type_object( $request['type'] );
   ...
   $data = $this->prepare_item_for_response( $obj, $request );
}

and

<?php
public function get_items( $request ) {
   ...
   foreach( get_post_types( array(), 'object' ) as $obj ) {
      ...
   }

   $post_type = $this->prepare_item_for_response( $obj, $request );
}

Since $obj is a known type, i.e. WP_Post_Type can we declare the parameter $post_type type as WP_Post_Type instead of stdClass ?

Also, the object of this class is used in wp-includes/rest-api.php for registering route but the function in question is never invoked in the system separately.

Attachments (1)

44437.diff (672 bytes) - added by subrataemfluence 21 months ago.
Proposed patch

Download all attachments as: .zip

Change History (4)

@subrataemfluence
21 months ago

Proposed patch

#1 @johnbillion
20 months ago

  • Focuses coding-standards removed
  • Keywords has-patch added; 2nd-opinion removed
  • Milestone changed from Awaiting Review to 5.0
  • Owner set to johnbillion
  • Status changed from new to reviewing
  • Version trunk deleted

#2 @johnbillion
20 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 43519:

Docs: Correct the parameter type for WP_REST_Post_Types_Controller::prepare_item_for_response().

Props subrataemfluence

Fixes #44437

#3 @johnbillion
18 months ago

  • Milestone changed from 5.0 to 5.1
Note: See TracTickets for help on using tickets.