wp/wp-includes/js/api-request.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-includes/js/api-request.js	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/js/api-request.js	Mon Oct 14 18:28:13 2019 +0200
@@ -9,6 +9,7 @@
  * - Allows specifying only an endpoint namespace/path instead of a full URL.
  *
  * @since     4.9.0
+ * @output wp-includes/js/api-request.js
  */
 
 ( function( $ ) {
@@ -22,7 +23,7 @@
 	apiRequest.buildAjaxOptions = function( options ) {
 		var url = options.url;
 		var path = options.path;
-		var namespaceTrimmed, endpointTrimmed;
+		var namespaceTrimmed, endpointTrimmed, apiRoot;
 		var headers, addNonceHeader, headerName;
 
 		if (
@@ -38,7 +39,16 @@
 			}
 		}
 		if ( typeof path === 'string' ) {
-			url = wpApiSettings.root + path.replace( /^\//, '' );
+			apiRoot = wpApiSettings.root;
+			path = path.replace( /^\//, '' );
+
+			// API root may already include query parameter prefix if site is
+			// configured to use plain permalinks.
+			if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) {
+				path = path.replace( '?', '&' );
+			}
+
+			url = apiRoot + path;
 		}
 
 		// If ?_wpnonce=... is present, no need to add a nonce header.