Taxonomy: Show error message for terms without a name.
Display an error message to users if they attempt to create a term without a name via the admin-ajax `add-tag` action. This improves the accessibility of the screen by avoiding the use of color alone to indicate an error. Props conner_bw, birgire, afercia. Fixes #47018. Built from https://develop.svn.wordpress.org/trunk@53088 git-svn-id: http://core.svn.wordpress.org/trunk@52677 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8e4e8afe5d
commit
3d9bb812f1
|
@ -1072,15 +1072,20 @@ function wp_ajax_add_tag() {
|
|||
|
||||
if ( ! $tag || is_wp_error( $tag ) ) {
|
||||
$message = __( 'An error has occurred. Please reload the page and try again.' );
|
||||
$error_code = 'error';
|
||||
|
||||
if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
|
||||
$message = $tag->get_error_message();
|
||||
}
|
||||
|
||||
if ( is_wp_error( $tag ) && $tag->get_error_code() ) {
|
||||
$error_code = $tag->get_error_code();
|
||||
}
|
||||
|
||||
$x->add(
|
||||
array(
|
||||
'what' => 'taxonomy',
|
||||
'data' => new WP_Error( 'error', $message ),
|
||||
'data' => new WP_Error( $error_code, $message ),
|
||||
)
|
||||
);
|
||||
$x->send();
|
||||
|
|
|
@ -101,9 +101,6 @@ jQuery( function($) {
|
|||
$('#submit').on( 'click', function(){
|
||||
var form = $(this).parents('form');
|
||||
|
||||
if ( ! validateForm( form ) )
|
||||
return false;
|
||||
|
||||
if ( addingTerm ) {
|
||||
// If we're adding a term, noop the button to avoid duplicate requests.
|
||||
return false;
|
||||
|
@ -127,8 +124,14 @@ jQuery( function($) {
|
|||
|
||||
$('#ajax-response').empty();
|
||||
res = wpAjax.parseAjaxResponse( r, 'ajax-response' );
|
||||
if ( ! res || res.errors )
|
||||
|
||||
if ( res.errors && res.responses[0].errors[0].code === 'empty_term_name' ) {
|
||||
validateForm( form );
|
||||
}
|
||||
|
||||
if ( ! res || res.errors ) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent = form.find( 'select#parent' ).val();
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
/*! This file is auto-generated */
|
||||
jQuery(function(o){var r=!1;o("#the-list").on("click",".delete-tag",function(){var t,e=o(this),n=e.parents("tr"),a=!0;return(a="undefined"!=showNotice?showNotice.warn():a)&&(t=e.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag"),o.post(ajaxurl,t,function(e){"1"==e?(o("#ajax-response").empty(),n.fadeOut("normal",function(){n.remove()}),o('select#parent option[value="'+t.match(/tag_ID=(\d+)/)[1]+'"]').remove(),o("a.tag-link-"+t.match(/tag_ID=(\d+)/)[1]).remove()):("-1"==e?o("#ajax-response").empty().append('<div class="error"><p>'+wp.i18n.__("Sorry, you are not allowed to do that.")+"</p></div>"):o("#ajax-response").empty().append('<div class="error"><p>'+wp.i18n.__("Something went wrong.")+"</p></div>"),n.children().css("backgroundColor",""))}),n.children().css("backgroundColor","#f33")),!1}),o("#edittag").on("click",".delete",function(e){return"undefined"==typeof showNotice||void(showNotice.warn()||e.preventDefault())}),o("#submit").on("click",function(){var s=o(this).parents("form");return validateForm(s)&&(r||(r=!0,s.find(".submit .spinner").addClass("is-active"),o.post(ajaxurl,o("#addtag").serialize(),function(e){var t,n,a;if(r=!1,s.find(".submit .spinner").removeClass("is-active"),o("#ajax-response").empty(),(t=wpAjax.parseAjaxResponse(e,"ajax-response"))&&!t.errors){if(0<(e=s.find("select#parent").val())&&0<o("#tag-"+e).length?o(".tags #tag-"+e).after(t.responses[0].supplemental.noparents):o(".tags").prepend(t.responses[0].supplemental.parents),o(".tags .no-items").remove(),s.find("select#parent")){for(e=t.responses[1].supplemental,n="",a=0;a<t.responses[1].position;a++)n+=" ";s.find("select#parent option:selected").after('<option value="'+e.term_id+'">'+n+e.name+"</option>")}o('input:not([type="checkbox"]):not([type="radio"]):visible, textarea:visible',s).val("")}}))),!1})});
|
||||
jQuery(function(s){var o=!1;s("#the-list").on("click",".delete-tag",function(){var t,e=s(this),n=e.parents("tr"),a=!0;return(a="undefined"!=showNotice?showNotice.warn():a)&&(t=e.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag"),s.post(ajaxurl,t,function(e){"1"==e?(s("#ajax-response").empty(),n.fadeOut("normal",function(){n.remove()}),s('select#parent option[value="'+t.match(/tag_ID=(\d+)/)[1]+'"]').remove(),s("a.tag-link-"+t.match(/tag_ID=(\d+)/)[1]).remove()):("-1"==e?s("#ajax-response").empty().append('<div class="error"><p>'+wp.i18n.__("Sorry, you are not allowed to do that.")+"</p></div>"):s("#ajax-response").empty().append('<div class="error"><p>'+wp.i18n.__("Something went wrong.")+"</p></div>"),n.children().css("backgroundColor",""))}),n.children().css("backgroundColor","#f33")),!1}),s("#edittag").on("click",".delete",function(e){return"undefined"==typeof showNotice||void(showNotice.warn()||e.preventDefault())}),s("#submit").on("click",function(){var r=s(this).parents("form");return o||(o=!0,r.find(".submit .spinner").addClass("is-active"),s.post(ajaxurl,s("#addtag").serialize(),function(e){var t,n,a;if(o=!1,r.find(".submit .spinner").removeClass("is-active"),s("#ajax-response").empty(),(t=wpAjax.parseAjaxResponse(e,"ajax-response")).errors&&"empty_term_name"===t.responses[0].errors[0].code&&validateForm(r),t&&!t.errors){if(0<(e=r.find("select#parent").val())&&0<s("#tag-"+e).length?s(".tags #tag-"+e).after(t.responses[0].supplemental.noparents):s(".tags").prepend(t.responses[0].supplemental.parents),s(".tags .no-items").remove(),r.find("select#parent")){for(e=t.responses[1].supplemental,n="",a=0;a<t.responses[1].position;a++)n+=" ";r.find("select#parent option:selected").after('<option value="'+e.term_id+'">'+n+e.name+"</option>")}s('input:not([type="checkbox"]):not([type="radio"]):visible, textarea:visible',r).val("")}})),!1})});
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.0-alpha-53087';
|
||||
$wp_version = '6.0-alpha-53088';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue