Make WordPress Core

Changeset 44049


Ignore:
Timestamp:
12/13/2018 01:26:36 AM (5 years ago)
Author:
iandunn
Message:

KSES: Make the URI attributes DRY.

This commit introduces the wp_kses_uri_attributes function and filter. The function centralizes the list of attributes, in order to prevent inconsistency, and the filter provides a way for plugins to customize the attributes.

Merges [44014] and [44017] to the 3.7 branch.

Location:
branches/3.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src

  • branches/3.7/src/wp-includes/kses.php

    r44019 r44049  
    489489 */
    490490function wp_kses_one_attr( $string, $element ) {
    491     $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
     491    $uris = wp_kses_uri_attributes();
    492492    $allowed_html = wp_kses_allowed_html( 'post' );
    493493    $allowed_protocols = wp_allowed_protocols();
     
    659659
    660660/**
     661 * Helper function listing HTML attributes containing a URL.
     662 *
     663 * This function returns a list of all HTML attributes that must contain
     664 * a URL according to the HTML specification.
     665 *
     666 * This list includes URI attributes both allowed and disallowed by KSES.
     667 *
     668 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
     669 *
     670 * @since 5.0.1
     671 *
     672 * @return array HTML attributes that must include a URL.
     673 */
     674function wp_kses_uri_attributes() {
     675    $uri_attributes = array(
     676        'action',
     677        'archive',
     678        'background',
     679        'cite',
     680        'classid',
     681        'codebase',
     682        'data',
     683        'formaction',
     684        'href',
     685        'icon',
     686        'longdesc',
     687        'manifest',
     688        'poster',
     689        'profile',
     690        'src',
     691        'usemap',
     692        'xmlns',
     693    );
     694
     695    /**
     696     * Filters the list of attributes that are required to contain a URL.
     697     *
     698     * Use this filter to add any `data-` attributes that are required to be
     699     * validated as a URL.
     700     *
     701     * @since 5.0.1
     702     *
     703     * @param array $uri_attributes HTML attributes requiring validation as a URL.
     704     */
     705    $uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );
     706
     707    return $uri_attributes;
     708}
     709
     710/**
    661711 * Callback for wp_kses_split.
    662712 *
     
    850900    $mode = 0;
    851901    $attrname = '';
    852     $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
     902    $uris = wp_kses_uri_attributes();
    853903
    854904    # Loop through the whole attribute list
Note: See TracChangeset for help on using the changeset viewer.