From 8fc9dbc55b578f630ba66f222ddab37c14092106 Mon Sep 17 00:00:00 2001 From: desrosj Date: Wed, 10 Jun 2020 18:19:52 +0000 Subject: [PATCH] General: Backport several commits for release. - Embeds: Ensure that the title attribute is set correctly on embeds. - Editor: Prevent HTML decoding on by setting the proper editor context. - Formatting: Ensure that wp_validate_redirect() sanitizes a wider variety of characters. - Themes: Ensure a broken theme name is returned properly. - Administration: Add a new filter to extend set-screen-option. Merges [47947-47951] to the 5.1 branch. Props xknown, sstoqnov, vortfu, SergeyBiryukov, whyisjake. Built from https://develop.svn.wordpress.org/branches/5.1@47963 git-svn-id: http://core.svn.wordpress.org/branches/5.1@47734 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/media.php | 2 +- wp-admin/includes/misc.php | 37 ++++++++++++++++---- wp-admin/themes.php | 2 +- wp-includes/default-filters.php | 1 + wp-includes/embed.php | 62 +++++++++++++++++++++++++++++++++ wp-includes/pluggable.php | 6 ++-- 6 files changed, 98 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 2738a2137b..b9bf72d885 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -3039,7 +3039,7 @@ function edit_form_image_editor( $post ) { } ?> - post_content, 'attachment_content', $editor_args ); ?> + post_content ), 'attachment_content', $editor_args ); ?> - get( 'Name' ) ? $broken_theme->display( 'Name' ) : $broken_theme->get_stylesheet(); ?> + get( 'Name' ) ? $broken_theme->display( 'Name' ) : esc_html( $broken_theme->get_stylesheet() ); ?> errors()->get_error_message(); ?> asXML(); } +/** + * Filters the given oEmbed HTML to make sure iframes have a title attribute. + * + * @since 5.2.0 + * + * @param string $result The oEmbed HTML result. + * @param object $data A data object result from an oEmbed provider. + * @param string $url The URL of the content to be embedded. + * @return string The filtered oEmbed result. + */ +function wp_filter_oembed_iframe_title_attribute( $result, $data, $url ) { + if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ), true ) ) { + return $result; + } + + $title = ! empty( $data->title ) ? $data->title : ''; + + $pattern = '`]*)>`i'; + if ( preg_match( $pattern, $result, $matches ) ) { + $attrs = wp_kses_hair( $matches[1], wp_allowed_protocols() ); + + 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']; + } + + /** + * Filters the title attribute of the given oEmbed HTML iframe. + * + * @since 5.2.0 + * + * @param string $title The title attribute. + * @param string $result The oEmbed HTML result. + * @param object $data A data object result from an oEmbed provider. + * @param string $url The URL of the content to be embedded. + */ + $title = apply_filters( 'oembed_iframe_title_attribute', $title, $result, $data, $url ); + + if ( '' === $title ) { + return $result; + } + + if ( isset( $attrs['title'] ) ) { + unset( $attrs['title'] ); + $attr_string = join( ' ', wp_list_pluck( $attrs, 'whole' ) ); + $result = str_replace( $matches[0], '