WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/07/2015 10:35:18 AM (4 years ago)
Author:
pento
Message:

Embeds: Add oEmbed provider support.

For the past 6 years, WordPress has operated as an oEmbed consumer, allowing users to easily embed content from other sites. By adding oEmbed provider support, this allows any oEmbed consumer to embed posts from WordPress sites.

In addition to creating an oEmbed provider, WordPress' oEmbed consumer code has been enhanced to work with any site that provides oEmbed data (as long as it matches some strict security rules), and provides a preview from within the post editor.

For security, embeds appear within a sandboxed iframe - the iframe content is a template that can be styled or replaced entirely by the theme on the provider site.

Props swissspidy, pento, melchoyce, netweb, pfefferle, johnbillion, extendwings, davidbinda, danielbachhuber, SergeyBiryukov, afercia

Fixes #32522.

File:
1 edited

Legend:

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

    r34836 r34903  
    717717
    718718    return $wp_query->is_404();
     719}
     720
     721/**
     722 * Is the query for an embedded post?
     723 *
     724 * @since 4.4.0
     725 *
     726 * @global WP_Query $wp_query Global WP_Query instance.
     727 *
     728 * @return bool Whether we're in an embedded post or not.
     729 */
     730function is_embed() {
     731    global $wp_query;
     732
     733    if ( ! isset( $wp_query ) ) {
     734        _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     735        return false;
     736    }
     737
     738    return $wp_query->is_embed();
    719739}
    720740
     
    12001220     */
    12011221    public $is_404 = false;
     1222
     1223    /**
     1224     * Set if query is embed.
     1225     *
     1226     * @since 4.4.0
     1227     * @access public
     1228     * @var bool
     1229     */
     1230    public $is_embed = false;
    12021231
    12031232    /**
     
    18461875            $this->set_404();
    18471876
     1877        $this->is_embed = isset( $qv['embed'] ) && ( $this->is_singular || $this->is_404 );
     1878
    18481879        $this->query_vars_hash = md5( serialize( $this->query_vars ) );
    18491880        $this->query_vars_changed = false;
     
    46364667
    46374668    /**
     4669     * Is the query for an embedded post?
     4670     *
     4671     * @since 3.1.0
     4672     *
     4673     * @return bool
     4674     */
     4675    public function is_embed() {
     4676        return (bool) $this->is_embed;
     4677    }
     4678
     4679    /**
    46384680     * Is the query the main query?
    46394681     *
     
    49364978        } elseif ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged'] > 1 ) {
    49374979            $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . $GLOBALS['wp_query']->query_vars['paged'] );
     4980        } elseif( is_embed() ) {
     4981            $link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
    49384982        } elseif ( is_404() ) {
    49394983            // Add rewrite endpoints if necessary.
Note: See TracChangeset for help on using the changeset viewer.