Make WordPress Core


Ignore:
Timestamp:
09/18/2023 12:28:24 AM (15 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/wpGetAdminNotice.php

    r56408 r56603  
    209209                'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>',
    210210            ),
     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="&lt;script&gt;alert( &quot;Howdy, admin!&quot; );&lt;/script&gt;"><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            ),
    211269            'paragraph wrapping as a falsy value rather than (bool) false' => array(
    212270                'message'  => 'A notice with paragraph wrapping as a falsy value rather than (bool) false.',
Note: See TracChangeset for help on using the changeset viewer.