Make WordPress Core


Ignore:
Timestamp:
12/12/2018 02:38:14 AM (8 years ago)
Author:
jeremyfelt
Message:

KSES: Allow HTML data-* attributes.

Add global support for HTML attributes prefixed data- for authors and contributors, as required by the new editor.

Merges [43727] to trunk.

Props azaozz, peterwilsoncc.
Fixes #33121.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/kses.php

    r43571 r43981  
    10771077 *
    10781078 * @since 4.2.3
     1079 * @since 5.0.0 Add support for `data-*` wildcard attributes.
    10791080 *
    10801081 * @param string $name         The attribute name. Passed by reference. Returns empty string when not allowed.
    … …  
    10911092        $name_low = strtolower( $name );
    10921093        if ( ! isset( $allowed_attr[ $name_low ] ) || '' == $allowed_attr[ $name_low ] ) {
    1093                 $name = $value = $whole = '';
    1094                 return false;
     1094                /*
     1095                 * Allow `data-*` attributes.
     1096                 *
     1097                 * When specifying `$allowed_html`, the attribute name should be set as
     1098                 * `data-*` (not to be mixed with the HTML 4.0 `data` attribute, see
     1099                 * https://www.w3.org/TR/html40/struct/objects.html#adef-data).
     1100                 *
     1101                 * Note: the attribute name should only contain `A-Za-z0-9_-` chars,
     1102                 * double hyphens `--` are not accepted by WordPress.
     1103                 */
     1104                if ( strpos( $name_low, 'data-' ) === 0 && ! empty( $allowed_attr['data-*'] ) && preg_match( '/^data(?:-[a-z0-9_]+)+$/', $name_low, $match ) ) {
     1105                        /*
     1106                         * Add the whole attribute name to the allowed attributes and set any restrictions
     1107                         * for the `data-*` attribute values for the current element.
     1108                         */
     1109                        $allowed_attr[ $match[0] ] = $allowed_attr['data-*'];
     1110                } else {
     1111                        $name = $value = $whole = '';
     1112                        return false;
     1113                }
    10951114        }
    10961115
    … …  
    20922111 *
    20932112 * @since 3.5.0
     2113 * @since 5.0.0 Add support for `data-*` wildcard attributes.
    20942114 * @access private
    20952115 * @ignore
    … …  
    21002120function _wp_add_global_attributes( $value ) {
    21012121        $global_attributes = array(
    2102                 'class' => true,
    2103                 'id'    => true,
    2104                 'style' => true,
    2105                 'title' => true,
    2106                 'role'  => true,
     2122                'class'  => true,
     2123                'id'     => true,
     2124                'style'  => true,
     2125                'title'  => true,
     2126                'role'   => true,
     2127                'data-*' => true,
    21072128        );
    21082129
Note: See TracChangeset for help on using the changeset viewer.