Changeset 44942
- Timestamp:
- 03/20/2019 05:21:56 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r44941 r44942 574 574 575 575 add_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10, 3 ); 576 add_filter( 'oembed_dataparse', 'wp_filter_oembed_iframe_title_attribute', 20, 3 ); 576 577 add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 ); 577 578 add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 ); -
trunk/src/wp-includes/embed.php
r44926 r44942 780 780 return $node->asXML(); 781 781 } 782 783 /** 784 * Filters the given oEmbed HTML to make sure iframes have a title attribute. 785 * 786 * @since 5.2.0 787 * 788 * @param string $result The oEmbed HTML result. 789 * @param object $data A data object result from an oEmbed provider. 790 * @param string $url The URL of the content to be embedded. 791 * @return string The filtered oEmbed result. 792 */ 793 function wp_filter_oembed_iframe_title_attribute( $result, $data, $url ) { 794 if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ) ) ) { 795 return $result; 796 } 797 798 $title = ! empty( $data->title ) ? $data->title : ''; 799 800 $pattern = '`<iframe[^>]*?title=(\\\\\'|\\\\"|[\'"])([^>]*?)\1`i'; 801 $has_title_attr = preg_match( $pattern, $result, $matches ); 802 803 if ( $has_title_attr && ! empty( $matches[2] ) ) { 804 $title = $matches[2]; 805 } 806 807 /** 808 * Filters the title attribute of the given oEmbed HTML iframe. 809 * 810 * @since 5.2.0 811 * 812 * @param string $title The title attribute. 813 * @param string $result The oEmbed HTML result. 814 * @param object $data A data object result from an oEmbed provider. 815 * @param string $url The URL of the content to be embedded. 816 */ 817 $title = apply_filters( 'oembed_iframe_title_attribute', $title, $result, $data, $url ); 818 819 if ( '' === $title ) { 820 return $result; 821 } 822 823 if ( $has_title_attr ) { 824 // Remove the old title, $matches[1]: quote, $matches[2]: title attribute value. 825 $result = str_replace( ' title=' . $matches[1] . $matches[2] . $matches[1], '', $result ); 826 } 827 828 return str_ireplace( '<iframe ', sprintf( '<iframe title="%s" ', esc_attr( $title ) ), $result ); 829 } 830 782 831 783 832 /** -
trunk/tests/qunit/fixtures/wp-api-generated.js
r44812 r44942 4989 4989 "width": 500, 4990 4990 "thumbnail_height": 360, 4991 "html": "<iframe width=\"500\" height=\"375\" src=\"https://www.youtube.com/embed/i_cVJgIz_Cs?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",4991 "html": "<iframe title=\"No te olvides de poner el Where en el Delete From. (Una cancion para programadores)\" width=\"500\" height=\"375\" src=\"https://www.youtube.com/embed/i_cVJgIz_Cs?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>", 4992 4992 "author_name": "Jorge Rubira Santos", 4993 4993 "thumbnail_url": "https://i.ytimg.com/vi/i_cVJgIz_Cs/hqdefault.jpg",
Note: See TracChangeset
for help on using the changeset viewer.