Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#44437 closed defect (bug) (fixed)

Invocation parameter types are not compatible with declared

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


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

* @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:

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


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 5 years ago.
Proposed patch

Download all attachments as: .zip

Change History (4)

5 years ago

Proposed patch

#1 @johnbillion
5 years 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
5 years 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
5 years ago

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