Make WordPress Core

Ticket #42382: 42382.diff

File 42382.diff, 1.6 KB (added by aduth, 7 years ago)
  • src/wp-includes/js/api-request.js

    diff --git src/wp-includes/js/api-request.js src/wp-includes/js/api-request.js
    index f0a84ef48f..4b299beb69 100644
     
    2222        apiRequest.buildAjaxOptions = function( options ) {
    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
    2828                if (
     
    3838                        }
    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
    4453                // If ?_wpnonce=... is present, no need to add a nonce header.
  • tests/qunit/wp-includes/js/api-request.js

    diff --git tests/qunit/wp-includes/js/api-request.js tests/qunit/wp-includes/js/api-request.js
    index 99a1213ea3..86d0d72cda 100644
     
    140140                        window.wpApiSettings.root = 'http://localhost/index.php?rest_route=/';
    141141                        assert.deepEqual( wp.apiRequest.buildAjaxOptions( {
    142142                                namespace: '/wp/v2/',
    143                                 endpoint: '/posts'
     143                                endpoint: '/posts?orderby=title'
    144144                        } ), {
    145                                 url: 'http://localhost/index.php?rest_route=/wp/v2/posts',
     145                                url: 'http://localhost/index.php?rest_route=/wp/v2/posts&orderby=title',
    146146                                headers: nonceHeader
    147147                        } );
    148148                }