mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-12 13:44:21 +01:00
Embeds: Ensure that the title attribute is set correctly on embeds.
Props xknown. Built from https://develop.svn.wordpress.org/trunk@47947 git-svn-id: http://core.svn.wordpress.org/trunk@47719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1d95eb63a7
commit
2ae3b3b801
@ -582,8 +582,8 @@ add_filter( 'the_excerpt_embed', 'wpautop' );
|
|||||||
add_filter( 'the_excerpt_embed', 'shortcode_unautop' );
|
add_filter( 'the_excerpt_embed', 'shortcode_unautop' );
|
||||||
add_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
|
add_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
|
||||||
|
|
||||||
|
add_filter( 'oembed_dataparse', 'wp_filter_oembed_iframe_title_attribute', 5, 3 );
|
||||||
add_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10, 3 );
|
add_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10, 3 );
|
||||||
add_filter( 'oembed_dataparse', 'wp_filter_oembed_iframe_title_attribute', 20, 3 );
|
|
||||||
add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 );
|
add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 );
|
||||||
add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 );
|
add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 );
|
||||||
|
|
||||||
|
@ -807,11 +807,24 @@ function wp_filter_oembed_iframe_title_attribute( $result, $data, $url ) {
|
|||||||
|
|
||||||
$title = ! empty( $data->title ) ? $data->title : '';
|
$title = ! empty( $data->title ) ? $data->title : '';
|
||||||
|
|
||||||
$pattern = '`<iframe[^>]*?title=(\\\\\'|\\\\"|[\'"])([^>]*?)\1`i';
|
$pattern = '`<iframe([^>]*)>`i';
|
||||||
$has_title_attr = preg_match( $pattern, $result, $matches );
|
if ( preg_match( $pattern, $result, $matches ) ) {
|
||||||
|
$attrs = wp_kses_hair( $matches[1], wp_allowed_protocols() );
|
||||||
|
|
||||||
if ( $has_title_attr && ! empty( $matches[2] ) ) {
|
foreach ( $attrs as $attr => $item ) {
|
||||||
$title = $matches[2];
|
$lower_attr = strtolower( $attr );
|
||||||
|
if ( $lower_attr === $attr ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( ! isset( $attrs[ $lower_attr ] ) ) {
|
||||||
|
$attrs[ $lower_attr ] = $item;
|
||||||
|
unset( $attrs[ $attr ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $attrs['title']['value'] ) ) {
|
||||||
|
$title = $attrs['title']['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -830,11 +843,11 @@ function wp_filter_oembed_iframe_title_attribute( $result, $data, $url ) {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $has_title_attr ) {
|
if ( isset( $attrs['title'] ) ) {
|
||||||
// Remove the old title, $matches[1]: quote, $matches[2]: title attribute value.
|
unset( $attrs['title'] );
|
||||||
$result = str_replace( ' title=' . $matches[1] . $matches[2] . $matches[1], '', $result );
|
$attr_string = join( ' ', wp_list_pluck( $attrs, 'whole' ) );
|
||||||
|
$result = str_replace( $matches[0], '<iframe ' . trim( $attr_string ) . '>', $result );
|
||||||
}
|
}
|
||||||
|
|
||||||
return str_ireplace( '<iframe ', sprintf( '<iframe title="%s" ', esc_attr( $title ) ), $result );
|
return str_ireplace( '<iframe ', sprintf( '<iframe title="%s" ', esc_attr( $title ) ), $result );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.5-alpha-47944';
|
$wp_version = '5.5-alpha-47947';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user