Introduce a meta_box_cb argument for register_taxonomy().

The specified callback function is used as the meta box callback for the taxonomy.

props garyc40, helen.
fixes #14206.

Built from https://develop.svn.wordpress.org/trunk@25572


git-svn-id: http://core.svn.wordpress.org/trunk@25489 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-09-23 17:12:10 +00:00
parent b07e886ed4
commit 5febb6045f
3 changed files with 19 additions and 6 deletions

View File

@ -140,16 +140,18 @@ if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type,
// all taxonomies
foreach ( get_object_taxonomies( $post ) as $tax_name ) {
$taxonomy = get_taxonomy($tax_name);
$taxonomy = get_taxonomy( $tax_name );
if ( ! $taxonomy->show_ui )
continue;
$label = $taxonomy->labels->name;
if ( !is_taxonomy_hierarchical($tax_name) )
add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name ));
if ( ! is_taxonomy_hierarchical( $tax_name ) )
$tax_meta_box_id = 'tagsdiv-' . $tax_name;
else
add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name ));
$tax_meta_box_id = $tax_name . 'div';
add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) );
}
if ( post_type_supports($post_type, 'page-attributes') )

View File

@ -1139,8 +1139,8 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' )
* - map_meta_cap - Whether to use the internal default meta capability handling. Defaults to false.
* - supports - An alias for calling add_post_type_support() directly. Defaults to title and editor.
* * See {@link add_post_type_support()} for documentation.
* - register_meta_box_cb - Provide a callback function that will be called when setting up the
* meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback.
* - register_meta_box_cb - Provide a callback function that sets up the meta boxes
* for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback.
* - taxonomies - An array of taxonomy identifiers that will be registered for the post type.
* * Default is no taxonomies.
* * Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type().

View File

@ -289,6 +289,8 @@ function is_taxonomy_hierarchical($taxonomy) {
* * If not set, the default is inherited from public.
* - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
* * If not set, the default is inherited from show_ui.
* - meta_box_cb - Provide a callback function for the meta box display. Defaults to
* post_categories_meta_box for hierarchical taxonomies and post_tags_meta_box for non-hierarchical.
* - capabilities - Array of capabilities for this taxonomy.
* * You can see accepted values in this function.
* - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
@ -332,6 +334,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
'show_in_menu' => null,
'show_in_nav_menus' => null,
'show_tagcloud' => null,
'meta_box_cb' => null,
'capabilities' => array(),
'rewrite' => true,
'query_var' => $taxonomy,
@ -401,6 +404,14 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$args['labels'] = get_taxonomy_labels( (object) $args );
$args['label'] = $args['labels']->name;
// If not set, use the default meta box
if ( null === $args['meta_box_cb'] ) {
if ( $args['hierarchical'] )
$args['meta_box_cb'] = 'post_categories_meta_box';
else
$args['meta_box_cb'] = 'post_tags_meta_box';
}
$wp_taxonomies[ $taxonomy ] = (object) $args;
// register callback handling for metabox