Make WordPress Core


Ignore:
Timestamp:
12/13/2018 01:13:46 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 4.3 branch.

Location:
branches/4.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3

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

    r44005 r44041  
    533533 */
    534534function wp_kses_one_attr( $string, $element ) {
    535     $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
     535    $uris = wp_kses_uri_attributes();
    536536    $allowed_html = wp_kses_allowed_html( 'post' );
    537537    $allowed_protocols = wp_allowed_protocols();
     
    733733
    734734/**
     735 * Helper function listing HTML attributes containing a URL.
     736 *
     737 * This function returns a list of all HTML attributes that must contain
     738 * a URL according to the HTML specification.
     739 *
     740 * This list includes URI attributes both allowed and disallowed by KSES.
     741 *
     742 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
     743 *
     744 * @since 5.0.1
     745 *
     746 * @return array HTML attributes that must include a URL.
     747 */
     748function wp_kses_uri_attributes() {
     749    $uri_attributes = array(
     750        'action',
     751        'archive',
     752        'background',
     753        'cite',
     754        'classid',
     755        'codebase',
     756        'data',
     757        'formaction',
     758        'href',
     759        'icon',
     760        'longdesc',
     761        'manifest',
     762        'poster',
     763        'profile',
     764        'src',
     765        'usemap',
     766        'xmlns',
     767    );
     768
     769    /**
     770     * Filters the list of attributes that are required to contain a URL.
     771     *
     772     * Use this filter to add any `data-` attributes that are required to be
     773     * validated as a URL.
     774     *
     775     * @since 5.0.1
     776     *
     777     * @param array $uri_attributes HTML attributes requiring validation as a URL.
     778     */
     779    $uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );
     780
     781    return $uri_attributes;
     782}
     783
     784/**
    735785 * Callback for wp_kses_split.
    736786 *
     
    927977    $mode = 0;
    928978    $attrname = '';
    929     $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
     979    $uris = wp_kses_uri_attributes();
    930980
    931981    // Loop through the whole attribute list
Note: See TracChangeset for help on using the changeset viewer.