<!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>[39506] trunk: Customize: Defer populating `post_name` for `auto-draft` posts in customized state until posts are published.</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/39506">39506</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/39506","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-12-05 19:32:09 +0000 (Mon, 05 Dec 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'>Customize: Defer populating `post_name` for `auto-draft` posts in customized state until posts are published.
The ultimate `post_name` is stored in postmeta until the post is published. The `get_page_by_path()` function does not exclude `auto-draft` posts. Revert changes to `wp_unique_post_slug()` from <a href="https://core.trac.wordpress.org/changeset/39411">[39411]</a> which excluded `auto-draft` posts.
Props westonruter, dlh for testing, helen for testing.
See <a href="https://core.trac.wordpress.org/ticket/38114">#38114</a>, <a href="https://core.trac.wordpress.org/ticket/38928">#38928</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/39078">#39078</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpcustomizemanagerphp">trunk/src/wp-includes/class-wp-customize-manager.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizenavmenusphp">trunk/src/wp-includes/class-wp-customize-nav-menus.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunktestsphpunittestsajaxCustomizeMenusphp">trunk/tests/phpunit/tests/ajax/CustomizeMenus.php</a></li>
<li><a href="#trunktestsphpunittestscustomizemanagerphp">trunk/tests/phpunit/tests/customize/manager.php</a></li>
<li><a href="#trunktestsphpunittestscustomizenavmenusphp">trunk/tests/phpunit/tests/customize/nav-menus.php</a></li>
<li><a href="#trunktestsphpunittestspostwpUniquePostSlugphp">trunk/tests/phpunit/tests/post/wpUniquePostSlug.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpcustomizemanagerphp"></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-customize-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-manager.php 2016-12-05 16:56:50 UTC (rev 39505)
+++ trunk/src/wp-includes/class-wp-customize-manager.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1006,7 +1006,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'posts_per_page' => -1,
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $existing_posts_query->posts as $existing_post ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $existing_starter_content_posts[ $existing_post->post_type . ':' . $existing_post->post_name ] = $existing_post;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_name = $existing_post->post_name;
+ if ( empty( $post_name ) ) {
+ $post_name = get_post_meta( $existing_post->ID, '_customize_draft_post_name', true );
+ }
+ $existing_starter_content_posts[ $existing_post->post_type . ':' . $post_name ] = $existing_post;
</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">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1067,7 +1071,7 @@
</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"> $attachment_post_data = array_merge(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt', 'post_name' ) ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt' ) ),
</ins><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_status' => 'auto-draft', // So attachment will be garbage collected in a week if changeset is never published.
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1085,6 +1089,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> update_post_meta( $attachment_id, '_starter_content_theme', $this->get_stylesheet() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_post_meta( $attachment_id, '_customize_draft_post_name', $attachment['post_name'] );
</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"> $attachment_ids[ $symbol ] = $attachment_id;
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizenavmenusphp"></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-customize-nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-nav-menus.php 2016-12-05 16:56:50 UTC (rev 39505)
+++ trunk/src/wp-includes/class-wp-customize-nav-menus.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -803,6 +803,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $postarr['post_name'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $postarr['post_name'] = sanitize_title( $postarr['post_title'] );
</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 ( ! isset( $postarr['meta_input'] ) ) {
+ $postarr['meta_input'] = array();
+ }
+ $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name'];
+ unset( $postarr['post_name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
</span><span class="cx" style="display: block; padding: 0 10px"> $r = wp_insert_post( wp_slash( $postarr ), true );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1192,9 +1197,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $post_ids ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $post_ids as $post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args = array(
+ 'ID' => $post_id,
+ 'post_status' => $target_status,
+ );
+ $post_name = get_post_meta( $post_id, '_customize_draft_post_name', true );
+ if ( $post_name ) {
+ $args['post_name'] = $post_name;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_update_post( array( 'ID' => $post_id, 'post_status' => $target_status ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_update_post( wp_slash( $args ) );
+
+ delete_post_meta( $post_id, '_customize_draft_post_name' );
</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"> }
</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-12-05 16:56:50 UTC (rev 39505)
+++ trunk/src/wp-includes/post.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3678,7 +3678,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'attachment' == $post_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Attachment slugs must be unique across all types.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_name = %s AND ID != %d LIMIT 1";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3706,7 +3706,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Page slugs must be unique within their own trees. Pages are in a separate
</span><span class="cx" style="display: block; padding: 0 10px"> * namespace than posts so page slugs are allowed to overlap post slugs.
</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_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3730,7 +3730,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> // Post slugs must be unique across all posts.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Prevent new post slugs that could result in URLs that conflict with date archives.
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxCustomizeMenusphp"></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/ajax/CustomizeMenus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/CustomizeMenus.php 2016-12-05 16:56:50 UTC (rev 39505)
+++ trunk/tests/phpunit/tests/ajax/CustomizeMenus.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -601,7 +601,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $response['data']['post_id'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Hello World', $post->post_title );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'post', $post->post_type );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( 'hello-world', $post->post_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( '', $post->post_name );
+ $this->assertEquals( 'hello-world', get_post_meta( $post->ID, '_customize_draft_post_name', true ) );
</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"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizemanagerphp"></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/customize/manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/manager.php 2016-12-05 16:56:50 UTC (rev 39505)
+++ trunk/tests/phpunit/tests/customize/manager.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -453,8 +453,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'inherit', $post->post_status );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'auto-draft', $post->post_status );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEmpty( $post->post_name );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $posts_by_name[ $post->post_name ] = $post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_name = $post->post_name;
+ if ( empty( $post_name ) ) {
+ $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true );
+ }
+ $posts_by_name[ $post_name ] = $post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Custom', get_post( $posts_by_name['custom'] )->post_title );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -464,6 +469,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( '', get_post_thumbnail_id( $posts_by_name['blog'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $attachment_metadata = wp_get_attachment_metadata( $posts_by_name['waffles'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Waffles', get_post( $posts_by_name['waffles'] )->post_title );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( 'waffles', get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'file', $attachment_metadata );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( 'waffles', $attachment_metadata['file'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -488,7 +494,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Ensure that re-importing doesn't cause auto-drafts to balloon.
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_customize->import_theme_starter_content();
</span><span class="cx" style="display: block; padding: 0 10px"> $changeset_data = $wp_customize->changeset_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'], 'Auto-drafts should not get re-created and amended with each import.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] ); // Auto-drafts should not get re-created and amended with each import.
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test that saving non-starter content on top of the changeset clears the starter_content flag.
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_customize->save_changeset_post( array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -539,6 +545,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( 'canola', get_custom_logo() );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( 'waffles', get_header_image() );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( 'waffles', get_background_image() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( 'waffles', get_post( $posts_by_name['waffles'] )->post_name );
+ $this->assertEmpty( get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) );
</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"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizenavmenusphp"></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/customize/nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/nav-menus.php 2016-12-05 16:56:50 UTC (rev 39505)
+++ trunk/tests/phpunit/tests/customize/nav-menus.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -549,14 +549,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Hello World', 'post_type' => 'post' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertInstanceOf( 'WP_Post', $r );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Hello World', $r->post_title );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( 'hello-world', $r->post_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( '', $r->post_name );
+ $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'post', $r->post_type );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Hello World', 'post_type' => 'post', 'post_name' => 'greetings-world', 'post_content' => 'Hi World' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertInstanceOf( 'WP_Post', $r );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Hello World', $r->post_title );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'post', $r->post_type );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( 'greetings-world', $r->post_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( '', $r->post_name );
+ $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Hi World', $r->post_content );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -739,11 +741,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $menus = new WP_Customize_Nav_Menus( $this->wp_customize );
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'customize_register', $this->wp_customize );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post_ids = $this->factory()->post->create_many( 3, array(
- 'post_status' => 'auto-draft',
- 'post_type' => 'post',
- 'post_name' => 'auto-draft',
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_ids = array();
+ for ( $i = 0; $i < 3; $i += 1 ) {
+ $r = $menus->insert_auto_draft_post( array(
+ 'post_title' => 'Auto Draft ' . $i,
+ 'post_type' => 'post',
+ 'post_name' => 'auto-draft-' . $i,
+ ) );
+ $this->assertInstanceOf( 'WP_Post', $r );
+ $post_ids[] = $r->ID;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $setting_id = 'nav_menus_created_posts';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -754,6 +762,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $post_ids, $setting->post_value() );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $post_ids as $post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'auto-draft', get_post_status( $post_id ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEmpty( get_post( $post_id )->post_name );
+ $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
</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"> $save_action_count = did_action( 'customize_save_nav_menus_created_posts' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -761,6 +771,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $post_ids as $post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'publish', get_post_status( $post_id ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
+ $this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
</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"> // Ensure that unique slugs were assigned.
</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-12-05 16:56:50 UTC (rev 39505)
+++ trunk/tests/phpunit/tests/post/wpUniquePostSlug.php 2016-12-05 19:32:09 UTC (rev 39506)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -347,46 +347,4 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( 'embed-2', $found );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- /**
- * @ticket 38928
- */
- public function test_non_unique_slugs_for_existing_auto_draft_posts() {
- $auto_draft_post_id = self::factory()->post->create( array(
- 'post_type' => 'post',
- 'post_name' => 'existing-post',
- 'post_status' => 'auto-draft',
- ) );
- $auto_draft_page_id = self::factory()->post->create( array(
- 'post_type' => 'page',
- 'post_name' => 'existing-page',
- 'post_status' => 'auto-draft',
- ) );
- $auto_draft_attachment_id = self::factory()->attachment->create_object( 'image.jpg', $auto_draft_page_id, array(
- 'post_mime_type' => 'image/jpeg',
- 'post_type' => 'attachment',
- 'post_name' => 'existing-attachment',
- 'post_status' => 'auto-draft',
- ) );
-
- $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
- $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
- $attachment_id = self::factory()->attachment->create_object( 'image2.jpg', $page_id, array(
- 'post_mime_type' => 'image/jpeg',
- 'post_type' => 'attachment',
- 'post_name' => 'existing-image',
- ) );
-
- $this->assertEquals( 'existing-post', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );
- wp_publish_post( $auto_draft_post_id );
- $this->assertEquals( 'existing-post-2', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );
-
- $this->assertEquals( 'existing-page', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );
- wp_publish_post( $auto_draft_page_id );
- $this->assertEquals( 'existing-page-2', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );
-
- $this->assertEquals( 'existing-attachment', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );
- wp_publish_post( $auto_draft_attachment_id );
- $this->assertEquals( 'existing-attachment-2', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>