[wp-trac] [WordPress Trac] #62292: Warning in WP_REST_Posts_Controller::get_items()

WordPress Trac noreply at wordpress.org
Thu Oct 24 15:51:45 UTC 2024


#62292: Warning in WP_REST_Posts_Controller::get_items()
--------------------------+----------------------------------------------
 Reporter:  apermo        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  ui, docs, rest-api, performance
--------------------------+----------------------------------------------
Changes (by Hemant Ahir):

 * focuses:   => ui, docs, rest-api, performance


Comment:

 Here's the concise solution for the warning Undefined array key "paged" in
 the WP_REST_Posts_Controller:

 Solution: Add a check to verify if the "paged" parameter exists in the
 request before accessing it. If it's not present, assign a default value.

 Fix (around line 400 in class-wp-rest-posts-controller.php):

 {{{#!php
 <?php
 $paged = isset( $request['paged'] ) ? absint( $request['paged'] ) : 1;
 ?>
 }}}

 This same logic can be applied to
 WP_REST_Global_Styles_Revisions_Controller and
 WP_REST_Revisions_Controller as well. This ensures that no warnings occur
 when the "paged" key is missing.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62292#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list