WordPress.org

Make WordPress Core

Changeset 44020


Ignore:
Timestamp:
12/13/2018 12:13:03 AM (10 months 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.9 branch.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

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

    r43997 r44020  
    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();
     
    735735
    736736/**
     737 * Helper function listing HTML attributes containing a URL.
     738 *
     739 * This function returns a list of all HTML attributes that must contain
     740 * a URL according to the HTML specification.
     741 *
     742 * This list includes URI attributes both allowed and disallowed by KSES.
     743 *
     744 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
     745 *
     746 * @since 5.0.1
     747 *
     748 * @return array HTML attributes that must include a URL.
     749 */
     750function wp_kses_uri_attributes() {
     751    $uri_attributes = array(
     752        'action',
     753        'archive',
     754        'background',
     755        'cite',
     756        'classid',
     757        'codebase',
     758        'data',
     759        'formaction',
     760        'href',
     761        'icon',
     762        'longdesc',
     763        'manifest',
     764        'poster',
     765        'profile',
     766        'src',
     767        'usemap',
     768        'xmlns',
     769    );
     770
     771    /**
     772     * Filters the list of attributes that are required to contain a URL.
     773     *
     774     * Use this filter to add any `data-` attributes that are required to be
     775     * validated as a URL.
     776     *
     777     * @since 5.0.1
     778     *
     779     * @param array $uri_attributes HTML attributes requiring validation as a URL.
     780     */
     781    $uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );
     782
     783    return $uri_attributes;
     784}
     785
     786/**
    737787 * Callback for wp_kses_split.
    738788 *
     
    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.