From 6e23bed1fd3cdccb72ecc5eac0fa3d87c65abd44 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 22 Apr 2008 22:45:53 +0000 Subject: [PATCH] wp_category_checklist() fixes from mdawaffe. fixes #6810 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@7777 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 3 +-- wp-admin/includes/template.php | 18 ++++++++++++++---- wp-admin/js/post.js | 2 +- wp-includes/script-loader.php | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 4e87164400..839070c346 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -162,9 +162,8 @@ case 'add-category' : // On the Fly if ( $parent ) // Do these all at once in a second continue; $category = get_category( $cat_id ); - $checked_categories[] = $cat_id; ob_start(); - dropdown_categories( 0, $category ); + wp_category_checklist( 0, $cat_id, $checked_categories ); $data = ob_get_contents(); ob_end_clean(); $x->add( array( diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 5a7ec974e2..c3884cd299 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -148,8 +148,9 @@ class Walker_Category_Checklist extends Walker { } } -function wp_category_checklist( $post_id = 0 ) { +function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) { $walker = new Walker_Category_Checklist; + $descendants_and_self = (int) $descendants_and_self; $args = array(); @@ -157,8 +158,17 @@ function wp_category_checklist( $post_id = 0 ) { $args['selected_cats'] = wp_get_post_categories($post_id); else $args['selected_cats'] = array(); - $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10 ) ); - $categories = get_categories('get=all'); + if ( is_array( $selected_cats ) ) + $args['selected_cats'] = $selected_cats; + $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); + if ( $descendants_and_self ) { + $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" ); + $self = get_category( $descendants_and_self ); + array_unshift( $categories, $self ); + } else { + $categories = get_categories('get=all'); + } + $args = array($categories, 0, $args); $output = call_user_func_array(array(&$walker, 'walk'), $args); @@ -166,7 +176,7 @@ function wp_category_checklist( $post_id = 0 ) { } function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) { - $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) ); + $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); $popular_ids = array(); foreach ( (array) $categories as $category ) { diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 18c9706fac..c938af3015 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -131,7 +131,7 @@ jQuery(document).ready( function() { var th = jQuery(this); var val = th.find('input').val(); var id = th.find('input')[0].id - jQuery('#' + id).change( syncChecks ); + jQuery('#' + id).change( syncChecks ).change(); if ( newCatParent.find( 'option[value=' + val + ']' ).size() ) return; var name = jQuery.trim( th.text() ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index a4894fbcc1..60a994f04b 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -144,7 +144,7 @@ class WP_Scripts { 'save' => __('Save'), 'cancel' => __('Cancel'), ) ); - $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080411' ); + $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080422' ); $this->localize( 'post', 'postL10n', array( 'tagsUsed' => __('Tags used on this post:'), 'add' => attribute_escape(__('Add')),