Changeset 63380
- Timestamp:
- 08/28/2026 12:04:49 AM (2 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/functions.php (modified) (4 diffs)
-
tests/phpunit/tests/functions/wpAdminNotice.php (modified) (4 diffs)
-
tests/phpunit/tests/functions/wpGetAdminNotice.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r63366 r63380 9238 9238 * @param string $message The message for the admin notice. 9239 9239 */ 9240 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 9241 $id = ''; 9242 $classes = 'notice'; 9243 $attributes = ''; 9240 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 9241 9242 $wrap_with_p = false !== $args['paragraph_wrap']; 9243 $wrap_opener = $wrap_with_p ? '<p>' : ''; 9244 $wrap_closer = $wrap_with_p ? '</p>' : ''; 9245 $html_builder = new WP_HTML_Tag_Processor( "<div class=\"notice\">{$wrap_opener}" ); 9246 $html_builder->next_token(); 9244 9247 9245 9248 if ( is_string( $args['id'] ) ) { … … 9247 9250 9248 9251 if ( '' !== $trimmed_id ) { 9249 $ id = 'id="' . $trimmed_id . '" ';9252 $html_builder->set_attribute( 'id', $trimmed_id ); 9250 9253 } 9251 9254 } … … 9254 9257 $type = trim( $args['type'] ); 9255 9258 9256 if ( str _contains( $type, ' ') ) {9259 if ( strlen( $type ) !== strcspn( $type, " \f\t\r\n" ) ) { 9257 9260 _doing_it_wrong( 9258 9261 __FUNCTION__, … … 9267 9270 9268 9271 if ( '' !== $type ) { 9269 $ classes .= ' notice-' . $type;9272 $html_builder->add_class( "notice-{$type}" ); 9270 9273 } 9271 9274 } 9272 9275 9273 9276 if ( true === $args['dismissible'] ) { 9274 $ classes .= ' is-dismissible';9277 $html_builder->add_class( 'is-dismissible' ); 9275 9278 } 9276 9279 9277 9280 if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) { 9278 $classes .= ' ' . implode( ' ', $args['additional_classes'] ); 9281 foreach ( $args['additional_classes'] as $class_name ) { 9282 $html_builder->add_class( $class_name ); 9283 } 9279 9284 } 9280 9285 9281 9286 if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) { 9282 $attributes = ''; 9283 foreach ( $args['attributes'] as $attr => $val ) { 9284 if ( is_bool( $val ) ) { 9285 $attributes .= $val ? ' ' . $attr : ''; 9286 } elseif ( is_int( $attr ) ) { 9287 $attributes .= ' ' . esc_attr( trim( $val ) ); 9288 } elseif ( $val ) { 9289 $attributes .= ' ' . $attr . '="' . esc_attr( trim( $val ) ) . '"'; 9287 foreach ( $args['attributes'] as $name => $value ) { 9288 if ( is_int( $name ) ) { 9289 /* 9290 * Boolean attributes may have been appended as numeric list items, 9291 * for example, with `$args['attributes'][] = 'disabled'`. They should 9292 * be recorded with the value serving as their name. 9293 */ 9294 $html_builder->set_attribute( $value, true ); 9295 } elseif ( true === $value ) { 9296 $html_builder->set_attribute( $name, true ); 9297 } elseif ( false !== $value ) { 9298 $html_builder->set_attribute( $name, trim( (string) $value ) ); 9290 9299 } 9291 9300 } 9292 9301 } 9293 9302 9294 if ( false !== $args['paragraph_wrap'] ) { 9295 $message = "<p>$message</p>"; 9296 } 9297 9298 $markup = sprintf( '<div %1$sclass="%2$s"%3$s>%4$s</div>', $id, $classes, $attributes, $message ); 9303 $markup = $html_builder->get_updated_html(); 9304 $markup .= $message; 9305 $markup .= "{$wrap_closer}</div>"; 9299 9306 9300 9307 /** -
trunk/tests/phpunit/tests/functions/wpAdminNotice.php
r57100 r63380 26 26 $actual = ob_get_clean(); 27 27 28 $this->assert Same( $expected, $actual );28 $this->assertEqualHTML( $expected, $actual ); 29 29 } 30 30 … … 155 155 'type' => '"><script>alert("Howdy,admin!");</script>', 156 156 ), 157 'expected' => '<div class="notice notice- ">alert("Howdy,admin!");"><p>A notice with an unsafe type.</p></div>',157 'expected' => '<div class="notice notice-"><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>', 158 158 ), 159 159 'an unsafe ID' => array( … … 162 162 'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice', 163 163 ), 164 'expected' => '<div id=" ">alert( "Howdy, admin!" ); <divclass="notice"><p>A notice with an unsafe ID.</p></div>',164 'expected' => '<div id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>', 165 165 ), 166 166 'unsafe additional classes' => array( … … 169 169 'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ), 170 170 ), 171 'expected' => '<div class="notice ">alert( "Howdy, admin!" ); <div class="notice"><p>A notice with unsafe additional classes.</p></div>',171 'expected' => '<div class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>', 172 172 ), 173 173 'a type that is not a string' => array( -
trunk/tests/phpunit/tests/functions/wpGetAdminNotice.php
r57100 r63380 22 22 */ 23 23 public function test_should_return_admin_notice( $message, $args, $expected ) { 24 $this->assert Same( $expected, wp_get_admin_notice( $message, $args ) );24 $this->assertEqualHTML( $expected, wp_get_admin_notice( $message, $args ) ); 25 25 } 26 26 … … 151 151 'type' => '"><script>alert("Howdy,admin!");</script>', 152 152 ), 153 'expected' => '<div class="notice notice- "><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>',153 'expected' => '<div class="notice notice-"><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>', 154 154 ), 155 155 'an unsafe ID' => array( … … 158 158 'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice', 159 159 ), 160 'expected' => '<div id=" "><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>',160 'expected' => '<div id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>', 161 161 ), 162 162 'unsafe additional classes' => array( … … 165 165 'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ), 166 166 ), 167 'expected' => '<div class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>',167 'expected' => '<div class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>', 168 168 ), 169 169 'a type that is not a string' => array(
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)