Make WordPress Core


Ignore:
Timestamp:
09/18/2023 12:28:24 AM (3 years 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/src/wp-admin/includes/misc.php

    r56549 r56603  
    16591659 *     @type string   $id                 Optional. The value of the admin notice's ID attribute. Default empty string.
    16601660 *     @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.
    16611662 *     @type bool     $paragraph_wrap     Optional. Whether to wrap the message in paragraph tags. Default true.
    16621663 * }
     
    16691670                'id'                 => '',
    16701671                'additional_classes' => array(),
     1672                'attributes'         => array(),
    16711673                'paragraph_wrap'     => true,
    16721674        );
     
    16821684         * @param string $message The message for the admin notice.
    16831685         */
    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 = '';
    16871690
    16881691        if ( is_string( $args['id'] ) ) {
     
    17221725        }
    17231726
     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
    17241740        if ( false !== $args['paragraph_wrap'] ) {
    17251741                $message = "<p>$message</p>";
    17261742        }
    17271743
    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 );
    17291745
    17301746        /**
Note: See TracChangeset for help on using the changeset viewer.