Make WordPress Core

Changeset 44044


Ignore:
Timestamp:
12/13/2018 01:18:07 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 4.0 branch.

Location:
branches/4.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

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

    r44015 r44044  
    498498 */
    499499function wp_kses_one_attr( $string, $element ) {
    500     $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
     500    $uris = wp_kses_uri_attributes();
    501501    $allowed_html = wp_kses_allowed_html( 'post' );
    502502    $allowed_protocols = wp_allowed_protocols();
     
    691691
    692692/**
     693 * Helper function listing HTML attributes containing a URL.
     694 *
     695 * This function returns a list of all HTML attributes that must contain
     696 * a URL according to the HTML specification.
     697 *
     698 * This list includes URI attributes both allowed and disallowed by KSES.
     699 *
     700 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
     701 *
     702 * @since 5.0.1
     703 *
     704 * @return array HTML attributes that must include a URL.
     705 */
     706function wp_kses_uri_attributes() {
     707    $uri_attributes = array(
     708        'action',
     709        'archive',
     710        'background',
     711        'cite',
     712        'classid',
     713        'codebase',
     714        'data',
     715        'formaction',
     716        'href',
     717        'icon',
     718        'longdesc',
     719        'manifest',
     720        'poster',
     721        'profile',
     722        'src',
     723        'usemap',
     724        'xmlns',
     725    );
     726
     727    /**
     728     * Filters the list of attributes that are required to contain a URL.
     729     *
     730     * Use this filter to add any `data-` attributes that are required to be
     731     * validated as a URL.
     732     *
     733     * @since 5.0.1
     734     *
     735     * @param array $uri_attributes HTML attributes requiring validation as a URL.
     736     */
     737    $uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );
     738
     739    return $uri_attributes;
     740}
     741
     742/**
    693743 * Callback for wp_kses_split.
    694744 *
     
    882932    $mode = 0;
    883933    $attrname = '';
    884     $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
     934    $uris = wp_kses_uri_attributes();
    885935
    886936    # Loop through the whole attribute list
Note: See TracChangeset for help on using the changeset viewer.