diff --git a/wp-admin/categories.php b/wp-admin/categories.php index 5fe9ef6ff4..b6c6c1ff25 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -11,7 +11,25 @@ require_once('admin.php'); $title = __('Categories'); -wp_reset_vars( array('action') ); +wp_reset_vars( array('action', 'taxonomy', 'post_type') ); + +if ( empty($taxonomy) ) + $taxonomy = 'category'; + +if ( !is_taxonomy($taxonomy) ) + wp_die(__('Invalid taxonomy')); + +if ( empty($post_type) || !in_array( $post_type, get_post_types( array('_show' => true) ) ) ) + $post_type = 'post'; + +if ( 'post' != $post_type ) { + $parent_file = "edit.php?post_type=$post_type"; + $submenu_file = "categories.php?taxonomy=$taxonomy&post_type=$post_type"; +} else { + $parent_file = 'edit.php'; + $submenu_file = "categories.php?taxonomy=$taxonomy"; +} + if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) ) $action = 'bulk-delete'; @@ -135,7 +153,7 @@ $messages[5] = __('Category not updated.');

' . __('Search results for “%s”') . '', esc_html( stripslashes($_GET['s']) ) ); ?>

@@ -146,6 +164,8 @@ if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?> endif; ?>
+ +
+ +
0, 'search' => $_GET['s']))); + $num_cats = count(get_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'search' => $_GET['s']))); else - $num_cats = wp_count_terms('category'); + $num_cats = wp_count_terms($taxonomy); $page_links = paginate_links( array( 'base' => add_query_arg( 'pagenum', '%#%' ), @@ -218,7 +240,7 @@ if ( $page_links ) @@ -244,8 +266,12 @@ if ( $page_links )
-

Note:
Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category %s.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?>

+ +

Note:
Deleting a %1$s does not delete the objects in that %1$s. Instead, objects that were only assigned to the deleted %1$s are set to the %1$s %2$s.'), $tax->label, apply_filters('the_category', get_cat_name(get_option('default_' . $taxonomy)))) ?>

+ +

category to tag converter.'), 'admin.php?import=wp-cat2tag') ?>

+
@@ -261,6 +287,8 @@ if ( $page_links )

+ + @@ -278,7 +306,7 @@ if ( $page_links )
- 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?> + 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>

diff --git a/wp-admin/includes/taxonomy.php b/wp-admin/includes/taxonomy.php index 2bbecad855..dc4484eb94 100644 --- a/wp-admin/includes/taxonomy.php +++ b/wp-admin/includes/taxonomy.php @@ -108,7 +108,7 @@ function wp_delete_category($cat_ID) { * @return unknown */ function wp_insert_category($catarr, $wp_error = false) { - $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => ''); + $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => ''); $catarr = wp_parse_args($catarr, $cat_defaults); extract($catarr, EXTR_SKIP); @@ -142,9 +142,9 @@ function wp_insert_category($catarr, $wp_error = false) { $args = compact('name', 'slug', 'parent', 'description'); if ( $update ) - $cat_ID = wp_update_term($cat_ID, 'category', $args); + $cat_ID = wp_update_term($cat_ID, $taxonomy, $args); else - $cat_ID = wp_insert_term($cat_name, 'category', $args); + $cat_ID = wp_insert_term($cat_name, $taxonomy, $args); if ( is_wp_error($cat_ID) ) { if ( $wp_error ) diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 9be6d6d313..a12d6bb4d6 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -20,13 +20,13 @@ * @param unknown_type $page * @param unknown_type $per_page */ -function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) { +function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20, $taxonomy = 'category' ) { $count = 0; if ( empty($categories) ) { - $args = array('hide_empty' => 0); + $args = array('hide_empty' => 0, 'taxonomy' => $taxonomy); if ( !empty($_GET['s']) ) $args['search'] = $_GET['s']; @@ -36,9 +36,9 @@ function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_pag return false; } - $children = _get_term_hierarchy('category'); + $children = _get_term_hierarchy($taxonomy); - _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count ); + echo _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count ); } @@ -53,14 +53,14 @@ function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_pag * @param unknown_type $level * @param unknown_type $page * @param unknown_type $per_page - * @return unknown + * @return string the output of the table. */ function _cat_rows( $parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count ) { $start = ($page - 1) * $per_page; $end = $start + $per_page; - ob_start(); + $output = ''; foreach ( $categories as $key => $category ) { if ( $count >= $end ) break; @@ -83,26 +83,23 @@ function _cat_rows( $parent = 0, $level = 0, $categories, &$children, $page = 1, $num_parents = count($my_parents); while( $my_parent = array_pop($my_parents) ) { - echo "\t" . _cat_row( $my_parent, $level - $num_parents ); + $output = "\t" . _cat_row( $my_parent, $level - $num_parents ); $num_parents--; } } if ( $count >= $start ) - echo "\t" . _cat_row( $category, $level ); + $output .= "\t" . _cat_row( $category, $level ); unset( $categories[ $key ] ); $count++; if ( isset($children[$category->term_id]) ) - _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count ); + $output .= _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count ); } - $output = ob_get_contents(); - ob_end_clean(); - - echo $output; + return $output; } /** @@ -2568,7 +2565,7 @@ function meta_form() { ?> - + @@ -3239,7 +3236,7 @@ function find_posts_div($found_action = '') { -
+
@@ -3249,7 +3246,7 @@ function find_posts_div($found_action = '') {
- +
diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 351e047602..97f3101199 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -47,15 +47,16 @@ $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu $i = 15; foreach ( $wp_taxonomies as $tax ) { - if ( $tax->hierarchical || ! in_array('post', (array) $tax->object_type, true) ) + if ( ! in_array('post', (array) $tax->object_type, true) ) continue; - $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name ); + if ( $tax->hierarchical ) + $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'categories.php?taxonomy=' . $tax->name ); + else + $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name ); ++$i; } - $submenu['edit.php'][50] = array( __('Categories'), 'manage_categories', 'categories.php' ); - $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' ); $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php'); /* translators: add new file */ @@ -86,10 +87,13 @@ foreach ( (array) get_post_types( array('_show' => true) ) as $ptype ) { $i = 15; foreach ( $wp_taxonomies as $tax ) { - if ( $tax->hierarchical || ! in_array($ptype, (array) $tax->object_type, true) ) + if ( ! in_array($ptype, (array) $tax->object_type, true) ) continue; - $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" ); + if ( $tax->hierarchical ) + $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "categories.php?taxonomy=$tax->name&post_type=$ptype" ); + else + $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" ); ++$i; } } diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index b0c9f47386..ceb4ce0e9e 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -337,7 +337,8 @@ function wp_dropdown_categories( $args = '' ) { 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', - 'depth' => 0, 'tab_index' => 0 + 'depth' => 0, 'tab_index' => 0, + 'taxonomy' => 'category', 'hide_if_empty' => false ); $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; @@ -359,9 +360,11 @@ function wp_dropdown_categories( $args = '' ) { $name = esc_attr($name); $class = esc_attr($class); - $output = ''; - if ( ! empty( $categories ) ) { + if ( ! $r['hide_if_empty'] || ! empty($categories) ) $output = "\n"; } + if ( ! $r['hide_if_empty'] || ! empty($categories) ) + $output .= "\n"; + $output = apply_filters( 'wp_dropdown_cats', $output ); diff --git a/wp-includes/category.php b/wp-includes/category.php index f9da42e3b5..26c6a4281e 100644 --- a/wp-includes/category.php +++ b/wp-includes/category.php @@ -37,12 +37,14 @@ function get_all_category_ids() { * @return array List of categories. */ function &get_categories( $args = '' ) { - $defaults = array( 'type' => 'category' ); + $defaults = array( 'taxonomy' => 'category' ); $args = wp_parse_args( $args, $defaults ); - $taxonomy = apply_filters( 'get_categories_taxonomy', 'category', $args ); - if ( 'link' == $args['type'] ) - $taxonomy = 'link_category'; + $taxonomy = apply_filters( 'get_categories_taxonomy', $args['taxonomy'], $args ); + + if ( isset($args['type']) && 'link' == $args['type'] ) //Back compat + $taxonomy = $args['taxonomy'] = 'link_category'; + $categories = (array) get_terms( $taxonomy, $args ); foreach ( array_keys( $categories ) as $k )