WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
356 stars 97 forks source link

REST API calls to store URL metrics fail when pretty permalinks aren't enabled #1567

Open westonruter opened 1 day ago

westonruter commented 1 day ago

When pretty permalinks aren't enabled, Optimization Detective sends the URL metrics data to the /index.php?rest_route=%2Foptimization-detective%2Fv1%2Furl-metrics%3Astore&_wpnonce=d6ef56f704. This ends up causing the request to fail with:

{
    "code": "rest_invalid_param",
    "message": "Failed to validate URL metric: rest_route is not a valid property of Object.",
    "data": {
        "status": 400
    }
}

This is because rest_route is returned, unexpectedly, as one of the params when calling $request->get_params():

https://github.com/WordPress/performance/blob/ddf297dca97641cfb21bef75fc4fd45ff49ea95b/plugins/optimization-detective/storage/rest-api.php#L131-L136

The quick fix would be to unset( $data['rest_route'] ), but it would be better if the params we obtain are exclusively from the JSON body.

This code is also being touched in https://github.com/WordPress/performance/pull/1373 where the issue is also occurring.

Granted, likely only a miniscule number of sites don't have pretty permalinks enabled, so this isn't a critical issue.

westonruter commented 1 day ago

See https://github.com/WordPress/performance/pull/1373#discussion_r1780210561