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