| | 712 | * Filters the given oEmbed HTML to make sure it has a title. |
| | 713 | * |
| | 714 | * @since x.x.x |
| | 715 | * |
| | 716 | * @param string $result The oEmbed HTML result. |
| | 717 | * @param object $data A data object result from an oEmbed provider. |
| | 718 | * @param string $url The URL of the content to be embedded. |
| | 719 | * @return string The filtered oEmbed result. |
| | 720 | */ |
| | 721 | function wp_filter_oembed_title( $result, $data, $url ) { |
| | 722 | |
| | 723 | // Get title from oEmbed data to start. |
| | 724 | $title = ! empty( $data->title ) ? $data->title : ''; |
| | 725 | |
| | 726 | // If no oEmbed title, search the return markup for a title attribute. |
| | 727 | $preg_match = '/title\=[\"|\\\']{1}([^\"\\\']*)[\"|\\\']{1}/i'; |
| | 728 | $has_title_attr = preg_match( $preg_match, $result, $matches ); |
| | 729 | if ( $has_title_attr && ! empty( $matches[1] ) ) { |
| | 730 | $title = $matches[1]; |
| | 731 | } |
| | 732 | |
| | 733 | $title = apply_filters( 'oembed_title', $title, $result, $data, $url ); |
| | 734 | |
| | 735 | /* |
| | 736 | * If the title attribute already |
| | 737 | * exists, replace with new value. |
| | 738 | * |
| | 739 | * Otherwise, add the title attribute. |
| | 740 | */ |
| | 741 | if ( $has_title_attr ) { |
| | 742 | $result = preg_replace( $preg_match, 'title="' . esc_attr( $title ) . '"', $result ); |
| | 743 | } else { |
| | 744 | $result = preg_replace( '/^\<iframe/i', '<iframe title="' . esc_attr( $title ) . '"', $result ); |
| | 745 | } |
| | 746 | |
| | 747 | return $result; |
| | 748 | } |
| | 749 | |
| | 750 | /** |