#44640 closed defect (bug) (fixed)
Use current `.notice` CSS classes for settings errors
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.3 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Administration | Keywords: | has-patch |
| Focuses: | Cc: |
Description
The CSS classes error and updated for settings errors are legacy, as numerous releases ago more proper classes notice, notice-success, notice-error etc. were introduced. However, the settings_errors() function still prints divs with the old classes.
We should consider adjusting that for consistency:
- Map
updatedtonotice-success. - Map
errortonotice-error.
Attachments (3)
Change History (10)
#1
@
7 years ago
- Keywords needs-patch added; 2nd-opinion removed
- Milestone changed from Awaiting Review to Future Release
#2
@
7 years ago
- Keywords has-patch added; needs-patch removed
Wondering if the following approach is valid. I did wonder about putting the mapping into it's own function, but seemed overkill.
WAS
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";
}
Proposed
foreach ( $settings_errors as $key => $details ) {
$type_css_class = '';
switch ( $details['type'] ) {
case 'error':
$type_css_class = 'notice-error';
break;
case 'updated':
$type_css_class = 'notice-success';
break;
}
$css_id = 'setting-error-' . $details['code'];
$css_class = $type_css_class . ' settings-error notice is-dismissible';
$output .= "<div id='$css_id' class='$css_class'> \n";
$output .= "<p><strong>{$details['message']}</strong></p>";
$output .= "</div> \n";
}
Tested (by saving "General Settings" with empty email address.
If this looks good will create a patch.
#3
@
6 years ago
I created a patch, 44640.diff, based on @toddhalfpenny code above.
#4
@
6 years ago
Please use the latest patch - 44640.2.diff . It will handle other notice types passed on add_settings_error() better than the first patch I submitted. See #44941.
Reference:
https://developer.wordpress.org/reference/functions/add_settings_error/
I think this is reasonable. Moving to
Future Releaseso a patch can be created.