[wp-trac] [WordPress Trac] #38928: Default theme content - problem with slugs
WordPress Trac
noreply at wordpress.org
Mon Nov 28 23:18:37 UTC 2016
#38928: Default theme content - problem with slugs
--------------------------+--------------------
Reporter: pavelevap | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.7
Component: Customize | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+--------------------
Changes (by westonruter):
* component: General => Customize
* milestone: Awaiting Review => 4.7
Comment:
I can replicate this issue. It happens if you open the customizer, close
it, and then open it again so that the starter content gets imported a
second time. When you do that, you currently get a posts table that looks
like:
{{{
+----+--------------------+--------------------+---------------------+-------------+
| ID | post_title | post_name | post_date |
post_status |
+----+--------------------+--------------------+---------------------+-------------+
| 19 | A homepage section | a-homepage-section | 2016-11-28 23:08:28 |
auto-draft |
| 18 | Blog | blog | 2016-11-28 23:08:28 |
auto-draft |
| 17 | Contact | contact | 2016-11-28 23:08:28 |
auto-draft |
| 16 | About | about | 2016-11-28 23:08:28 |
auto-draft |
| 15 | Home | home | 2016-11-28 23:08:28 |
auto-draft |
| 10 | A homepage section | a-homepage-section | 2016-11-28 23:08:16 |
auto-draft |
| 9 | Blog | blog | 2016-11-28 23:08:16 |
auto-draft |
| 8 | Contact | contact | 2016-11-28 23:08:16 |
auto-draft |
| 7 | About | about | 2016-11-28 23:08:16 |
auto-draft |
| 6 | Home | home | 2016-11-28 23:08:16 |
auto-draft |
+----+--------------------+--------------------+---------------------+-------------+
}}}
There are two fixes we can consider here, which aren't mutually exclusive:
For one, the logic for `wp_unique_post_slug()` can be changed to
explicitly ignore `auto-draft` posts when it is doing the lookup to see if
a slug is already being used. This seems like a no-brainer:
{{{#!diff
--- src/wp-includes/post.php
+++ src/wp-includes/post.php
@@ -3673,7 +3673,7 @@ function wp_unique_post_slug( $slug, $post_ID,
$post_status, $post_type, $post_p
if ( 'attachment' == $post_type ) {
// Attachment slugs must be unique across all types.
- $check_sql = "SELECT post_name FROM $wpdb->posts WHERE
post_name = %s AND ID != %d LIMIT 1";
+ $check_sql = "SELECT post_name FROM $wpdb->posts WHERE
post_status != 'auto-draft' post_name = %s AND ID != %d LIMIT 1";
$post_name_check = $wpdb->get_var( $wpdb->prepare(
$check_sql, $slug, $post_ID ) );
/**
}}}
The second fix would be specifically to account for when we allow starter
content to be applied on existing sites. Namely, when we do our lookup to
see if there are existing auto-draft posts in the current customized state
that have the given slugs… we could expand this to see if there are any
non-auto-draft posts _outside_ the customized state which already have
those slugs, and then re-use them instead of inserting new auto-drafts.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38928#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list