WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 21 months ago

Last modified 17 months ago

#21543 closed enhancement (fixed)

Add a show_metabox parameter to register_taxonomy

Reported by: wycks Owned by: helen
Milestone: 3.8 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

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 (5)

21543.diff (2.8 KB) - added by DrewAPicture 3 years ago.
21543.2.diff (2.7 KB) - added by DrewAPicture 3 years ago.
Removed dupes
21543.3.diff (647 bytes) - added by helen 21 months ago.
21543.4.diff (1.7 KB) - added by helen 21 months ago.
21543.5.diff (933 bytes) - added by ocean90 21 months ago.

Download all attachments as: .zip

Change History (21)

comment:1 @SergeyBiryukov3 years ago

  • Description modified (diff)

comment:2 @SergeyBiryukov3 years ago

  • Component changed from General to Taxonomy

comment:3 @F J Kaiser3 years ago

  • Cc 24-7@… added

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 box

We 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 box

This would be backwards compatible and allow showing in the menu or the meta box without major changes.

Last edited 3 years ago by F J Kaiser (previous) (diff)

comment:4 follow-up: @DrewAPicture3 years 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.

@DrewAPicture3 years ago

@DrewAPicture3 years ago

Removed dupes

comment:5 in reply to: ↑ 4 @F J Kaiser3 years ago

Replying to DrewAPicture:

'public' => true

or

'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 @DrewAPicture3 years 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.

comment:7 @sc0ttkclark3 years ago

  • Cc lol@… added

I'd like to see this ability too

comment:8 @helen21 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

I believe this should actually work now through the addition of the meta_box_cb arg - you should be able to pass false and have no meta box be used. Closing as a dupe of #14206.

comment:9 follow-up: @helen21 months ago

  • Milestone set to Awaiting Review
  • Resolution duplicate deleted
  • Status changed from closed to reopened

Oh, I lied. It gets mad if you pass false. Reopening - I think we should make that work.

comment:10 in reply to: ↑ 9 @DrewAPicture21 months ago

Replying to helen:

Oh, I lied. It gets mad if you pass false. Reopening - I think we should make that work.

+1 for making that work. Seems logical :)

@helen21 months ago

@helen21 months ago

comment:11 @helen21 months ago

  • Milestone changed from Awaiting Review to 3.8

comment:12 @helen21 months ago

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

In 25948:

Allow passing false for the meta_box_cb arg in register_taxonomy() to turn off the meta box display entirely. fixes #21543.

@ocean9021 months ago

comment:13 @ocean9021 months ago

  • Keywords 2nd-opinion removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

IMO we should put the check a bit higher, see 21543.5.diff.

comment:14 @helen21 months ago

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

In 25953:

Consolidate logic for not showing a taxonomy meta box. props ocean90. fixes #21543.

comment:15 follow-up: @webvakman17 months ago

  • Keywords 2nd-opinion added
  • Type changed from enhancement to feature request

#21543
This only solves half of the ticket. Although the meta-box can be turned off now, the admin-menu still can't.

comment:16 in reply to: ↑ 15 @SergeyBiryukov17 months ago

  • Keywords 2nd-opinion removed
  • Type changed from feature request to enhancement

Replying to webvakman:

This only solves half of the ticket. Although the meta-box can be turned off now, the admin-menu still can't.

You can set show_ui parameter to false, which will disable both the meta box and the admin menu item.

This ticket was closed on a completed milestone. If you have additional suggestions, please open a new one.

Note: See TracTickets for help on using tickets.