equal
deleted
inserted
replaced
7 * - Allows overriding these requests as needed by customized WP installations. |
7 * - Allows overriding these requests as needed by customized WP installations. |
8 * - Sends the REST API nonce as a request header. |
8 * - Sends the REST API nonce as a request header. |
9 * - Allows specifying only an endpoint namespace/path instead of a full URL. |
9 * - Allows specifying only an endpoint namespace/path instead of a full URL. |
10 * |
10 * |
11 * @since 4.9.0 |
11 * @since 4.9.0 |
|
12 * @output wp-includes/js/api-request.js |
12 */ |
13 */ |
13 |
14 |
14 ( function( $ ) { |
15 ( function( $ ) { |
15 var wpApiSettings = window.wpApiSettings; |
16 var wpApiSettings = window.wpApiSettings; |
16 |
17 |
20 } |
21 } |
21 |
22 |
22 apiRequest.buildAjaxOptions = function( options ) { |
23 apiRequest.buildAjaxOptions = function( options ) { |
23 var url = options.url; |
24 var url = options.url; |
24 var path = options.path; |
25 var path = options.path; |
25 var namespaceTrimmed, endpointTrimmed; |
26 var namespaceTrimmed, endpointTrimmed, apiRoot; |
26 var headers, addNonceHeader, headerName; |
27 var headers, addNonceHeader, headerName; |
27 |
28 |
28 if ( |
29 if ( |
29 typeof options.namespace === 'string' && |
30 typeof options.namespace === 'string' && |
30 typeof options.endpoint === 'string' |
31 typeof options.endpoint === 'string' |
36 } else { |
37 } else { |
37 path = namespaceTrimmed; |
38 path = namespaceTrimmed; |
38 } |
39 } |
39 } |
40 } |
40 if ( typeof path === 'string' ) { |
41 if ( typeof path === 'string' ) { |
41 url = wpApiSettings.root + path.replace( /^\//, '' ); |
42 apiRoot = wpApiSettings.root; |
|
43 path = path.replace( /^\//, '' ); |
|
44 |
|
45 // API root may already include query parameter prefix if site is |
|
46 // configured to use plain permalinks. |
|
47 if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) { |
|
48 path = path.replace( '?', '&' ); |
|
49 } |
|
50 |
|
51 url = apiRoot + path; |
42 } |
52 } |
43 |
53 |
44 // If ?_wpnonce=... is present, no need to add a nonce header. |
54 // If ?_wpnonce=... is present, no need to add a nonce header. |
45 addNonceHeader = ! ( options.data && options.data._wpnonce ); |
55 addNonceHeader = ! ( options.data && options.data._wpnonce ); |
46 |
56 |