From 5febb6045fc410d6d38d6daa39cb73160385d6ed Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 23 Sep 2013 17:12:10 +0000 Subject: [PATCH] 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 --- wp-admin/edit-form-advanced.php | 10 ++++++---- wp-includes/post.php | 4 ++-- wp-includes/taxonomy.php | 11 +++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 3dbbb6bd85..e466606a00 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -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') ) diff --git a/wp-includes/post.php b/wp-includes/post.php index d28f5984d9..1d305de18d 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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(). diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index acb8517ce7..69e1622f85 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -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