<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36307] trunk: Embeds: Allow embedding static front pages and pages having a child page with an `embed` slug.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/36307">36307</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/36307","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-01-15 07:55:19 +0000 (Fri, 15 Jan 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Embeds: Allow embedding static front pages and pages having a child page with an `embed` slug.
This makes `embed` a special slug that can't be used for new pages/posts. When `https://example.com/foo/embed/` is an existing page, embeds fall back to `https://example.com/foo/?embed=true`.
Adds unit tests.
Fixes <a href="https://core.trac.wordpress.org/ticket/34971">#34971</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswprewritephp">trunk/src/wp-includes/class-wp-rewrite.php</a></li>
<li><a href="#trunksrcwpincludesembedphp">trunk/src/wp-includes/embed.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunksrcwpincludesqueryphp">trunk/src/wp-includes/query.php</a></li>
<li><a href="#trunksrcwpincludesrewritephp">trunk/src/wp-includes/rewrite.php</a></li>
<li><a href="#trunktestsphpunittestsoembedcontrollerphp">trunk/tests/phpunit/tests/oembed/controller.php</a></li>
<li><a href="#trunktestsphpunittestsoembeddiscoveryphp">trunk/tests/phpunit/tests/oembed/discovery.php</a></li>
<li><a href="#trunktestsphpunittestsoembedpostEmbedUrlphp">trunk/tests/phpunit/tests/oembed/postEmbedUrl.php</a></li>
<li><a href="#trunktestsphpunittestspostwpUniquePostSlugphp">trunk/tests/phpunit/tests/post/wpUniquePostSlug.php</a></li>
<li><a href="#trunktestsphpunittestsrewritephp">trunk/tests/phpunit/tests/rewrite.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswprewritephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-rewrite.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-rewrite.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/src/wp-includes/class-wp-rewrite.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1022,6 +1022,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $feedmatch2 = $match . $feedregex2;
</span><span class="cx" style="display: block; padding: 0 10px"> $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Create query and regex for embeds.
+ $embedmatch = $match . $embedregex;
+ $embedquery = $embedindex . '?' . $query . '&embed=true';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // If asked to, turn the feed queries into comment feed ones.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $forcomments ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $feedquery .= '&withcomments=1';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1033,7 +1037,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // ...adding on /feed/ regexes => queries
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $feed ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2, $embedmatch => $embedquery );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> //...and /page/xx ones
</span></span></pre></div>
<a id="trunksrcwpincludesembedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/embed.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/embed.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/src/wp-includes/embed.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -345,7 +345,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_oembed_add_discovery_links() {
</span><span class="cx" style="display: block; padding: 0 10px"> $output = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_singular() && ! is_front_page() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_singular() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( class_exists( 'SimpleXMLElement' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -387,9 +387,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( get_option( 'permalink_structure' ) ) {
- $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
- } else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
+ $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) );
+
+ if ( ! get_option( 'permalink_structure' ) || $path_conflict ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/src/wp-includes/post.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3574,7 +3574,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $bad_slug Whether the slug would be bad as an attachment slug.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug The post slug.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $suffix = 2;
</span><span class="cx" style="display: block; padding: 0 10px"> do {
</span><span class="cx" style="display: block; padding: 0 10px"> $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3604,7 +3604,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $post_type Post type.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $post_parent Post parent ID.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $suffix = 2;
</span><span class="cx" style="display: block; padding: 0 10px"> do {
</span><span class="cx" style="display: block; padding: 0 10px"> $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3649,7 +3649,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug The post slug.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $post_type Post type.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post_name_check || in_array( $slug, $feeds ) || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $suffix = 2;
</span><span class="cx" style="display: block; padding: 0 10px"> do {
</span><span class="cx" style="display: block; padding: 0 10px"> $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
</span></span></pre></div>
<a id="trunksrcwpincludesqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/query.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/src/wp-includes/query.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1456,6 +1456,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> , 'title'
</span><span class="cx" style="display: block; padding: 0 10px"> , 'fields'
</span><span class="cx" style="display: block; padding: 0 10px"> , 'menu_order'
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ , 'embed'
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $keys as $key ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1756,6 +1757,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' != $qv['feed'] )
</span><span class="cx" style="display: block; padding: 0 10px"> $this->is_feed = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( '' != $qv['embed'] ) {
+ $this->is_embed = true;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( '' != $qv['tb'] )
</span><span class="cx" style="display: block; padding: 0 10px"> $this->is_trackback = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1788,6 +1793,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset($_query['pagename']) && '' == $_query['pagename'] )
</span><span class="cx" style="display: block; padding: 0 10px"> unset($_query['pagename']);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ unset( $_query['embed'] );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty($_query) || !array_diff( array_keys($_query), array('preview', 'page', 'paged', 'cpage') ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->is_page = true;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->is_home = false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1859,7 +1867,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '404' == $qv['error'] )
</span><span class="cx" style="display: block; padding: 0 10px"> $this->set_404();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->is_embed = isset( $qv['embed'] ) && ( $this->is_singular || $this->is_404 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->query_vars_hash = md5( serialize( $this->query_vars ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->query_vars_changed = false;
</span></span></pre></div>
<a id="trunksrcwpincludesrewritephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rewrite.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rewrite.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/src/wp-includes/rewrite.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -478,13 +478,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Check to see if we are using rewrite rules
- $rewrite = $wp_rewrite->wp_rewrite_rules();
-
- // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
- if ( empty($rewrite) )
- return 0;
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Get rid of the #anchor
</span><span class="cx" style="display: block; padding: 0 10px"> $url_split = explode('#', $url);
</span><span class="cx" style="display: block; padding: 0 10px"> $url = $url_split[0];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -504,6 +497,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false === strpos(home_url(), '://www.') )
</span><span class="cx" style="display: block; padding: 0 10px"> $url = str_replace('://www.', '://', $url);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) {
+ $page_on_front = get_option( 'page_on_front' );
+
+ if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) {
+ return (int) $page_on_front;
+ }
+ }
+
+ // Check to see if we are using rewrite rules
+ $rewrite = $wp_rewrite->wp_rewrite_rules();
+
+ // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
+ if ( empty($rewrite) )
+ return 0;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Strip 'index.php/' if we're not using path info permalinks
</span><span class="cx" style="display: block; padding: 0 10px"> if ( !$wp_rewrite->using_index_permalinks() )
</span><span class="cx" style="display: block; padding: 0 10px"> $url = str_replace( $wp_rewrite->index . '/', '', $url );
</span></span></pre></div>
<a id="trunktestsphpunittestsoembedcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/oembed/controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/oembed/controller.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/tests/phpunit/tests/oembed/controller.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -169,6 +169,49 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $data['width'] <= $request['maxwidth'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @ticket 34971
+ */
+ function test_request_static_front_page() {
+ $post = self::factory()->post->create_and_get( array(
+ 'post_title' => 'Front page',
+ 'post_type' => 'page',
+ ) );
+
+ update_option( 'show_on_front', 'page' );
+ update_option( 'page_on_front', $post->ID );
+
+ $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' );
+ $request->set_param( 'url', home_url() );
+ $request->set_param( 'maxwidth', 400 );
+
+ $response = $this->server->dispatch( $request );
+ $data = $response->get_data();
+
+ $this->assertInternalType( 'array', $data );
+ $this->assertNotEmpty( $data );
+
+ $this->assertArrayHasKey( 'version', $data );
+ $this->assertArrayHasKey( 'provider_name', $data );
+ $this->assertArrayHasKey( 'provider_url', $data );
+ $this->assertArrayHasKey( 'author_name', $data );
+ $this->assertArrayHasKey( 'author_url', $data );
+ $this->assertArrayHasKey( 'title', $data );
+ $this->assertArrayHasKey( 'type', $data );
+ $this->assertArrayHasKey( 'width', $data );
+
+ $this->assertEquals( '1.0', $data['version'] );
+ $this->assertEquals( get_bloginfo( 'name' ), $data['provider_name'] );
+ $this->assertEquals( get_home_url(), $data['provider_url'] );
+ $this->assertEquals( get_bloginfo( 'name' ), $data['author_name'] );
+ $this->assertEquals( get_home_url(), $data['author_url'] );
+ $this->assertEquals( $post->post_title, $data['title'] );
+ $this->assertEquals( 'rich', $data['type'] );
+ $this->assertTrue( $data['width'] <= $request['maxwidth'] );
+
+ update_option( 'show_on_front', 'posts' );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_request_xml() {
</span><span class="cx" style="display: block; padding: 0 10px"> $user = self::factory()->user->create_and_get( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'display_name' => 'John Doe',
</span></span></pre></div>
<a id="trunktestsphpunittestsoembeddiscoveryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/oembed/discovery.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/oembed/discovery.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/tests/phpunit/tests/oembed/discovery.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,18 +9,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_add_oembed_discovery_links_front_page() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->go_to( home_url('/') );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->go_to( home_url() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertSame( 0, url_to_postid( home_url() ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @ticket 34971
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_add_oembed_discovery_links_static_front_page() {
</span><span class="cx" style="display: block; padding: 0 10px"> update_option( 'show_on_front', 'page' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- update_option( 'page_for_posts', self::factory()->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
</del><span class="cx" style="display: block; padding: 0 10px"> update_option( 'page_on_front', self::factory()->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->go_to( home_url('/') );
- $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->go_to( home_url() );
+ $this->assertQueryTrue( 'is_front_page', 'is_singular', 'is_page' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
+ $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
+
+ $this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> update_option( 'show_on_front', 'posts' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsoembedpostEmbedUrlphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/oembed/postEmbedUrl.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/oembed/postEmbedUrl.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/tests/phpunit/tests/oembed/postEmbedUrl.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,28 +4,105 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @group oembed
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Post_Embed_URL extends WP_UnitTestCase {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function test_get_post_embed_url_non_existent_post() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_non_existent_post() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $embed_url = get_post_embed_url( 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( $embed_url );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function test_get_post_embed_url_with_pretty_permalinks() {
- update_option( 'permalink_structure', '/%postname%' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_with_pretty_permalinks() {
+ $this->set_permalink_structure( '/%postname%' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post_id = self::factory()->post->create();
</span><span class="cx" style="display: block; padding: 0 10px"> $permalink = get_permalink( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $embed_url = get_post_embed_url( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( user_trailingslashit( trailingslashit( $permalink ) . 'embed' ), $embed_url );
-
- update_option( 'permalink_structure', '' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( $permalink . '/embed', $embed_url );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function test_get_post_embed_url_with_ugly_permalinks() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_with_ugly_permalinks() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_id = self::factory()->post->create();
</span><span class="cx" style="display: block; padding: 0 10px"> $permalink = get_permalink( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $embed_url = get_post_embed_url( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $permalink . '&embed=true', $embed_url );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 34971
+ */
+ function test_static_front_page() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+
+ update_option( 'show_on_front', 'page' );
+ update_option( 'page_on_front', $post_id );
+
+ $embed_url = get_post_embed_url( $post_id );
+
+ $this->assertSame( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url );
+
+ update_option( 'show_on_front', 'posts' );
+ }
+
+ /**
+ * @ticket 34971
+ */
+ function test_static_front_page_with_ugly_permalinks() {
+ $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+
+ update_option( 'show_on_front', 'page' );
+ update_option( 'page_on_front', $post_id );
+
+ $embed_url = get_post_embed_url( $post_id );
+
+ $this->assertSame( trailingslashit( home_url() ) . '?embed=true', $embed_url );
+
+ update_option( 'show_on_front', 'posts' );
+ }
+
+ /**
+ * @ticket 34971
+ */
+ function test_page_conflicts_with_embed_slug() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ $parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) );
+
+ add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
+ $child_page = self::factory()->post->create( array(
+ 'post_type' => 'page',
+ 'post_parent' => $parent_page,
+ 'post_name' => 'embed',
+ ) );
+ remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
+
+ $this->assertSame( get_permalink( $parent_page ) . '?embed=true', get_post_embed_url( $parent_page ) );
+ $this->assertSame( get_permalink( $child_page ) . 'embed/', get_post_embed_url( $child_page ) );
+ }
+
+ /**
+ * @ticket 34971
+ */
+ function test_static_front_page_conflicts_with_embed_slug() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ // Create a post with the 'embed' post_name
+ add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
+ $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) );
+ remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
+ $page_front = self::factory()->post->create( array( 'post_type' => 'page' ) );
+
+ update_option( 'show_on_front', 'page' );
+ update_option( 'page_on_front', $page_front );
+
+ $this->assertSame( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) );
+ $this->assertSame( home_url() . '/?embed=true', get_post_embed_url( $page_front ) );
+
+ update_option( 'show_on_front', 'posts' );
+ }
+
+ public function filter_unique_post_slug() {
+ return 'embed';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestspostwpUniquePostSlugphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/wpUniquePostSlug.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/wpUniquePostSlug.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/tests/phpunit/tests/post/wpUniquePostSlug.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -302,4 +302,49 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( '32', $found );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 34971
+ */
+ public function test_embed_slug_should_be_suffixed_for_posts() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ $p = self::factory()->post->create( array(
+ 'post_type' => 'post',
+ 'post_name' => 'embed',
+ ) );
+
+ $found = wp_unique_post_slug( 'embed', $p, 'publish', 'post', 0 );
+ $this->assertSame( 'embed-2', $found );
+ }
+
+ /**
+ * @ticket 34971
+ */
+ public function test_embed_slug_should_be_suffixed_for_pages() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ $p = self::factory()->post->create( array(
+ 'post_type' => 'page',
+ 'post_name' => 'embed',
+ ) );
+
+ $found = wp_unique_post_slug( 'embed', $p, 'publish', 'paage', 0 );
+ $this->assertSame( 'embed-2', $found );
+ }
+
+ /**
+ * @ticket 34971
+ */
+ public function test_embed_slug_should_be_suffixed_for_attachments() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ $p = self::factory()->post->create( array(
+ 'post_type' => 'attachment',
+ 'post_name' => 'embed',
+ ) );
+
+ $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 );
+ $this->assertSame( 'embed-2', $found );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrewritephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rewrite.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rewrite.php 2016-01-15 07:28:48 UTC (rev 36306)
+++ trunk/tests/phpunit/tests/rewrite.php 2016-01-15 07:55:19 UTC (rev 36307)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -304,6 +304,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 34971
+ */
+ function test_url_to_postid_static_front_page() {
+ $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+
+ $this->assertSame( 0, url_to_postid( home_url() ) );
+
+ update_option( 'show_on_front', 'page' );
+ update_option( 'page_on_front', $post_id );
+
+ $this->assertSame( $post_id, url_to_postid( set_url_scheme( home_url(), 'http' ) ) );
+ $this->assertSame( $post_id, url_to_postid( set_url_scheme( home_url(), 'https' ) ) );
+ $this->assertSame( $post_id, url_to_postid( str_replace( array( 'http://', 'https://' ), 'http://www.', home_url() ) ) );
+ $this->assertSame( $post_id, url_to_postid( home_url() . '#random' ) );
+ $this->assertSame( $post_id, url_to_postid( home_url() . '?random' ) );
+
+ update_option( 'show_on_front', 'posts' );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 21970
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_parse_request_with_post_slug_that_clashes_with_a_trashed_page() {
</span></span></pre>
</div>
</div>
</body>
</html>