[wp-trac] [WordPress Trac] #48166: Cannot create a new CPT without taxonomies

WordPress Trac noreply at wordpress.org
Mon Sep 30 04:59:34 UTC 2019


#48166: Cannot create a new CPT without taxonomies
-----------------------------------+------------------------------
 Reporter:  scarr                  |       Owner:  (none)
     Type:  defect (bug)           |      Status:  new
 Priority:  normal                 |   Milestone:  Awaiting Review
Component:  Posts, Post Types      |     Version:  5.2.3
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+------------------------------
Changes (by subrataemfluence):

 * keywords:  has-patch => has-patch 2nd-opinion


Comment:

 @scarr thanks for the ticket and the proposal, which works well if
 `$taxonomy => null`.
 The workaround looks good, but I have some thoughts about whether we
 should go for it or not.

 We only use `$taxonomies` keys when we need to add one or more taxonomies
 to a custom post type. I don't see a reason to add this key with a NULL
 value intentionally while registering a CPT.

 And if we need to add this check for `$taxonomies`, it has to be added for
 `$capabilities` key too.

 What I think is we use these keys to form the associative array (`$args`),
 only when we know what value to pass. For passing just `NULL`, we don't
 use them.

 However, from coding-best-practice perspective, I would say it is a good
 idea to bring it in, but if we do, we have to incorporate at in other
 areas of the core as well, like once I mentioned above.

 Regarding summary:
 A CPT can always be created if no `$taxonomies` key is used or it is
 assigned with an empty array like `$taxonomies => array()`. The only
 situation it throws the said error when the value is NULL, i.e.
 `$taxonomies => NULL`. So, for me the initial summary by @scarr was
 correct, i.e. **Cannot create new CPT when passing NULL to taxonomies**.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48166#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list