Opened 10 months ago
Last modified 8 months ago
#21543 new enhancement
Add a show_metabox parameter to register_taxonomy
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Taxonomy | Version: | |
| Severity: | normal | Keywords: | has-patch 2nd-opinion |
| Cc: | 24-7@…, xoodrew@…, lol@… |
Description (last modified by SergeyBiryukov)
Currently when registering a taxonomy we have the $show_ui param, this effects both the admin menu and the actual taxonomy meta box on the post edit screens.
There are cases when you want it to show in one but not the other, to do that now you have to use either remove_meta_box or remove_menu_page.
It would be nice to add another parameter like show_metabox => array(posts) to register_taxonomy which would effect the meta boxes only. And one for the admin menu as well.
related: #12718
Attachments (2)
Change History (9)
comment:1
SergeyBiryukov — 10 months ago
- Description modified (diff)
comment:2
SergeyBiryukov — 10 months ago
- Component changed from General to Taxonomy
comment:3
F J Kaiser — 10 months ago
- Cc 24-7@… added
comment:4
follow-up:
↓ 5
DrewAPicture — 9 months ago
- Cc xoodrew@… added
- Keywords has-patch 2nd-opinion added
I'm not sure this constitutes 'major changes' but took a stab at a different option in 21543.diff. Taking a cue from how rewrite was handled in register_post_type(), I allowed public to accept either a boolean or array. And it's backward compatible, so either of these works:
'public' => true
or
'public' => array( 'admin_menu' => false, 'meta_box' => true )
The indexes also default to true if not set.
I'd appreciate some feedback on whether there's a more elegant way to go about it.
DrewAPicture — 9 months ago
comment:5
in reply to:
↑ 4
F J Kaiser — 9 months ago
Replying to DrewAPicture:
'public' => trueor
'public' => array( 'admin_menu' => false, 'meta_box' => true )
I wouldn't add an array. We already got public => true for both of them. Why add admin_menu => false when the whole thing is an A/B decision: meta_box/admin_menu: yes = set in string. No need for an array, as we don't need to state false for the second option - the typeOf( string ) already tells us, that we only want one of them.
comment:6
DrewAPicture — 9 months ago
Setting 'meta_box => true isn't actually necessary, I just added it for the comparison.
'public' => array( 'admin_menu' => false )
Is exactly the same.
The reason I went with an array instead of a string was so that we wouldn't get stuck with an A/B decision. It future-proofs the public param. Look at it from an extensibility standpoint. In the future a need to add another argument would be trivial, but turning an A/B decision into an A/B/C decision would probably result in an array anyway.

Maybe even easier:
The show_ui argument comes in ~/wp-admin/menu.php to add the admin menu entry and in ~/wp-admin/edit-form-advanced.php to add the meta box.
Currently both tests are against an expected boolean:
# ~/wp-admin/menu.php if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) ) # add menu entry # ~/wp-admin/edit-form-advanced.php if ( ! $taxonomy->show_ui ) # add meta boxWe could simply extend the test and check for a string value too:
# ~/wp-admin/menu.php if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) || is_string( $tax->show_ui ) AND 'admin_menu' === $tax->show_ui ) # add menu entry # ~/wp-admin/edit-form-advanced.php if ( ! $taxonomy->show_ui || is_string( $taxonomy->show_ui ) AND 'meta_box' === $taxonomy->show_ui ) # add meta boxThis would be backwards compatible and allow showing in the menu or the meta box without major changes.