From 2ae3b3b801aab04b92bacb89bea3f0c9b1c78fec Mon Sep 17 00:00:00 2001 From: whyisjake Date: Wed, 10 Jun 2020 17:20:10 +0000 Subject: [PATCH] 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 --- wp-includes/default-filters.php | 2 +- wp-includes/embed.php | 29 +++++++++++++++++++++-------- wp-includes/version.php | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index fd5d9f32f2..43faaf6507 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -582,8 +582,8 @@ add_filter( 'the_excerpt_embed', 'wpautop' ); add_filter( 'the_excerpt_embed', 'shortcode_unautop' ); 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_iframe_title_attribute', 20, 3 ); add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 ); add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 ); diff --git a/wp-includes/embed.php b/wp-includes/embed.php index 673e178b1b..282882d85d 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -807,11 +807,24 @@ function wp_filter_oembed_iframe_title_attribute( $result, $data, $url ) { $title = ! empty( $data->title ) ? $data->title : ''; - $pattern = '`]*?title=(\\\\\'|\\\\"|[\'"])([^>]*?)\1`i'; - $has_title_attr = preg_match( $pattern, $result, $matches ); + $pattern = '`]*)>`i'; + if ( preg_match( $pattern, $result, $matches ) ) { + $attrs = wp_kses_hair( $matches[1], wp_allowed_protocols() ); - if ( $has_title_attr && ! empty( $matches[2] ) ) { - $title = $matches[2]; + foreach ( $attrs as $attr => $item ) { + $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; } - if ( $has_title_attr ) { - // Remove the old title, $matches[1]: quote, $matches[2]: title attribute value. - $result = str_replace( ' title=' . $matches[1] . $matches[2] . $matches[1], '', $result ); + if ( isset( $attrs['title'] ) ) { + unset( $attrs['title'] ); + $attr_string = join( ' ', wp_list_pluck( $attrs, 'whole' ) ); + $result = str_replace( $matches[0], '