WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 6 months ago

#39610 closed defect (bug) (fixed)

Customize: Custom post types cannot be used in starter content

Reported by: westonruter Owned by: westonruter
Milestone: 4.7.3 Priority: normal
Severity: normal Version: 4.7
Component: Customize Keywords: has-patch has-unit-tests commit fixed-major
Focuses: Cc:

Description

As reported by @tiagonoronha:

hi! I noticed that custom posts types cannot be used in Starter Content. CPTs are registered in the init hook, way after starter content is loaded in after_theme_setup. Is this a known issue? thanks!

and:

Hi! Well, they literally cannot be used in any way. Adding a post of a CPT in starter content gives me a warning in the customizer. I’m testing this with WooCommerce that registers the CPTs on init. This is not a problem with the default post types because they get registered two times, in wp-settings.php and then again on the init hook.

Attachments (3)

39610.0.diff (705 bytes) - added by westonruter 7 months ago.
39610.test-case.diff (830 bytes) - added by westonruter 7 months ago.
39610.1.diff (4.9 KB) - added by westonruter 7 months ago.

Download all attachments as: .zip

Change History (13)

@westonruter
7 months ago

#1 @westonruter
7 months ago

  • Keywords has-patch needs-testing added

#2 @westonruter
7 months ago

The problem is that \WP_Customize_Nav_Menus::insert_auto_draft_post() was doing a post_type_exists() check and bailing. It's clear that for the purposes of this API method there needn't be a post type existence check, especially in the case of importing starter content. Note that post_type_exists() check is still present in WP_Customize_Nav_Menus::ajax_insert_auto_draft_post() and so the check was actually redundant.

Last edited 7 months ago by westonruter (previous) (diff)

#3 @westonruter
7 months ago

A fix also was needed in Customize Posts to prevent a warning from being triggered: https://github.com/xwp/wp-customize-posts/pull/340

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


7 months ago

@westonruter
7 months ago

#5 @westonruter
7 months ago

  • Keywords has-unit-tests added

#6 @tiagonoronha
7 months ago

@westonruter tested, works perfectly! :)

#7 @westonruter
7 months ago

  • Keywords commit added; needs-testing removed
  • Owner set to westonruter
  • Status changed from new to accepted

#8 @westonruter
7 months ago

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

In 39924:

Customize: Allow custom post types to be used in starter content.

Changes WP_Customize_Nav_Menus::insert_auto_draft_post() so it can be invoked for a post_type that is not registered (yet).

See #38615, #38114.
Fixes #39610.

#9 @westonruter
7 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-opening for 4.7.2

#10 @dd32
6 months ago

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

In 40098:

Customize: Allow custom post types to be used in starter content.

Changes WP_Customize_Nav_Menus::insert_auto_draft_post() so it can be invoked for a post_type that is not registered (yet).

Props westonruter.
Merges [39924] to the 4.7 branch.
See #38615, #38114.
Fixes #39610.

Note: See TracTickets for help on using tickets.