WordPress.org

Make WordPress Core

#38539 closed defect (bug) (fixed)

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

Reported by: westonruter Owned by: 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 16 months ago.
38539.1.diff (3.4 KB) - added by westonruter 16 months ago.
38539.2.diff (7.9 KB) - added by westonruter 16 months ago.

Download all attachments as: .zip

Change History (10)

#1 @westonruter
16 months 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.

#2 @westonruter
16 months 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
16 months ago

  • Description modified (diff)

#4 @westonruter
16 months 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
16 months ago

#38568 was marked as a duplicate.

#7 @westonruter
16 months 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.