[wp-trac] [WordPress Trac] #48166: Cannot create a new CPT when passing NULL to taxonomies

WordPress Trac noreply at wordpress.org
Wed Oct 2 19:42:33 UTC 2019


#48166: Cannot create a new CPT when passing NULL to taxonomies
-------------------------------+----------------------
 Reporter:  scarr              |       Owner:  (none)
     Type:  defect (bug)       |      Status:  closed
 Priority:  normal             |   Milestone:
Component:  Posts, Post Types  |     Version:  5.2.3
 Severity:  normal             |  Resolution:  invalid
 Keywords:  has-patch          |     Focuses:
-------------------------------+----------------------

Comment (by scarr):

 @jrf - Sorry for the earlier rant. But, I feel compelled to raise this
 issue:

 **Please, don’t needlessly force coding restrictions on your customers**.

 If I don’t want to declare taxonomies inside a cpt declaration, why should
 I have to memorize the fact that the parameter still needs to be set?
 Doesn’t it make equal sense to have your customer (the developer) simply
 ignore setting the parameter all together in that case? You know, make it
 optional, like you do so many other parameters in WordPress.

 And, it does not cost anything from a performance perspective. You are
 adding an if-statement to your code, thus eliminating the if-statement in
 my code.
         Your code adds:
                 //* to register_taxonomies() in wp-includes/class-wp-post-
 type.php
                 if (!is_array($this->taxonomies)) { return; }
         My code loses:
                 //* Because I cannot ASSUME good behavior from my
 customers
                 If (!is_array($taxomonies) { $taxomonies=array(); }

 Your “public function”, register_taxonomies, is now bullet proof and I
 (the customer) have one less aspect to memorize regarding the WordPress
 interface. It’s a win-win proposition.


 Replying to [comment:7 scarr]:
 > Hey, thanks for the encouraging feedback. I'll be sure to jump in to
 help again!
 >
 > Perhaps, if the code was a bit better from a best practices perspective,
 you wouldn't have your time wasted by people like me who "should just read
 the documentation."
 >
 > Replying to [comment:5 jrf]:
 > > My two pennies: this sounds more like a case of "doing it wrong" than
 as a bug to be fixed.

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


More information about the wp-trac mailing list