Changeset 44942 for trunk/src/wp-includes/embed.php
- Timestamp:
- 03/20/2019 05:21:56 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 /**
Note: See TracChangeset
for help on using the changeset viewer.