mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-10 21:00:59 +01:00
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.7` branch. Built from https://develop.svn.wordpress.org/branches/3.7@44049 git-svn-id: http://core.svn.wordpress.org/branches/3.7@43879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
81fb9c10a2
commit
a2d1cee61d
@ -488,7 +488,7 @@ function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) {
|
||||
* @return string Filtered attribute.
|
||||
*/
|
||||
function wp_kses_one_attr( $string, $element ) {
|
||||
$uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
|
||||
$uris = wp_kses_uri_attributes();
|
||||
$allowed_html = wp_kses_allowed_html( 'post' );
|
||||
$allowed_protocols = wp_allowed_protocols();
|
||||
$string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) );
|
||||
@ -657,6 +657,56 @@ function wp_kses_split( $string, $allowed_html, $allowed_protocols ) {
|
||||
return preg_replace_callback( '%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function listing HTML attributes containing a URL.
|
||||
*
|
||||
* This function returns a list of all HTML attributes that must contain
|
||||
* a URL according to the HTML specification.
|
||||
*
|
||||
* This list includes URI attributes both allowed and disallowed by KSES.
|
||||
*
|
||||
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
|
||||
*
|
||||
* @since 5.0.1
|
||||
*
|
||||
* @return array HTML attributes that must include a URL.
|
||||
*/
|
||||
function wp_kses_uri_attributes() {
|
||||
$uri_attributes = array(
|
||||
'action',
|
||||
'archive',
|
||||
'background',
|
||||
'cite',
|
||||
'classid',
|
||||
'codebase',
|
||||
'data',
|
||||
'formaction',
|
||||
'href',
|
||||
'icon',
|
||||
'longdesc',
|
||||
'manifest',
|
||||
'poster',
|
||||
'profile',
|
||||
'src',
|
||||
'usemap',
|
||||
'xmlns',
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the list of attributes that are required to contain a URL.
|
||||
*
|
||||
* Use this filter to add any `data-` attributes that are required to be
|
||||
* validated as a URL.
|
||||
*
|
||||
* @since 5.0.1
|
||||
*
|
||||
* @param array $uri_attributes HTML attributes requiring validation as a URL.
|
||||
*/
|
||||
$uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );
|
||||
|
||||
return $uri_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for wp_kses_split.
|
||||
*
|
||||
@ -849,7 +899,7 @@ function wp_kses_hair($attr, $allowed_protocols) {
|
||||
$attrarr = array();
|
||||
$mode = 0;
|
||||
$attrname = '';
|
||||
$uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
|
||||
$uris = wp_kses_uri_attributes();
|
||||
|
||||
# Loop through the whole attribute list
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user