Make WordPress Core


Ignore:
Timestamp:
12/13/2018 12:32:59 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.8 branch.

Location:
branches/4.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

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

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