Make WordPress Core


Ignore:
Timestamp:
10/19/2018 06:32:03 PM (8 years ago)
Author:
danielbachhuber
Message:

REST API: Handle api-request query parameters with plain permalinks.

When constructing the request URL, ensure that ? is replaced with & when the API root already contains a ?. Fixes an issue where requests were broken when sites had permalinks set to plain.

Props aduth.
Merges [42965] to the 5.0 branch.
Fixes #42382.

Location:
branches/5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

  • branches/5.0/src/wp-includes/js/api-request.js

    r41351 r43771  
    2323        var url = options.url;
    2424        var path = options.path;
    25         var namespaceTrimmed, endpointTrimmed;
     25        var namespaceTrimmed, endpointTrimmed, apiRoot;
    2626        var headers, addNonceHeader, headerName;
    2727
     
    3939        }
    4040        if ( typeof path === 'string' ) {
    41             url = wpApiSettings.root + path.replace( /^\//, '' );
     41            apiRoot = wpApiSettings.root;
     42            path = path.replace( /^\//, '' );
     43
     44            // API root may already include query parameter prefix if site is
     45            // configured to use plain permalinks.
     46            if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) {
     47                path = path.replace( '?', '&' );
     48            }
     49
     50            url = apiRoot + path;
    4251        }
    4352
Note: See TracChangeset for help on using the changeset viewer.