Make WordPress Core


Ignore:
Timestamp:
10/07/2015 10:35:18 AM (9 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/class-wp-rewrite.php

    r34708 r34903  
    862862        $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
    863863        $commentregex = $this->comments_pagination_base . '-([0-9]{1,})/?$';
     864        $embedregex = 'embed/?$';
    864865
    865866        //build up an array of endpoint regexes to append => queries to append
     
    885886        $feedindex = $index;
    886887        $trackbackindex = $index;
     888        $embedindex = $index;
     889
    887890        //build a list from the rewritecode and queryreplace arrays, that will look something like
    888891        //tagname=$matches[i] where i is the current $i
     
    10301033                    $trackbackmatch = $match . $trackbackregex;
    10311034                    $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
     1035
     1036                    // Create query and regex for embeds.
     1037                    $embedmatch = $match . $embedregex;
     1038                    $embedquery = $embedindex . '?' . $query . '&embed=true';
     1039
    10321040                    //trim slashes from the end of the regex for this dir
    10331041                    $match = rtrim($match, '/');
     1042
    10341043                    //get rid of brackets
    10351044                    $submatchbase = str_replace( array('(', ')'), '', $match);
     
    10411050                    $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
    10421051                    $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx
     1052                    $sub1embed = $sub1 . $embedregex; //and <permalink>/embed/...
    10431053
    10441054                    //add another rule to match attachments in the explicit form:
     
    10491059                    $sub2feed2 = $sub2 . $feedregex2;  //and feeds again on to this <permalink>/attachment/(feed|atom...)
    10501060                    $sub2comment = $sub2 . $commentregex; //and <permalink>/comment-page-xx
     1061                    $sub2embed = $sub2 . $embedregex; //and <permalink>/embed/...
    10511062
    10521063                    //create queries for these extra tag-ons we've just dealt with
     
    10551066                    $subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
    10561067                    $subcommentquery = $subquery . '&cpage=' . $this->preg_index(2);
     1068                    $subembedquery = $subquery . '&embed=true';
    10571069
    10581070                    //do endpoints for attachments
     
    10931105                    $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
    10941106
     1107                    // add embed
     1108                    $rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite );
     1109
    10951110                    //add regexes/queries for attachments, attachment trackbacks and so on
    1096                     if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages
    1097                         $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery));
    1098                     $rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite);
     1111                    if ( ! $page ) {
     1112                        //require <permalink>/attachment/stuff form for pages because of confusion with subpages
     1113                        $rewrite = array_merge( $rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery, $sub1embed => $subembedquery ) );
     1114                    }
     1115
     1116                    $rewrite = array_merge( array( $sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery, $sub2embed => $subembedquery ), $rewrite );
    10991117                }
    11001118            } //if($num_toks)
Note: See TracChangeset for help on using the changeset viewer.