Make WordPress Core

Changeset 45814


Ignore:
Timestamp:
08/15/2019 11:00:38 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Administration: In add_settings_error(), add warning and info as possible values for message type.

Account for these new values in settings_errors(), resulting in notice-warning and notice-info CSS classes.

Map legacy error and updated CSS classes to notice-error and notice-success.

Props donmhico, toddhalfpenny, flixos90, desrosj, javorszky, SergeyBiryukov.
Fixes #44640, #44941.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template.php

    r45737 r45814  
    16861686 *
    16871687 * @since 3.0.0
     1688 * @since 5.3.0 Added `warning` and `info` as possible values for `$type`.
    16881689 *
    16891690 * @global array $wp_settings_errors Storage array of errors registered during this pageload
     
    16931694 * @param string $message The formatted message text to display to the user (will be shown inside styled
    16941695 *                        `<div>` and `<p>` tags).
    1695  * @param string $type    Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
    1696  *                        Default 'error'.
     1696 * @param string $type    Optional. Message type, controls HTML class. Possible values include 'error',
     1697 *                        'success', 'warning', 'info'. Default 'error'.
    16971698 */
    16981699function add_settings_error( $setting, $code, $message, $type = 'error' ) {
     
    17881789 *
    17891790 * @since 3.0.0
     1791 * @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to
     1792 *              `notice-error` and `notice-success`.
    17901793 *
    17911794 * @param string $setting        Optional slug title of a specific setting whose errors you want.
     
    18081811    $output = '';
    18091812    foreach ( $settings_errors as $key => $details ) {
    1810         $css_id    = 'setting-error-' . $details['code'];
    1811         $css_class = $details['type'] . ' settings-error notice is-dismissible';
    1812         $output   .= "<div id='$css_id' class='$css_class'> \n";
    1813         $output   .= "<p><strong>{$details['message']}</strong></p>";
    1814         $output   .= "</div> \n";
     1813        if ( 'updated' === $details['type'] ) {
     1814            $details['type'] = 'success';
     1815        }
     1816
     1817        $css_id    = sprintf(
     1818            'setting-error-%s',
     1819            sanitize_html_class( $details['code'] )
     1820        );
     1821        $css_class = sprintf(
     1822            'notice notice-%s settings-error is-dismissible',
     1823            sanitize_html_class( $details['type'] )
     1824        );
     1825
     1826        $output .= "<div id='$css_id' class='$css_class'> \n";
     1827        $output .= "<p><strong>{$details['message']}</strong></p>";
     1828        $output .= "</div> \n";
    18151829    }
    18161830    echo $output;
Note: See TracChangeset for help on using the changeset viewer.