diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php
index b29123f131..adfda0c982 100644
--- a/src/wp-admin/includes/template.php
+++ b/src/wp-admin/includes/template.php
@@ -1814,13 +1814,17 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa
$details['type'] = 'success';
}
+ if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ) ) ) {
+ $details['type'] = 'notice-' . $details['type'];
+ }
+
$css_id = sprintf(
'setting-error-%s',
- sanitize_html_class( $details['code'] )
+ esc_attr( $details['code'] )
);
$css_class = sprintf(
- 'notice notice-%s settings-error is-dismissible',
- sanitize_html_class( $details['type'] )
+ 'notice %s settings-error is-dismissible',
+ esc_attr( $details['type'] )
);
$output .= "
\n";
diff --git a/tests/phpunit/tests/admin/includesTemplate.php b/tests/phpunit/tests/admin/includesTemplate.php
index c0bc3b8884..7e1745125f 100644
--- a/tests/phpunit/tests/admin/includesTemplate.php
+++ b/tests/phpunit/tests/admin/includesTemplate.php
@@ -108,4 +108,81 @@ class Tests_Admin_includesTemplate extends WP_UnitTestCase {
$this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] );
}
+ /**
+ * Test calling get_settings_errors() with variations on where it gets errors from.
+ *
+ * @ticket 42498
+ * @covers ::get_settings_errors()
+ * @global array $wp_settings_errors
+ */
+ public function test_get_settings_errors_sources() {
+ global $wp_settings_errors;
+
+ $blogname_error = array(
+ 'setting' => 'blogname',
+ 'code' => 'blogname',
+ 'message' => 'Capital P dangit!',
+ 'type' => 'error',
+ );
+ $blogdescription_error = array(
+ 'setting' => 'blogdescription',
+ 'code' => 'blogdescription',
+ 'message' => 'Too short',
+ 'type' => 'error',
+ );
+
+ $wp_settings_errors = null;
+ $this->assertSame( array(), get_settings_errors( 'blogname' ) );
+
+ // Test getting errors from transient.
+ $_GET['settings-updated'] = '1';
+ set_transient( 'settings_errors', array( $blogname_error ) );
+ $wp_settings_errors = null;
+ $this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) );
+
+ // Test getting errors from transient and from global.
+ $_GET['settings-updated'] = '1';
+ set_transient( 'settings_errors', array( $blogname_error ) );
+ $wp_settings_errors = null;
+ add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] );
+ $this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() );
+
+ $wp_settings_errors = null;
+ }
+
+ /**
+ * @ticket 44941
+ * @covers ::settings_errors()
+ * @global array $wp_settings_errors
+ * @dataProvider settings_errors_css_classes_provider
+ */
+ public function test_settings_errors_css_classes( $type, $expected ) {
+ global $wp_settings_errors;
+
+ add_settings_error( 'foo', 'bar', 'Capital P dangit!', $type );
+
+ ob_start();
+ settings_errors();
+ $output = ob_get_clean();
+
+ $wp_settings_errors = null;
+
+ $expected = sprintf( 'notice %s settings-error is-dismissible', $expected );
+
+ $this->assertContains( $expected, $output );
+ $this->assertNotContains( 'notice-notice-', $output );
+ }
+
+ public function settings_errors_css_classes_provider() {
+ return array(
+ array( 'error', 'notice-error' ),
+ array( 'success', 'notice-success' ),
+ array( 'warning', 'notice-warning' ),
+ array( 'info', 'notice-info' ),
+ array( 'updated', 'notice-success' ),
+ array( 'notice-error', 'notice-error' ),
+ array( 'error my-own-css-class hello world', 'error my-own-css-class hello world' ),
+ );
+ }
+
}
diff --git a/tests/phpunit/tests/option/sanitize-option.php b/tests/phpunit/tests/option/sanitize-option.php
index edfb180127..0a6ec865bb 100644
--- a/tests/phpunit/tests/option/sanitize-option.php
+++ b/tests/phpunit/tests/option/sanitize-option.php
@@ -158,45 +158,4 @@ class Tests_Sanitize_Option extends WP_UnitTestCase {
);
}
- /**
- * Test calling get_settings_errors() with variations on where it gets errors from.
- *
- * @ticket 42498
- * @covers ::get_settings_errors()
- * @global array $wp_settings_errors
- */
- public function test_get_settings_errors_sources() {
- global $wp_settings_errors;
-
- $blogname_error = array(
- 'setting' => 'blogname',
- 'code' => 'blogname',
- 'message' => 'Capital P dangit!',
- 'type' => 'error',
- );
- $blogdescription_error = array(
- 'setting' => 'blogdescription',
- 'code' => 'blogdescription',
- 'message' => 'Too short',
- 'type' => 'error',
- );
-
- $wp_settings_errors = null;
- $this->assertSame( array(), get_settings_errors( 'blogname' ) );
-
- // Test getting errors from transient.
- $_GET['settings-updated'] = '1';
- set_transient( 'settings_errors', array( $blogname_error ) );
- $wp_settings_errors = null;
- $this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) );
-
- // Test getting errors from transient and from global.
- $_GET['settings-updated'] = '1';
- set_transient( 'settings_errors', array( $blogname_error ) );
- $wp_settings_errors = null;
- add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] );
- $this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() );
-
- $wp_settings_errors = null;
- }
}