Skip to:
Content

BuddyPress.org

Ticket #8117: 8117.patch

File 8117.patch, 1.4 KB (added by imath, 6 years ago)
  • src/bp-core/js/bp-api-request.js

    diff --git src/bp-core/js/bp-api-request.js src/bp-core/js/bp-api-request.js
    index adae8c848..f3475de2e 100644
    window.bp = window.bp || {}; 
    1616    bp.isRestEnabled = true;
    1717
    1818    // Polyfill wp.apiRequest if WordPress < 4.9
    19     bp.apiRequest = wp.apiRequest || function( options ) {
    20         var url = bpApiSettings.root;
    21 
    22         if ( options.path ) {
    23             url = url + options.path.replace( /^\//, '' );
     19    bp.apiRequest = function( options ) {
     20        if ( ! options.dataType ) {
     21            options.dataType = 'json';
    2422        }
    2523
    26         options.url = url;
    27         options.beforeSend = function( xhr ) {
    28             xhr.setRequestHeader( 'X-WP-Nonce', bpApiSettings.nonce );
    29         };
     24        // WordPress is >= 4.9.0.
     25        if ( wp.apiRequest ) {
     26            return wp.apiRequest( options );
     27
     28        // WordPress is < 4.9.0.
     29        } else {
     30            var url = bpApiSettings.root;
     31
     32            if ( options.path ) {
     33                url = url + options.path.replace( /^\//, '' );
     34            }
    3035
    31         return $.ajax( options );
     36            options.url = url;
     37            options.beforeSend = function( xhr ) {
     38                xhr.setRequestHeader( 'X-WP-Nonce', bpApiSettings.nonce );
     39            };
     40
     41            return $.ajax( options );
     42        }
    3243    };
    3344
    3445} )( window.wp || {}, window.bp, jQuery );