Changeset 63943
- Timestamp:
- 09/26/2026 12:37:37 PM (6 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-admin/includes/template.php (modified) (2 diffs)
-
tests/phpunit/tests/admin/includesTemplate.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/template.php
r63648 r63943 1975 1975 * @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to 1976 1976 * `notice-error` and `notice-success`. 1977 * @since 7.2.0 Uses `wp_admin_notice()` to echo the notices so that the CSS 1978 * classes, filters, and hooks are handled consistently. 1977 1979 * 1978 1980 * @param string $setting Optional slug title of a specific setting whose errors you want. … … 1993 1995 } 1994 1996 1995 $output = '';1996 1997 1997 foreach ( $settings_errors as $key => $details ) { 1998 if ( 'updated' === $details['type'] ) { 1999 $details['type'] = 'success'; 2000 } 2001 2002 if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) { 2003 $details['type'] = 'notice-' . $details['type']; 2004 } 2005 2006 $css_id = sprintf( 1998 $type = trim( $details['type'] ); 1999 2000 if ( 'updated' === $type ) { 2001 $type = 'success'; 2002 } 2003 2004 $additional_classes = array( 'settings-error' ); 2005 2006 /* 2007 * Backward compatibility: `wp_admin_notice()` generates the admin notice 2008 * CSS classes based on the passed message type. For example, 'error', 2009 * 'success', 'warning', 'info'. Custom types will be treated as 2010 * additional classes and appended to the end of the CSS classes. 2011 */ 2012 if ( ! in_array( $type, array( 'error', 'success', 'warning', 'info' ), true ) ) { 2013 $additional_classes = array_merge( $additional_classes, explode( ' ', $type ) ); 2014 $type = ''; 2015 } 2016 2017 /* 2018 * Note that the setting error code contains underscores, for example: 2019 * `settings_updated`. This will build a CSS ID selector that contains 2020 * underscores, which are currently not allowed by the WordPress CSS 2021 * Coding Standards. Kept for backwards compatibility. 2022 */ 2023 $css_id = sprintf( 2007 2024 'setting-error-%s', 2008 esc_attr( $details['code'] )2025 $details['code'], 2009 2026 ); 2010 $css_class = sprintf( 2011 'notice %s settings-error is-dismissible', 2012 esc_attr( $details['type'] ) 2027 2028 wp_admin_notice( 2029 "<strong>{$details['message']}</strong>", 2030 array( 2031 'type' => $type, 2032 'code' => $details['code'], 2033 'id' => $css_id, 2034 'paragraph_wrap' => true, 2035 'dismissible' => true, 2036 'additional_classes' => $additional_classes, 2037 ) 2013 2038 ); 2014 2015 $output .= "<div id='$css_id' class='$css_class'> \n"; 2016 $output .= "<p><strong>{$details['message']}</strong></p>"; 2017 $output .= "</div> \n"; 2018 } 2019 2020 echo $output; 2039 } 2021 2040 } 2022 2041 -
trunk/tests/phpunit/tests/admin/includesTemplate.php
r62756 r63943 443 443 $wp_settings_errors = null; 444 444 445 $expected = sprintf( 'notice %s settings-error is-dismissible', $expected );446 447 445 $this->assertStringContainsString( $expected, $output ); 448 446 $this->assertStringNotContainsString( 'notice-notice-', $output ); … … 451 449 public function data_settings_errors_css_classes() { 452 450 return array( 453 array( 'error', 'notice-error' ), 454 array( 'success', 'notice-success' ), 455 array( 'warning', 'notice-warning' ), 456 array( 'info', 'notice-info' ), 457 array( 'updated', 'notice-success' ), 458 array( 'notice-error', 'notice-error' ), 459 array( 'error my-own-css-class hello world', 'error my-own-css-class hello world' ), 451 // The admin notices default types will generate CSS classes in this order. 452 array( 'error', 'notice notice-error is-dismissible settings-error' ), 453 array( 'success', 'notice notice-success is-dismissible settings-error' ), 454 array( 'warning', 'notice notice-warning is-dismissible settings-error' ), 455 array( 'info', 'notice notice-info is-dismissible settings-error' ), 456 array( 'updated', 'notice notice-success is-dismissible settings-error' ), 457 /* 458 * Backward compatibility: custom types and anything else (e.g. 459 * strings with spaces) are now passed as additional_classes. As 460 * such, the classes will be appended to the end of the generated 461 * class attribute. 462 */ 463 array( 'notice-error', 'notice is-dismissible settings-error notice-error' ), 464 array( 'custom', 'notice is-dismissible settings-error custom' ), 465 array( 'error my-own-css-class hello world', 'notice is-dismissible settings-error error my-own-css-class hello world' ), 466 array( 'error my-notice-is-awesome hello world', 'notice is-dismissible settings-error error my-notice-is-awesome hello world' ), 460 467 ); 461 468 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)