Make WordPress Core

Changeset 53088


Ignore:
Timestamp:
04/07/2022 03:48:16 AM (3 years ago)
Author:
peterwilsoncc
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/tags.js

    r52953 r53088  
    102102        var form = $(this).parents('form');
    103103
    104         if ( ! validateForm( form ) )
    105             return false;
    106 
    107104        if ( addingTerm ) {
    108105            // If we're adding a term, noop the button to avoid duplicate requests.
     
    128125            $('#ajax-response').empty();
    129126            res = wpAjax.parseAjaxResponse( r, 'ajax-response' );
    130             if ( ! res || res.errors )
     127
     128            if ( res.errors && res.responses[0].errors[0].code === 'empty_term_name' ) {
     129                validateForm( form );
     130            }
     131
     132            if ( ! res || res.errors ) {
    131133                return;
     134            }
    132135
    133136            parent = form.find( 'select#parent' ).val();
  • trunk/src/wp-admin/includes/ajax-actions.php

    r53027 r53088  
    10721072
    10731073    if ( ! $tag || is_wp_error( $tag ) ) {
    1074         $message = __( 'An error has occurred. Please reload the page and try again.' );
     1074        $message    = __( 'An error has occurred. Please reload the page and try again.' );
     1075        $error_code = 'error';
    10751076
    10761077        if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
    10771078            $message = $tag->get_error_message();
     1079        }
     1080
     1081        if ( is_wp_error( $tag ) && $tag->get_error_code() ) {
     1082            $error_code = $tag->get_error_code();
    10781083        }
    10791084
     
    10811086            array(
    10821087                'what' => 'taxonomy',
    1083                 'data' => new WP_Error( 'error', $message ),
     1088                'data' => new WP_Error( $error_code, $message ),
    10841089            )
    10851090        );
Note: See TracChangeset for help on using the changeset viewer.