[wp-trac] [WordPress Trac] #48166: Cannot create a new CPT when passing NULL to taxonomies
WordPress Trac
noreply at wordpress.org
Mon Sep 30 14:34:43 UTC 2019
#48166: Cannot create a new CPT when passing NULL to 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:
-----------------------------------+------------------------------
Comment (by subrataemfluence):
Thank you @scarr.
Jut to add, if you don't want to associate any taxonomy with your Custom
Post Type, just **don't define that key at all**. No need to add
`$taxonomies => array()`. It is not mandatory. A CPT is good enough
without any taxonomy associated with it.
If `$taxonomies` key is not defined, the post type will be created without
any associated taxonomy. Use this only if you need to add any. For
example:
{{{
$taxonomies => array( 'category', 'some-other-taxonomy', ... ),
}}}
Replying to [comment:3 scarr]:
> @subrataemfluence - Thank you for taking swift action on my ticket.
>
> Your characterization of the issue I raised is a much more accurate (and
better) re-statement, **Cannot create new CPT when passing NULL to
taxonomies**. I've adjusted the description to reflect it. Further, I
agree that $capabilities suffers the same issue.
>
> I also accept your workaround - use "'taxonomies' => array()" instead of
"'taxonomies' => NULL" when creating a CPT without taxonomies.
>
> Finally, I will leave it to the Core Team to decide whether to accept my
proposal on a best "best practices" basis.
>
> @scarr
>
> Replying to [comment:2 subrataemfluence]:
> > @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:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list