Administration: Remove term page check from ajax-response.js.

Replace hard coded check for the term creation page in `_enqueues/lib/ajax-response.js` with a check for a notification to display in the AJAX response data.

Follow up to  [52170], [52672].

Props SergeyBiryukov, ryokuhi, johnregan3, sabernhardt, joedolson.
Fixes #55078.
See #54955.


git-svn-id: https://develop.svn.wordpress.org/trunk@53123 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2022-04-11 04:35:37 +00:00
parent 59b4b3e6a6
commit c0ab51309e
2 changed files with 15 additions and 8 deletions

View File

@ -18,7 +18,7 @@ window.wpAjax = jQuery.extend( {
return r;
},
parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission.
var parsed = {}, re = jQuery('#' + r).empty(), err = '', successmsg = '';
var parsed = {}, re = jQuery('#' + r).empty(), err = '', noticeMessage = '';
if ( x && typeof x === 'object' && x.getElementsByTagName('wp_ajax') ) {
parsed.responses = [];
@ -27,11 +27,14 @@ window.wpAjax = jQuery.extend( {
var th = jQuery(this), child = jQuery(this.firstChild), response;
response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') };
response.data = jQuery( 'response_data', child ).text();
if ( jQuery( 'body' ).hasClass( 'edit-tags-php' ) ) {
successmsg += response.data;
}
response.supplemental = {};
if ( !jQuery( 'supplemental', child ).children().each( function() {
if ( this.nodeName === 'notice' ) {
noticeMessage += jQuery(this).text();
return;
}
response.supplemental[this.nodeName] = jQuery(this).text();
} ).length ) { response.supplemental = false; }
response.errors = [];
@ -52,10 +55,10 @@ window.wpAjax = jQuery.extend( {
if ( err.length ) {
re.html( '<div class="error">' + err + '</div>' );
wp.a11y.speak( err );
} else if ( successmsg.length ) {
re.html( '<div class="updated notice is-dismissible"><p>' + successmsg + '</p></div>');
} else if ( noticeMessage.length ) {
re.html( '<div class="updated notice is-dismissible"><p>' + noticeMessage + '</p></div>');
jQuery(document).trigger( 'wp-updates-notice-added' );
wp.a11y.speak( successmsg );
wp.a11y.speak( noticeMessage );
}
return parsed;
}

View File

@ -1121,7 +1121,11 @@ function wp_ajax_add_tag() {
array(
'what' => 'taxonomy',
'data' => $message,
'supplemental' => compact( 'parents', 'noparents' ),
'supplemental' => array(
'parents' => $parents,
'noparents' => $noparents,
'notice' => $message,
),
)
);