Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
westonruter opened this issue Sep 29, 2024 · 1 comment · Fixed by #1574
Closed

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

westonruter opened this issue Sep 29, 2024 · 1 comment · Fixed by #1574
Assignees
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken

Comments

@westonruter
Copy link
Member

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():

$data = $request->get_params();
// Remove params which are only used for the REST API request and which are not part of a URL Metric.
unset(
$data['slug'],
$data['nonce']
);

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 #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 westonruter added [Type] Bug An existing feature is broken [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Sep 29, 2024
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 Sep 29, 2024
@westonruter westonruter moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance 2025 Sep 29, 2024
@westonruter
Copy link
Member Author

westonruter commented Sep 30, 2024

See #1373 (comment)

@westonruter westonruter self-assigned this Sep 30, 2024
@westonruter westonruter moved this from To Do 🔧 to Code Review 👀 in WP Performance 2025 Oct 2, 2024
@github-project-automation github-project-automation bot moved this from Code Review 👀 to Done 😃 in WP Performance 2025 Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken
Projects
Status: Done 😃
Development

Successfully merging a pull request may close this issue.

1 participant