[wp-trac] [WordPress Trac] #15000: add_meta_box() should accept array of post types

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 30 19:15:04 UTC 2010


#15000: add_meta_box() should accept array of post types
----------------------------+-----------------------------------------------
 Reporter:  coffee2code     |       Owner:                 
     Type:  enhancement     |      Status:  new            
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:  3.0.1          
 Severity:  minor           |    Keywords:  has-patch      
----------------------------+-----------------------------------------------
 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.

 Example:

 {{{
 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' );
 }}}

 would become:

 {{{
 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)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15000>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list