add_meta_box() should accept array of post types
|Reported by:||coffee2code||Owned by:||madalin.ungureanu|
I often find myself defining an identical meta box for different post types. It would be nice if add_meta_box() accepted an array as its $page argument. For backward-compatibility the function will still accept a string. So for all else being equal, the same metabox could be added to multiple post types in a single line of code. Of course, if the meta box needs per-post_type configuration, add_meta_box() could be called separately for each post type.
add_meta_box( 'my-geo', 'Geolocation Info', array( &$this, 'geo_form' ), 'post', 'side' ); add_meta_box( 'my-geo', 'Geolocation Info', array( &$this, 'geo_form' ), 'page', 'side' ); add_meta_box( 'my-geo', 'Geolocation Info', array( &$this, 'geo_form' ), 'event', 'side' );
add_meta_box( 'my-geo', 'Geolocation Info', array( &$this, 'geo_form' ), array( 'post', 'page', 'event' ), 'side' );
Of course, the former would continue to work.
One could certainly loop through the post types manually to call add_meta_box(), but I think the proposed patch clarifies coding intention.
Patch is attached. (In the patch, I didn't indent the content of the newly introduced foreach() ... endforeach; since it would look like the whole function got changed when in fact I only made a very minor change. The function also has a precendent of a non-indented foreach. However, I would anticipate the actual commit might want the indentation, which can be provided.)
(Note: affects, or affected by, #13937)
Change History (29)
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
comment:5 @ericlewis — 11 months ago
- Keywords has-patch removed
- Resolution duplicate deleted
- Status changed from closed to reopened
- Milestone set to Awaiting Review
comment:13 @DrewAPicture — 8 months ago
- Owner set to iamfriendly
- Status changed from reopened to assigned