Gutenberg: withAPIData URL parameters and Plain Permalinks

Created on 28 Oct 2017  路  9Comments  路  Source: WordPress/gutenberg

Issue Overview

If you use plain permalinks and the withAPIData URL has parameters, the request fails because of two question marks.

Example: /index.php?rest_route=/wp/v2/users?context=edit&per_page=100 Failed to load resource: the server responded with a status of 404 (Not Found)

Steps to Reproduce (for bugs)

  1. Enable Plain Permalinks in the settings.
  2. Open the Gutenberg Editor
  3. See the JS Error in the Console

Related Issues and/or PRs

3121 Delete post fails with plain permalinks and force=true

Todos

  • [ ] Tests
  • [ ] Documentation
Core REST API Task [Feature] Permalink [Type] WP Core Bug

Most helpful comment

Taking a look at this...

All 9 comments

the same problem with
rest_route=/wp/v2/posts/id?force=true
that call with all languages but not English (United States)

Is this the correct call?
rest_route=/wp/v2/posts/id&force=true

But force=true is not the correct call to delete a post to trash

@RickorDD The force problem is a core wp-api.js bug: https://core.trac.wordpress.org/ticket/40672#comment:19

I expect the solution is to URL encode the REST path if it is appended to the root as a query argument?

Arguably might be the responsibility of the core wp.apiRequest to handle, since this is where the concatenation occurs:

https://github.com/WordPress/WordPress/blob/cb7483b59543cd973cb2a7c2d4f9a5852e5e9d5c/wp-includes/js/api-request.js#L40-L42

Taking a look at this...

It would be nice if Gutenberg could perform a common sense check in gutenberg_pre_init() to see if plain permalinks are being used and WordPress < 5..., or whichever version has the fix for TRAC 42382.

@aduth Could we shim this in Gutenberg for the time being?

@aduth Could we shim this in Gutenberg for the time being?

Probably. We could either replace the api-request.js dependency wholesale, or override buildAjaxOptions to modify options before calling the original function.

apiRequest.buildAjaxOptions = flow( [
    ( options ) => {
        // Fix `options.path` ...
    },
    apiRequest.buildAjaxOptions,
] );

Fix at #4877

Was this page helpful?
0 / 5 - 0 ratings