Skip to content
Permalink
Browse files

Administration: In `add_settings_error()`, add `warning` and `info` a…

…s 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@45814 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Aug 15, 2019
1 parent d65b89c commit 7113ab1f51699cf2098791b735f1521c3b1c2cd7
Showing with 21 additions and 7 deletions.
  1. +21 −7 src/wp-admin/includes/template.php
@@ -1685,15 +1685,16 @@ function do_settings_fields( $page, $section ) {
* page is first accessed.
*
* @since 3.0.0
* @since 5.3.0 Added `warning` and `info` as possible values for `$type`.
*
* @global array $wp_settings_errors Storage array of errors registered during this pageload
*
* @param string $setting Slug title of the setting to which this error applies.
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
* @param string $message The formatted message text to display to the user (will be shown inside styled
* `<div>` and `<p>` tags).
* @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
* Default 'error'.
* @param string $type Optional. Message type, controls HTML class. Possible values include 'error',
* 'success', 'warning', 'info'. Default 'error'.
*/
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
global $wp_settings_errors;
@@ -1787,6 +1788,8 @@ function get_settings_errors( $setting = '', $sanitize = false ) {
* missing settings when the user arrives at the settings page.
*
* @since 3.0.0
* @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to
* `notice-error` and `notice-success`.
*
* @param string $setting Optional slug title of a specific setting whose errors you want.
* @param bool $sanitize Whether to re-sanitize the setting value before returning errors.
@@ -1807,11 +1810,22 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa
$output = '';
foreach ( $settings_errors as $key => $details ) {
$css_id = 'setting-error-' . $details['code'];
$css_class = $details['type'] . ' settings-error notice is-dismissible';
$output .= "<div id='$css_id' class='$css_class'> \n";
$output .= "<p><strong>{$details['message']}</strong></p>";
$output .= "</div> \n";
if ( 'updated' === $details['type'] ) {
$details['type'] = 'success';
}
$css_id = sprintf(
'setting-error-%s',
sanitize_html_class( $details['code'] )
);
$css_class = sprintf(
'notice notice-%s settings-error is-dismissible',
sanitize_html_class( $details['type'] )
);
$output .= "<div id='$css_id' class='$css_class'> \n";
$output .= "<p><strong>{$details['message']}</strong></p>";
$output .= "</div> \n";
}
echo $output;
}

0 comments on commit 7113ab1

Please sign in to comment.
You can’t perform that action at this time.