Changeset 64347
- Timestamp:
- 10/14/2026 07:34:43 PM (31 hours ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 6 edited
-
src/js/_enqueues/admin/common.js (modified) (3 diffs)
-
src/wp-admin/admin.php (modified) (1 diff)
-
src/wp-includes/class-wp-admin-notice-collector.php (deleted)
-
src/wp-includes/functions.php (modified) (2 diffs)
-
src/wp-settings.php (modified) (1 diff)
-
tests/phpunit/tests/functions/wpAdminNotice.php (modified) (36 diffs)
-
tests/phpunit/tests/functions/wpGetAdminNotice.php (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/common.js
r64301 r64347 1076 1076 } 1077 1077 1078 /* 1079 * The `.below-h2` class is here just for backward compatibility with plugins 1080 * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570. 1081 * If '.wp-header-end' is found, append the notices after it otherwise 1082 * after the first h1 or h2 heading found within the main content. 1083 */ 1084 if ( ! $headerEnd.length ) { 1085 $headerEnd = $( '.wrap h1, .wrap h2' ).first(); 1086 } 1087 $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd ); 1088 1078 1089 /** 1079 1090 * Makes notices dismissible. … … 1514 1525 input.on('change', toggleUploadButton); 1515 1526 })(); 1516 1517 /**1518 * Moves the admin notices into an `aside` element after the first `h1`.1519 * Prior to 7.2.0, admin notices were only moved after the first `h1`;1520 * The `aside` wrapper was added in 7.2.0.1521 *1522 * @since 7.2.01523 *1524 * @return {void}1525 */1526 function moveAdminNotices() {1527 /*1528 * The `.below-h2` class is here just for backward compatibility with plugins1529 * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570.1530 * If '.wp-header-end' is found, append the notices after it otherwise1531 * after the first h1 or h2 heading found within the main content.1532 */1533 if ( ! $headerEnd.length ) {1534 $headerEnd = $( '.wrap h1, .wrap h2' ).first();1535 }1536 const $notices = $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' );1537 if ( $notices.length ) {1538 const $wpAdminNotices = $( '<aside id="wp-admin-notices"></aside>' ).attr( 'aria-label', __( 'Admin Notices' ) ).insertAfter( $headerEnd );1539 $notices.appendTo( $wpAdminNotices );1540 }1541 }1542 1527 1543 1528 /** … … 2144 2129 2145 2130 window.wpResponsive.init(); 2146 moveAdminNotices();2147 2131 setPinMenu(); 2148 2132 setMenuState(); -
trunk/src/wp-admin/admin.php
r64282 r64347 101 101 102 102 require_once ABSPATH . 'wp-admin/includes/admin.php'; 103 104 WP_Admin_Notice_Collector::init();105 103 106 104 auth_redirect(); -
trunk/src/wp-includes/functions.php
r64305 r64347 9346 9346 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 9347 9347 9348 // Unique ID is intended for internal use, and is not a filterable argument.9349 $unique_id = wp_unique_prefixed_id( 'wp-admin-notice-' );9350 $args['notice_id'] = $unique_id;9351 9352 9348 $wrap_with_p = false !== $args['paragraph_wrap']; 9353 9349 $wrap_opener = $wrap_with_p ? '<p>' : ''; … … 9359 9355 $trimmed_id = trim( $args['id'] ); 9360 9356 9361 $html_builder->set_attribute( 'data-id', $unique_id );9362 9357 if ( '' !== $trimmed_id ) { 9363 9358 $html_builder->set_attribute( 'id', $trimmed_id ); 9364 } else { 9365 $html_builder->set_attribute( 'id', $unique_id ); 9366 } 9367 } else { 9368 $html_builder->set_attribute( 'data-id', $unique_id ); 9369 $html_builder->set_attribute( 'id', $unique_id ); 9359 } 9370 9360 } 9371 9361 -
trunk/src/wp-settings.php
r64337 r64347 116 116 require ABSPATH . WPINC . '/meta.php'; 117 117 require ABSPATH . WPINC . '/functions.php'; 118 require ABSPATH . WPINC . '/class-wp-admin-notice-collector.php';119 118 require ABSPATH . WPINC . '/class-wp-meta-query.php'; 120 119 require ABSPATH . WPINC . '/class-wp-matchesmapregex.php'; -
trunk/tests/phpunit/tests/functions/wpAdminNotice.php
r64282 r64347 22 22 */ 23 23 public function test_should_output_admin_notice( $message, $args, $expected ) { 24 // Replace placeholder %%ID%% in expected string, required for test isolation.25 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) );26 ++$next_id;27 $expected = str_replace( '%%ID%%', $next_id, $expected );28 29 24 ob_start(); 30 25 wp_admin_notice( $message, $args ); … … 44 39 'message' => 'A notice with defaults.', 45 40 'args' => array(), 46 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with defaults.</p></div>',41 'expected' => '<div class="notice"><p>A notice with defaults.</p></div>', 47 42 ), 48 43 'an empty message (used for templates)' => array( … … 54 49 'additional_classes' => array( 'inline', 'hidden' ), 55 50 ), 56 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>',51 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>', 57 52 ), 58 53 'an empty message (used for templates) without paragraph wrapping' => array( … … 65 60 'paragraph_wrap' => false, 66 61 ), 67 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice notice-error is-dismissible inline hidden"></div>',62 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"></div>', 68 63 ), 69 64 'an "error" notice' => array( … … 72 67 'type' => 'error', 73 68 ), 74 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-error"><p>An "error" notice.</p></div>',69 'expected' => '<div class="notice notice-error"><p>An "error" notice.</p></div>', 75 70 ), 76 71 'a "success" notice' => array( … … 79 74 'type' => 'success', 80 75 ), 81 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-success"><p>A "success" notice.</p></div>',76 'expected' => '<div class="notice notice-success"><p>A "success" notice.</p></div>', 82 77 ), 83 78 'a "warning" notice' => array( … … 86 81 'type' => 'warning', 87 82 ), 88 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-warning"><p>A "warning" notice.</p></div>',83 'expected' => '<div class="notice notice-warning"><p>A "warning" notice.</p></div>', 89 84 ), 90 85 'an "info" notice' => array( … … 93 88 'type' => 'info', 94 89 ), 95 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-info"><p>An "info" notice.</p></div>',90 'expected' => '<div class="notice notice-info"><p>An "info" notice.</p></div>', 96 91 ), 97 92 'a type that already starts with "notice-"' => array( … … 100 95 'type' => 'notice-info', 101 96 ), 102 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>',97 'expected' => '<div class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>', 103 98 ), 104 99 'a dismissible notice' => array( … … 107 102 'dismissible' => true, 108 103 ), 109 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice is-dismissible"><p>A dismissible notice.</p></div>',104 'expected' => '<div class="notice is-dismissible"><p>A dismissible notice.</p></div>', 110 105 ), 111 106 'no type and an ID' => array( … … 114 109 'id' => 'message', 115 110 ), 116 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice"><p>A notice with an ID.</p></div>',111 'expected' => '<div id="message" class="notice"><p>A notice with an ID.</p></div>', 117 112 ), 118 113 'a type and an ID' => array( … … 122 117 'id' => 'message', 123 118 ), 124 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>',119 'expected' => '<div id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>', 125 120 ), 126 121 'no type and additional classes' => array( … … 129 124 'additional_classes' => array( 'error', 'notice-alt' ), 130 125 ), 131 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice error notice-alt"><p>A notice with additional classes.</p></div>',126 'expected' => '<div class="notice error notice-alt"><p>A notice with additional classes.</p></div>', 132 127 ), 133 128 'a type and additional classes' => array( … … 137 132 'additional_classes' => array( 'error', 'notice-alt' ), 138 133 ), 139 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>',134 'expected' => '<div class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>', 140 135 ), 141 136 'a dismissible notice with a type and additional classes' => array( … … 146 141 'additional_classes' => array( 'error', 'notice-alt' ), 147 142 ), 148 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>',143 'expected' => '<div class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>', 149 144 ), 150 145 'a notice without paragraph wrapping' => array( … … 153 148 'paragraph_wrap' => false, 154 149 ), 155 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><span>A notice without paragraph wrapping.</span></div>',150 'expected' => '<div class="notice"><span>A notice without paragraph wrapping.</span></div>', 156 151 ), 157 152 'an unsafe type' => array( … … 160 155 'type' => '"><script>alert("Howdy,admin!");</script>', 161 156 ), 162 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-"><script>alert("Howdy,admin!");</script>"><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>', 163 158 ), 164 159 'an unsafe ID' => array( … … 167 162 'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice', 168 163 ), 169 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="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>', 170 165 ), 171 166 'unsafe additional classes' => array( … … 174 169 'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ), 175 170 ), 176 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice "><script>alert( "Howdy, admin!" );</script> <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>', 177 172 ), 178 173 'a type that is not a string' => array( … … 181 176 'type' => array(), 182 177 ), 183 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with a type that is not a string.</p></div>',178 'expected' => '<div class="notice"><p>A notice with a type that is not a string.</p></div>', 184 179 ), 185 180 'a type with only empty space' => array( … … 188 183 'type' => " \t\r\n", 189 184 ), 190 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with a type with only empty space.</p></div>',185 'expected' => '<div class="notice"><p>A notice with a type with only empty space.</p></div>', 191 186 ), 192 187 'an ID that is not a string' => array( … … 195 190 'id' => array( 'message' ), 196 191 ), 197 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with an ID that is not a string.</p></div>',192 'expected' => '<div class="notice"><p>A notice with an ID that is not a string.</p></div>', 198 193 ), 199 194 'an ID with only empty space' => array( … … 202 197 'id' => " \t\r\n", 203 198 ), 204 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with an ID with only empty space.</p></div>',199 'expected' => '<div class="notice"><p>A notice with an ID with only empty space.</p></div>', 205 200 ), 206 201 'dismissible as a truthy value rather than (bool) true' => array( … … 209 204 'dismissible' => 1, 210 205 ), 211 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>',206 'expected' => '<div class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>', 212 207 ), 213 208 'additional classes that are not an array' => array( … … 216 211 'additional_classes' => 'class-1 class-2 class-3', 217 212 ), 218 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with additional classes that are not an array.</p></div>',213 'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>', 219 214 ), 220 215 'additional attribute with a value' => array( … … 223 218 'attributes' => array( 'aria-live' => 'assertive' ), 224 219 ), 225 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>',220 'expected' => '<div class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>', 226 221 ), 227 222 'additional hidden attribute' => array( … … 230 225 'attributes' => array( 'hidden' => true ), 231 226 ), 232 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" hidden><p>A notice with the hidden attribute.</p></div>',227 'expected' => '<div class="notice" hidden><p>A notice with the hidden attribute.</p></div>', 233 228 ), 234 229 'additional attribute no associative keys' => array( … … 237 232 'attributes' => array( 'hidden' ), 238 233 ), 239 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>',234 'expected' => '<div class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>', 240 235 ), 241 236 'additional attribute with role' => array( … … 244 239 'attributes' => array( 'role' => 'alert' ), 245 240 ), 246 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>',241 'expected' => '<div class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>', 247 242 ), 248 243 'multiple additional attributes' => array( … … 254 249 ), 255 250 ), 256 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>',251 'expected' => '<div class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>', 257 252 ), 258 253 'data attribute with unsafe value' => array( … … 261 256 'attributes' => array( 'data-unsafe' => '<script>alert( "Howdy, admin!" );</script>' ), 262 257 ), 263 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>',258 'expected' => '<div class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>', 264 259 ), 265 260 'additional invalid attribute' => array( … … 268 263 'attributes' => array( 'not-valid' => 'not-valid' ), 269 264 ), 270 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with an additional attribute that is invalid.</p></div>',265 'expected' => '<div class="notice"><p>A notice with an additional attribute that is invalid.</p></div>', 271 266 ), 272 267 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array( … … 281 276 ), 282 277 ), 283 'expected' => '<div id="wp-admin-notice-%%ID%%"class="notice" role="alert" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>',278 'expected' => '<div class="notice" role="alert" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>', 284 279 ), 285 280 'paragraph wrapping as a falsy value rather than (bool) false' => array( … … 288 283 'paragraph_wrap' => 0, 289 284 ), 290 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>',285 'expected' => '<div class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>', 291 286 ), 292 287 ); … … 301 296 */ 302 297 public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() { 303 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) );304 ++$next_id;305 306 298 ob_start(); 307 299 wp_admin_notice( … … 312 304 313 305 $this->assertSame( 314 '<div class="notice notice-first second third fourth" data-id="wp-admin-notice-' . $next_id . '" id="wp-admin-notice-' . $next_id . '"><p>A type containing spaces.</p></div>',306 '<div class="notice notice-first second third fourth"><p>A type containing spaces.</p></div>', 315 307 $actual 316 308 ); -
trunk/tests/phpunit/tests/functions/wpGetAdminNotice.php
r64282 r64347 22 22 */ 23 23 public function test_should_return_admin_notice( $message, $args, $expected ) { 24 // Replace placeholder %%ID%% in expected string, required for test isolation.25 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) );26 ++$next_id;27 $expected = str_replace( '%%ID%%', $next_id, $expected );28 29 24 $this->assertEqualHTML( $expected, wp_get_admin_notice( $message, $args ) ); 30 25 } … … 40 35 'message' => 'A notice with defaults.', 41 36 'args' => array(), 42 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with defaults.</p></div>',37 'expected' => '<div class="notice"><p>A notice with defaults.</p></div>', 43 38 ), 44 39 'an empty message (used for templates)' => array( … … 50 45 'additional_classes' => array( 'inline', 'hidden' ), 51 46 ), 52 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>',47 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>', 53 48 ), 54 49 'an empty message (used for templates) without paragraph wrapping' => array( … … 61 56 'paragraph_wrap' => false, 62 57 ), 63 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice notice-error is-dismissible inline hidden"></div>',58 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"></div>', 64 59 ), 65 60 'an "error" notice' => array( … … 68 63 'type' => 'error', 69 64 ), 70 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-error"><p>An "error" notice.</p></div>',65 'expected' => '<div class="notice notice-error"><p>An "error" notice.</p></div>', 71 66 ), 72 67 'a "success" notice' => array( … … 75 70 'type' => 'success', 76 71 ), 77 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-success"><p>A "success" notice.</p></div>',72 'expected' => '<div class="notice notice-success"><p>A "success" notice.</p></div>', 78 73 ), 79 74 'a "warning" notice' => array( … … 82 77 'type' => 'warning', 83 78 ), 84 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-warning"><p>A "warning" notice.</p></div>',79 'expected' => '<div class="notice notice-warning"><p>A "warning" notice.</p></div>', 85 80 ), 86 81 'an "info" notice' => array( … … 89 84 'type' => 'info', 90 85 ), 91 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-info"><p>An "info" notice.</p></div>',86 'expected' => '<div class="notice notice-info"><p>An "info" notice.</p></div>', 92 87 ), 93 88 'a type that already starts with "notice-"' => array( … … 96 91 'type' => 'notice-info', 97 92 ), 98 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>',93 'expected' => '<div class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>', 99 94 ), 100 95 'a dismissible notice' => array( … … 103 98 'dismissible' => true, 104 99 ), 105 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice is-dismissible"><p>A dismissible notice.</p></div>',100 'expected' => '<div class="notice is-dismissible"><p>A dismissible notice.</p></div>', 106 101 ), 107 102 'no type and an ID' => array( … … 110 105 'id' => 'message', 111 106 ), 112 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice"><p>A notice with an ID.</p></div>',107 'expected' => '<div id="message" class="notice"><p>A notice with an ID.</p></div>', 113 108 ), 114 109 'a type and an ID' => array( … … 118 113 'id' => 'message', 119 114 ), 120 'expected' => '<div data-id="wp-admin-notice-%%ID%%"id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>',115 'expected' => '<div id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>', 121 116 ), 122 117 'no type and additional classes' => array( … … 125 120 'additional_classes' => array( 'error', 'notice-alt' ), 126 121 ), 127 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice error notice-alt"><p>A notice with additional classes.</p></div>',122 'expected' => '<div class="notice error notice-alt"><p>A notice with additional classes.</p></div>', 128 123 ), 129 124 'a type and additional classes' => array( … … 133 128 'additional_classes' => array( 'error', 'notice-alt' ), 134 129 ), 135 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>',130 'expected' => '<div class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>', 136 131 ), 137 132 'a dismissible notice with a type and additional classes' => array( … … 142 137 'additional_classes' => array( 'error', 'notice-alt' ), 143 138 ), 144 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>',139 'expected' => '<div class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>', 145 140 ), 146 141 'a notice without paragraph wrapping' => array( … … 149 144 'paragraph_wrap' => false, 150 145 ), 151 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><span>A notice without paragraph wrapping.</span></div>',146 'expected' => '<div class="notice"><span>A notice without paragraph wrapping.</span></div>', 152 147 ), 153 148 'an unsafe type' => array( … … 156 151 'type' => '"><script>alert("Howdy,admin!");</script>', 157 152 ), 158 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"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>', 159 154 ), 160 155 'an unsafe ID' => array( … … 163 158 'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice', 164 159 ), 165 'expected' => '<div data-id="wp-admin-notice-%%ID%%"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>', 166 161 ), 167 162 'unsafe additional classes' => array( … … 170 165 'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ), 171 166 ), 172 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"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>', 173 168 ), 174 169 'a type that is not a string' => array( … … 177 172 'type' => array(), 178 173 ), 179 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with a type that is not a string.</p></div>',174 'expected' => '<div class="notice"><p>A notice with a type that is not a string.</p></div>', 180 175 ), 181 176 'a type with only empty space' => array( … … 184 179 'type' => " \t\r\n", 185 180 ), 186 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with a type with only empty space.</p></div>',181 'expected' => '<div class="notice"><p>A notice with a type with only empty space.</p></div>', 187 182 ), 188 183 'an ID that is not a string' => array( … … 191 186 'id' => array( 'message' ), 192 187 ), 193 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with an ID that is not a string.</p></div>',188 'expected' => '<div class="notice"><p>A notice with an ID that is not a string.</p></div>', 194 189 ), 195 190 'an ID with only empty space' => array( … … 198 193 'id' => " \t\r\n", 199 194 ), 200 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with an ID with only empty space.</p></div>',195 'expected' => '<div class="notice"><p>A notice with an ID with only empty space.</p></div>', 201 196 ), 202 197 'dismissible as a truthy value rather than (bool) true' => array( … … 205 200 'dismissible' => 1, 206 201 ), 207 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>',202 'expected' => '<div class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>', 208 203 ), 209 204 'additional classes that are not an array' => array( … … 212 207 'additional_classes' => 'class-1 class-2 class-3', 213 208 ), 214 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with additional classes that are not an array.</p></div>',209 'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>', 215 210 ), 216 211 'additional attribute with a value' => array( … … 219 214 'attributes' => array( 'aria-live' => 'assertive' ), 220 215 ), 221 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>',216 'expected' => '<div class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>', 222 217 ), 223 218 'additional hidden attribute' => array( … … 226 221 'attributes' => array( 'hidden' => true ), 227 222 ), 228 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" hidden><p>A notice with the hidden attribute.</p></div>',223 'expected' => '<div class="notice" hidden><p>A notice with the hidden attribute.</p></div>', 229 224 ), 230 225 'additional attribute no associative keys' => array( … … 233 228 'attributes' => array( 'hidden' ), 234 229 ), 235 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>',230 'expected' => '<div class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>', 236 231 ), 237 232 'additional attribute with role' => array( … … 240 235 'attributes' => array( 'role' => 'alert' ), 241 236 ), 242 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>',237 'expected' => '<div class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>', 243 238 ), 244 239 'multiple additional attributes' => array( … … 250 245 ), 251 246 ), 252 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>',247 'expected' => '<div class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>', 253 248 ), 254 249 'data attribute with unsafe value' => array( … … 257 252 'attributes' => array( 'data-unsafe' => '<script>alert( "Howdy, admin!" );</script>' ), 258 253 ), 259 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>',254 'expected' => '<div class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>', 260 255 ), 261 256 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array( … … 270 265 ), 271 266 ), 272 'expected' => '<div id="wp-admin-notice-%%ID%%"class="notice" role="alert" disabled="disabled" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>',267 'expected' => '<div class="notice" role="alert" disabled="disabled" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>', 273 268 ), 274 269 'paragraph wrapping as a falsy value rather than (bool) false' => array( … … 277 272 'paragraph_wrap' => 0, 278 273 ), 279 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%"class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>',274 'expected' => '<div class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>', 280 275 ), 281 276 ); … … 291 286 */ 292 287 public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() { 293 // Replace placeholder %%ID%% in expected string, required for test isolation. 294 $expected = '<div class="notice notice-first second third fourth" id="wp-admin-notice-%%ID%%" data-id="wp-admin-notice-%%ID%%"><p>A type containing spaces.</p></div>'; 295 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) ); 296 ++$next_id; 297 $expected = str_replace( '%%ID%%', $next_id, $expected ); 298 299 $this->assertEqualHTML( 300 $expected, 288 $this->assertSame( 289 '<div class="notice notice-first second third fourth"><p>A type containing spaces.</p></div>', 301 290 wp_get_admin_notice( 302 291 'A type containing spaces.',
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)