Make WordPress Core


Ignore:
Timestamp:
10/29/2015 11:10:46 PM (11 years ago)
Author:
pento
Message:

Embeds: Provide a cached text fallback.

Sometimes, embedded sites might suffer from less than 100% uptime. Instead of leaving the embedding site with a big blank space where the embed should be, let's fall back to a link to the embedded post, so there's at least some context for the post.

Fixes #34462.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/embed-functions.php

    r35436 r35437  
    462462        $embed_url = get_post_embed_url( $post );
    463463
    464         $output = "<script type='text/javascript'>\n";
     464        $output = '<blockquote><a href="' . get_permalink( $post ) . '">' . get_the_title( $post ) . "</a></blockquote>\n";
     465
     466        $output .= "<script type='text/javascript'>\n";
    465467        $output .= "<!--//--><![CDATA[//><!--\n";
    466468        if ( SCRIPT_DEBUG ) {
     
    753755
    754756        $allowed_html = array(
    755                 'iframe' => array(
     757                'a'          => array(
     758                                'href' => true,
     759                ),
     760                'blockquote' => array(),
     761                'iframe'     => array(
    756762                        'src'          => true,
    757763                        'width'        => true,
     
    767773
    768774        $html = wp_kses( $result, $allowed_html );
    769         preg_match( '|^.*(<iframe.*?></iframe>).*$|m', $html, $iframes );
    770 
    771         if ( empty( $iframes ) ) {
     775
     776        preg_match( '|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content );
     777        // We require at least the iframe to exist.
     778        if ( empty( $content[2] ) ) {
    772779                return false;
    773780        }
    774 
    775         $html = str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $iframes[1] );
     781        $html = $content[1] . $content[2];
     782
     783        if ( ! empty( $content[1] ) ) {
     784                // We have a blockquote to fall back on. Hide the iframe by default.
     785                $html = str_replace( '<iframe', '<iframe style="display:none;"', $html );
     786        }
     787
     788        $html = str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $html );
    776789
    777790        preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results );
     
    783796
    784797                $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html );
     798                $html = str_replace( '<blockquote', "<blockquote data-secret=\"$secret\"", $html );
    785799        }
    786800
     
    911925        <?php
    912926}
     927
     928/**
     929 * Prepare the oembed HTML to be displayed in an RSS feed.
     930 *
     931 * @since 4.4.0
     932 * @access private
     933 *
     934 * @param string $content The content to filter.
     935 * @return string The filtered content.
     936 */
     937function _oembed_filter_feed_content( $content ) {
     938        return str_replace( '<iframe sandbox="allow-scripts" security="restricted" style="display:none;"', '<iframe sandbox="allow-scripts" security="restricted"', $content );
     939}
Note: See TracChangeset for help on using the changeset viewer.