Changeset 56603
- Timestamp:
- 09/18/2023 12:28:24 AM (12 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/misc.php
r56549 r56603 1659 1659 * @type string $id Optional. The value of the admin notice's ID attribute. Default empty string. 1660 1660 * @type string[] $additional_classes Optional. A string array of class names. Default empty array. 1661 * @type string[] $attributes Optional. Additional attributes for the notice div. Default empty array. 1661 1662 * @type bool $paragraph_wrap Optional. Whether to wrap the message in paragraph tags. Default true. 1662 1663 * } … … 1669 1670 'id' => '', 1670 1671 'additional_classes' => array(), 1672 'attributes' => array(), 1671 1673 'paragraph_wrap' => true, 1672 1674 ); … … 1682 1684 * @param string $message The message for the admin notice. 1683 1685 */ 1684 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 1685 $id = ''; 1686 $classes = 'notice'; 1686 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 1687 $id = ''; 1688 $classes = 'notice'; 1689 $attributes = ''; 1687 1690 1688 1691 if ( is_string( $args['id'] ) ) { … … 1722 1725 } 1723 1726 1727 if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) { 1728 $attributes = ''; 1729 foreach ( $args['attributes'] as $attr => $val ) { 1730 if ( is_bool( $val ) ) { 1731 $attributes .= $val ? ' ' . $attr : ''; 1732 } elseif ( is_int( $attr ) ) { 1733 $attributes .= ' ' . esc_attr( trim( $val ) ); 1734 } elseif ( $val ) { 1735 $attributes .= ' ' . $attr . '="' . esc_attr( trim( $val ) ) . '"'; 1736 } 1737 } 1738 } 1739 1724 1740 if ( false !== $args['paragraph_wrap'] ) { 1725 1741 $message = "<p>$message</p>"; 1726 1742 } 1727 1743 1728 $markup = sprintf( '<div %1$sclass="%2$s" >%3$s</div>', $id, $classes, $message );1744 $markup = sprintf( '<div %1$sclass="%2$s"%3$s>%4$s</div>', $id, $classes, $attributes, $message ); 1729 1745 1730 1746 /** -
trunk/src/wp-includes/kses.php
r56559 r56603 2646 2646 'aria-details' => true, 2647 2647 'aria-expanded' => true, 2648 'aria-hidden' => true, 2648 2649 'aria-label' => true, 2649 2650 'aria-labelledby' => true, 2650 'aria- hidden'=> true,2651 'aria-live' => true, 2651 2652 'class' => true, 2652 2653 'data-*' => true, 2653 2654 'dir' => true, 2655 'hidden' => true, 2654 2656 'id' => true, 2655 2657 'lang' => true, -
trunk/tests/phpunit/tests/admin/wpAdminNotice.php
r56408 r56603 212 212 ), 213 213 'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>', 214 ), 215 'additional attribute with a value' => array( 216 'message' => 'A notice with an additional attribute with a value.', 217 'args' => array( 218 'attributes' => array( 'aria-live' => 'assertive' ), 219 ), 220 'expected' => '<div class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>', 221 ), 222 'additional hidden attribute' => array( 223 'message' => 'A notice with the hidden attribute.', 224 'args' => array( 225 'attributes' => array( 'hidden' => true ), 226 ), 227 'expected' => '<div class="notice" hidden><p>A notice with the hidden attribute.</p></div>', 228 ), 229 'additional attribute no associative keys' => array( 230 'message' => 'A notice with a boolean attribute without an associative key.', 231 'args' => array( 232 'attributes' => array( 'hidden' ), 233 ), 234 'expected' => '<div class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>', 235 ), 236 'additional attribute with role' => array( 237 'message' => 'A notice with an additional attribute role.', 238 'args' => array( 239 'attributes' => array( 'role' => 'alert' ), 240 ), 241 'expected' => '<div class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>', 242 ), 243 'multiple additional attributes' => array( 244 'message' => 'A notice with multiple additional attributes.', 245 'args' => array( 246 'attributes' => array( 247 'role' => 'alert', 248 'data-test' => -1, 249 ), 250 ), 251 'expected' => '<div class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>', 252 ), 253 'data attribute with unsafe value' => array( 254 'message' => 'A notice with an additional attribute with an unsafe value.', 255 'args' => array( 256 'attributes' => array( 'data-unsafe' => '<script>alert( "Howdy, admin!" );</script>' ), 257 ), 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>', 259 ), 260 'additional invalid attribute' => array( 261 'message' => 'A notice with an additional attribute that is invalid.', 262 'args' => array( 263 'attributes' => array( 'not-valid' => 'not-valid' ), 264 ), 265 'expected' => '<div class="notice"><p>A notice with an additional attribute that is invalid.</p></div>', 266 ), 267 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array( 268 'message' => 'A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.', 269 'args' => array( 270 'attributes' => array( 271 'role' => 'alert', 272 'disabled' => 'disabled', 273 'data-name' => 'my-name', 274 'data-id' => 1, 275 'hidden', 276 ), 277 ), 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>', 214 279 ), 215 280 'paragraph wrapping as a falsy value rather than (bool) false' => array( -
trunk/tests/phpunit/tests/admin/wpGetAdminNotice.php
r56408 r56603 209 209 'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>', 210 210 ), 211 'additional attribute with a value' => array( 212 'message' => 'A notice with an additional attribute with a value.', 213 'args' => array( 214 'attributes' => array( 'aria-live' => 'assertive' ), 215 ), 216 'expected' => '<div class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>', 217 ), 218 'additional hidden attribute' => array( 219 'message' => 'A notice with the hidden attribute.', 220 'args' => array( 221 'attributes' => array( 'hidden' => true ), 222 ), 223 'expected' => '<div class="notice" hidden><p>A notice with the hidden attribute.</p></div>', 224 ), 225 'additional attribute no associative keys' => array( 226 'message' => 'A notice with a boolean attribute without an associative key.', 227 'args' => array( 228 'attributes' => array( 'hidden' ), 229 ), 230 'expected' => '<div class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>', 231 ), 232 'additional attribute with role' => array( 233 'message' => 'A notice with an additional attribute role.', 234 'args' => array( 235 'attributes' => array( 'role' => 'alert' ), 236 ), 237 'expected' => '<div class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>', 238 ), 239 'multiple additional attributes' => array( 240 'message' => 'A notice with multiple additional attributes.', 241 'args' => array( 242 'attributes' => array( 243 'role' => 'alert', 244 'data-test' => -1, 245 ), 246 ), 247 'expected' => '<div class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>', 248 ), 249 'data attribute with unsafe value' => array( 250 'message' => 'A notice with an additional attribute with an unsafe value.', 251 'args' => array( 252 'attributes' => array( 'data-unsafe' => '<script>alert( "Howdy, admin!" );</script>' ), 253 ), 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>', 255 ), 256 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array( 257 'message' => 'A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.', 258 'args' => array( 259 'attributes' => array( 260 'role' => 'alert', 261 'disabled' => 'disabled', 262 'data-name' => 'my-name', 263 'data-id' => 1, 264 'hidden', 265 ), 266 ), 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>', 268 ), 211 269 'paragraph wrapping as a falsy value rather than (bool) false' => array( 212 270 'message' => 'A notice with paragraph wrapping as a falsy value rather than (bool) false.',
Note: See TracChangeset
for help on using the changeset viewer.