Make WordPress Core

Ticket #40245: for40245updated.diff

File for40245updated.diff, 2.2 KB (added by bamadesigner, 7 years ago)

Updated patch for 40245

  • src/wp-includes/default-filters.php

     
    544544add_filter( 'the_excerpt_embed', 'shortcode_unautop' );
    545545add_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
    546546
     547add_filter( 'oembed_dataparse', 'wp_filter_oembed_title', 9, 3 );
    547548add_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10, 3 );
    548549add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 );
    549550add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 );
  • src/wp-includes/embed.php

     
    707707}
    708708
    709709/**
     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 */
     719function 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/**
    710749 * Filters the given oEmbed HTML.
    711750 *
    712751 * If the `$url` isn't on the trusted providers list,