Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#38539 closed defect (bug) (fixed)

Customizer post/page stubs fail to get unique slugs when publishing

Reported by: westonruter's profile westonruter Owned by: westonruter's profile westonruter
Milestone: 4.7 Priority: normal
Severity: normal Version:
Component: Customize Keywords: has-patch
Focuses: Cc:

Description (last modified by westonruter)

I noticed that after initializing Twenty Seventeen all of the Top nav menu items all linked to the homepage. It turns out that the auto-draft status post/page stubs were not getting a post_name specified and so the permalink for them would point to the homepage.

Likewise, when adding new nav menu items, I'm able to supply titles which then result in pages/posts that have the same post_name as other items. This is due to wp_publish_posts() being used which bypasses the unique slug check.

See #38114, #38013, #34923

Attachments (3)

38539.0.diff (717 bytes) - added by westonruter 8 years ago.
38539.1.diff (3.4 KB) - added by westonruter 8 years ago.
38539.2.diff (7.9 KB) - added by westonruter 8 years ago.

Download all attachments as: .zip

Change History (10)

@westonruter
8 years ago

#1 @westonruter
8 years ago

Naturally this issue was addressed by \WP_Customize_Nav_Menus::insert_auto_draft_post() and since we require the nav menus component anyway for inserting post/page stubs, we might as well re-use it.

@westonruter
8 years ago

#2 @westonruter
8 years ago

  • Description modified (diff)
  • Keywords has-patch needs-unit-tests added
  • Owner set to westonruter
  • Status changed from new to accepted
  • Summary changed from Auto-draft posts/pages inserted from starter content lack slugs to Post/page stubs fail to get unique slugs

#3 @westonruter
8 years ago

  • Description modified (diff)

#4 @westonruter
8 years ago

  • Summary changed from Post/page stubs fail to get unique slugs to Customizer post/page stubs fail to get unique slugs when publishing

#5 @westonruter
8 years ago

#38568 was marked as a duplicate.

@westonruter
8 years ago

#7 @westonruter
8 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 39038:

Customize: Prevent auto-draft post/page stubs from being saved with empty slugs or published with non-unique slugs.

  • Allow WP_Customize_Nav_Menus::insert_auto_draft_post() to take full post array to pass to wp_insert_post(), except for post_status. Require post_title.
  • Ensure empty post_name gets explicitly set to slugified post_title.
  • Explicitly allow only post_type and post_title params in WP_Customize_Nav_Menus::ajax_insert_auto_draft_post().
  • Use wp_update_post() instead of wp_publish_post() to ensure unique slugs are assigned to published auto-draft posts.
  • Re-use WP_Customize_Nav_Menus::insert_auto_draft_post() when inserting stubs from starter content.


See #38114, #38013, #34923.
Fixes #38539.

Note: See TracTickets for help on using tickets.