Edit File by line
/home/barbar84/www/wp-inclu.../js
File: wp-ajax-response.js
/**
[0] Fix | Delete
* @output wp-includes/js/wp-ajax-response.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global wpAjax */
[4] Fix | Delete
[5] Fix | Delete
window.wpAjax = jQuery.extend( {
[6] Fix | Delete
unserialize: function( s ) {
[7] Fix | Delete
var r = {}, q, pp, i, p;
[8] Fix | Delete
if ( !s ) { return r; }
[9] Fix | Delete
q = s.split('?'); if ( q[1] ) { s = q[1]; }
[10] Fix | Delete
pp = s.split('&');
[11] Fix | Delete
for ( i in pp ) {
[12] Fix | Delete
if ( typeof pp.hasOwnProperty === 'function' && !pp.hasOwnProperty(i) ) { continue; }
[13] Fix | Delete
p = pp[i].split('=');
[14] Fix | Delete
r[p[0]] = p[1];
[15] Fix | Delete
}
[16] Fix | Delete
return r;
[17] Fix | Delete
},
[18] Fix | Delete
parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission.
[19] Fix | Delete
var parsed = {}, re = jQuery('#' + r).empty(), err = '';
[20] Fix | Delete
[21] Fix | Delete
if ( x && typeof x === 'object' && x.getElementsByTagName('wp_ajax') ) {
[22] Fix | Delete
parsed.responses = [];
[23] Fix | Delete
parsed.errors = false;
[24] Fix | Delete
jQuery('response', x).each( function() {
[25] Fix | Delete
var th = jQuery(this), child = jQuery(this.firstChild), response;
[26] Fix | Delete
response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') };
[27] Fix | Delete
response.data = jQuery( 'response_data', child ).text();
[28] Fix | Delete
response.supplemental = {};
[29] Fix | Delete
if ( !jQuery( 'supplemental', child ).children().each( function() {
[30] Fix | Delete
response.supplemental[this.nodeName] = jQuery(this).text();
[31] Fix | Delete
} ).length ) { response.supplemental = false; }
[32] Fix | Delete
response.errors = [];
[33] Fix | Delete
if ( !jQuery('wp_error', child).each( function() {
[34] Fix | Delete
var code = jQuery(this).attr('code'), anError, errorData, formField;
[35] Fix | Delete
anError = { code: code, message: this.firstChild.nodeValue, data: false };
[36] Fix | Delete
errorData = jQuery('wp_error_data[code="' + code + '"]', x);
[37] Fix | Delete
if ( errorData ) { anError.data = errorData.get(); }
[38] Fix | Delete
formField = jQuery( 'form-field', errorData ).text();
[39] Fix | Delete
if ( formField ) { code = formField; }
[40] Fix | Delete
if ( e ) { wpAjax.invalidateForm( jQuery('#' + e + ' :input[name="' + code + '"]' ).parents('.form-field:first') ); }
[41] Fix | Delete
err += '<p>' + anError.message + '</p>';
[42] Fix | Delete
response.errors.push( anError );
[43] Fix | Delete
parsed.errors = true;
[44] Fix | Delete
} ).length ) { response.errors = false; }
[45] Fix | Delete
parsed.responses.push( response );
[46] Fix | Delete
} );
[47] Fix | Delete
if ( err.length ) { re.html( '<div class="error">' + err + '</div>' ); }
[48] Fix | Delete
return parsed;
[49] Fix | Delete
}
[50] Fix | Delete
if ( isNaN(x) ) { return !re.html('<div class="error"><p>' + x + '</p></div>'); }
[51] Fix | Delete
x = parseInt(x,10);
[52] Fix | Delete
if ( -1 === x ) { return !re.html('<div class="error"><p>' + wpAjax.noPerm + '</p></div>'); }
[53] Fix | Delete
else if ( 0 === x ) { return !re.html('<div class="error"><p>' + wpAjax.broken + '</p></div>'); }
[54] Fix | Delete
return true;
[55] Fix | Delete
},
[56] Fix | Delete
invalidateForm: function ( selector ) {
[57] Fix | Delete
return jQuery( selector ).addClass( 'form-invalid' ).find('input').one( 'change wp-check-valid-field', function() { jQuery(this).closest('.form-invalid').removeClass( 'form-invalid' ); } );
[58] Fix | Delete
},
[59] Fix | Delete
validateForm: function( selector ) {
[60] Fix | Delete
selector = jQuery( selector );
[61] Fix | Delete
return !wpAjax.invalidateForm( selector.find('.form-required').filter( function() { return jQuery('input:visible', this).val() === ''; } ) ).length;
[62] Fix | Delete
}
[63] Fix | Delete
}, wpAjax || { noPerm: 'Sorry, you are not allowed to do that.', broken: 'Something went wrong.' } );
[64] Fix | Delete
[65] Fix | Delete
// Basic form validation.
[66] Fix | Delete
jQuery(document).ready( function($){
[67] Fix | Delete
$('form.validate').on( 'submit', function() { return wpAjax.validateForm( $(this) ); } );
[68] Fix | Delete
});
[69] Fix | Delete
[70] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function