Skip to content

Commit 8c81b54

Browse files
committed
wp_category_checklist() fixes from mdawaffe. fixes WordPress#6810 for trunk
git-svn-id: https://develop.svn.wordpress.org/trunk@7777 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6964bbb commit 8c81b54

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

wp-admin/admin-ajax.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@
162162
if ( $parent ) // Do these all at once in a second
163163
continue;
164164
$category = get_category( $cat_id );
165-
$checked_categories[] = $cat_id;
166165
ob_start();
167-
dropdown_categories( 0, $category );
166+
wp_category_checklist( 0, $cat_id, $checked_categories );
168167
$data = ob_get_contents();
169168
ob_end_clean();
170169
$x->add( array(

wp-admin/includes/template.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,25 +148,35 @@ function end_el(&$output, $category, $depth, $args) {
148148
}
149149
}
150150

151-
function wp_category_checklist( $post_id = 0 ) {
151+
function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) {
152152
$walker = new Walker_Category_Checklist;
153+
$descendants_and_self = (int) $descendants_and_self;
153154

154155
$args = array();
155156

156157
if ( $post_id )
157158
$args['selected_cats'] = wp_get_post_categories($post_id);
158159
else
159160
$args['selected_cats'] = array();
160-
$args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10 ) );
161-
$categories = get_categories('get=all');
161+
if ( is_array( $selected_cats ) )
162+
$args['selected_cats'] = $selected_cats;
163+
$args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
164+
if ( $descendants_and_self ) {
165+
$categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
166+
$self = get_category( $descendants_and_self );
167+
array_unshift( $categories, $self );
168+
} else {
169+
$categories = get_categories('get=all');
170+
}
171+
162172
$args = array($categories, 0, $args);
163173
$output = call_user_func_array(array(&$walker, 'walk'), $args);
164174

165175
echo $output;
166176
}
167177

168178
function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
169-
$categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) );
179+
$categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
170180

171181
$popular_ids = array();
172182
foreach ( (array) $categories as $category ) {

wp-admin/js/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jQuery(document).ready( function() {
131131
var th = jQuery(this);
132132
var val = th.find('input').val();
133133
var id = th.find('input')[0].id
134-
jQuery('#' + id).change( syncChecks );
134+
jQuery('#' + id).change( syncChecks ).change();
135135
if ( newCatParent.find( 'option[value=' + val + ']' ).size() )
136136
return;
137137
var name = jQuery.trim( th.text() );

wp-includes/script-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function default_scripts() {
144144
'save' => __('Save'),
145145
'cancel' => __('Cancel'),
146146
) );
147-
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080411' );
147+
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080422' );
148148
$this->localize( 'post', 'postL10n', array(
149149
'tagsUsed' => __('Tags used on this post:'),
150150
'add' => attribute_escape(__('Add')),

0 commit comments

Comments
 (0)