Make WordPress Core


Ignore:
Timestamp:
09/18/2023 12:28:24 AM (17 months ago)
Author:
joedolson
Message:

Administration: Add support for attributes in wp_admin_notice().

Allow admin notices to be created with additional attributes. Test attributes include hidden, data-*, and role="*" values, which are all in use in various admin notices across core.

This commit adds aria-live and hidden to the KSES global attributes array to support core usages.

Follow up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597], [56599], [56600], [56601], [56602].

Props costdev, joedolson.
See #57791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/wpAdminNotice.php

    r56408 r56603  
    212212                ),
    213213                '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="&lt;script&gt;alert( &quot;Howdy, admin!&quot; );&lt;/script&gt;"><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>',
    214279            ),
    215280            'paragraph wrapping as a falsy value rather than (bool) false' => array(
Note: See TracChangeset for help on using the changeset viewer.