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.

git-svn-id: https://develop.svn.wordpress.org/trunk@45814 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-08-15 23:00:38 +00:00
parent d65b89c5e4
commit 7113ab1f51

View File

@ -1685,6 +1685,7 @@ function do_settings_fields( $page, $section ) {
* page is first accessed. * page is first accessed.
* *
* @since 3.0.0 * @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 * @global array $wp_settings_errors Storage array of errors registered during this pageload
* *
@ -1692,8 +1693,8 @@ function do_settings_fields( $page, $section ) {
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. * @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 * @param string $message The formatted message text to display to the user (will be shown inside styled
* `<div>` and `<p>` tags). * `<div>` and `<p>` tags).
* @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'. * @param string $type Optional. Message type, controls HTML class. Possible values include 'error',
* Default 'error'. * 'success', 'warning', 'info'. Default 'error'.
*/ */
function add_settings_error( $setting, $code, $message, $type = 'error' ) { function add_settings_error( $setting, $code, $message, $type = 'error' ) {
global $wp_settings_errors; 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. * missing settings when the user arrives at the settings page.
* *
* @since 3.0.0 * @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 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. * @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 = ''; $output = '';
foreach ( $settings_errors as $key => $details ) { foreach ( $settings_errors as $key => $details ) {
$css_id = 'setting-error-' . $details['code']; if ( 'updated' === $details['type'] ) {
$css_class = $details['type'] . ' settings-error notice is-dismissible'; $details['type'] = 'success';
$output .= "<div id='$css_id' class='$css_class'> \n"; }
$output .= "<p><strong>{$details['message']}</strong></p>";
$output .= "</div> \n"; $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; echo $output;
} }