Ticket #16475: 16475.patch
File 16475.patch, 3.0 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/template.php
90 90 'taxonomy' => 'category', 91 91 'checked_ontop' => true 92 92 ); 93 93 94 extract( wp_parse_args($args, $defaults), EXTR_SKIP ); 94 95 95 if ( empty($walker) || !is_a($walker, 'Walker') ) 96 if ( empty($walker) || !is_a($walker, 'Walker') ) 96 97 $walker = new Walker_Category_Checklist; 97 98 98 99 $descendants_and_self = (int) $descendants_and_self; 99 100 100 $args = array('taxonomy' => $taxonomy); 101 102 101 $tax = get_taxonomy($taxonomy); 103 102 $args['disabled'] = !current_user_can($tax->cap->assign_terms); 104 103 105 104 if ( is_array( $selected_cats ) ) 106 105 $args['selected_cats'] = $selected_cats; 107 elseif ( $post_id ) 106 elseif ( $post_id ) 108 107 $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids'))); 109 108 else 110 109 $args['selected_cats'] = array(); 111 110 112 111 if ( is_array( $popular_cats ) ) 112 113 113 $args['popular_cats'] = $popular_cats; 114 114 else 115 115 $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); … … 122 122 $categories = (array) get_terms($taxonomy, array('get' => 'all')); 123 123 } 124 124 125 if ( $checked_ontop ) { 126 // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) 127 $checked_categories = array(); 128 $keys = array_keys( $categories ); 125 $final_categories = array(); 126 $top_level = true; 129 127 130 foreach( $keys as $k ) { 131 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { 132 $checked_categories[] = $categories[$k]; 133 unset( $categories[$k] ); 128 while(count($categories) > 0){ 129 foreach( $args['selected_cats'] as $sk ) { 130 foreach( $categories as $catk => $cat ) { 131 if ($cat->term_id == $sk && $top_level && $cat->parent == 0) { 132 $final_categories[] = $cat; 133 unset( $categories[$catk] ); 134 } 135 else if ($cat->term_id == $sk) { 136 foreach( $final_categories as $fk ) { 137 if($fk->term_id == $cat->parent) { 138 $final_categories[] = $cat; 139 unset( $categories[$catk] ); 140 } 141 } 142 } 134 143 } 135 144 } 145 foreach( $categories as $catk => $cat ) { 146 if ($top_level && $cat->parent == 0) { 147 $final_categories[] = $cat; 148 unset( $categories[$catk] ); 149 } 150 else { 151 foreach( $final_categories as $fk ) { 152 if($fk->term_id == $cat->parent) { 153 $final_categories[] = $cat; 154 unset( $categories[$catk] ); 155 } 156 } 157 } 158 } 159 $top_level = false; 160 } 136 161 137 // Put checked cats on top 138 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); 139 } 140 // Then the rest of them 141 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); 162 echo call_user_func_array(array(&$walker, 'walk'), array($final_categories, 0, $args)); 142 163 } 143 164 144 165 /**