Make WordPress Core

Changeset 44046 for branches/3.8


Ignore:
Timestamp:
12/13/2018 01:22:08 AM (6 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.8 branch.

Location:
branches/3.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

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

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