#62292 closed defect (bug) (fixed)
Warning in WP_REST_Posts_Controller::get_items()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
On my sentry installation I get Warning: Undefined array key "paged"
for /wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php in WP_REST_Posts_Controller::get_items at line 400
Same also technically applies to the WP_REST_Global_Styles_Revisions_Controller
and WP_REST_Revisions_Controller
.
A Github PR for this follows.
Change History (10)
This ticket was mentioned in PR #7635 on WordPress/wordpress-develop by @apermo.
5 months ago
#1
- Keywords has-patch added
#2
@
5 months ago
- Focuses ui docs rest-api performance added
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 $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.
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
5 months ago
This ticket was mentioned in PR #8021 on WordPress/wordpress-develop by @pbearne.
3 months ago
#4
- Keywords has-unit-tests added
#5
@
3 months ago
- Milestone changed from Awaiting Review to 6.8
- Owner set to pbearne
- Status changed from new to assigned
#8
@
2 months ago
- Owner changed from pbearne to flixos90
- Status changed from assigned to reviewing
Great catch @apermo! The PR by @pbearne looks good. While I agree this is unrelated to performance
, this is a worthwhile win. I'll take a closer look at the PR later.
@flixos90 commented on PR #8021:
2 months ago
#10
Committed in https://core.trac.wordpress.org/changeset/59630
WP_REST_Revisions_Controller::get_items()
,WP_REST_Posts_Controller::get_items()
andWP_REST_Global_Styles_Revisions_Controller::get_items()
can throw a warning ifpaged
is not set inquery_args
This PR fixes that, by duplicating and adjusting the same logic already present for
offset
in both Revisions controller, ensuring that the result in$page
will still be0
if it was empty, and the int value otherwise, just catching the warning.Trac ticket: [](https://core.trac.wordpress.org/ticket/62292)