Ticket #16475: 16475_2.patch
File 16475_2.patch, 3.3 KB (added by , 13 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 $c hecked_categories = array();128 $keys = array_keys( $categories );125 // checked has three values: 0 means not checked at all, 1 means checked, and 2 means one ore more of its children are checked. 126 foreach( $categories as $cat ) { 127 $cat->checked = 0; 128 } 129 129 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] ); 130 $current_cat; 131 foreach( $args['selected_cats'] as $sc ) { 132 foreach( $categories as $cat ) { 133 if($cat->term_id == $sc) { 134 $current_cat = $cat; 134 135 } 135 136 } 136 137 137 // Put checked cats on top 138 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); 138 $current_cat->checked = 1; 139 140 while($current_cat->parent != 0) { 141 foreach( $categories as $cat ) { 142 if($cat->term_id == $current_cat->parent) { 143 $current_cat = $cat; 144 $current_cat->checked = 2; 145 } 146 } 147 } 139 148 } 140 // Then the rest of them 141 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); 149 150 $final_categories = array(); 151 152 foreach( $categories as $catk => $cat ) { 153 if ($cat->parent == 0 && $cat->checked == 1) { 154 $final_categories[] = $cat; 155 unset( $categories[$catk] ); 156 } 157 } 158 159 foreach( $categories as $catk => $cat ) { 160 if ($cat->parent == 0 && $cat->checked == 2) { 161 $final_categories[] = $cat; 162 unset( $categories[$catk] ); 163 } 164 } 165 166 foreach( $categories as $catk => $cat ) { 167 if ($cat->parent == 0) { 168 $final_categories[] = $cat; 169 unset( $categories[$catk] ); 170 } 171 } 172 173 foreach( $categories as $catk => $cat ) { 174 $final_categories[] = $cat; 175 unset( $categories[$catk]); 176 } 177 178 echo call_user_func_array(array(&$walker, 'walk'), array($final_categories, 0, $args)); 142 179 } 143 180 144 181 /**