Changeset 1299

Show
Ignore:
Timestamp:
05/19/08 22:17:49 (7 months ago)
Author:
ryan
Message:

Put checked categories at the top of the checklist. Props mdawaffe. see #WP7000

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/admin-ajax.php

    r1260 r1299  
    151151        $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array(); 
    152152        $checked_categories = array_map( 'absint', (array) $post_category ); 
     153        $popular_ids = isset( $_POST['popular_ids'] ) ? 
     154                        array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) : 
     155                        false; 
    153156 
    154157        $x = new WP_Ajax_Response(); 
     
    164167                $category = get_category( $cat_id ); 
    165168                ob_start(); 
    166                         wp_category_checklist( 0, $cat_id, $checked_categories ); 
     169                        wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids ); 
    167170                $data = ob_get_contents(); 
    168171                ob_end_clean(); 
  • trunk/wp-admin/edit-form-advanced.php

    r1260 r1299  
    242242<div id="categories-all" class="ui-tabs-panel"> 
    243243        <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 
    244                 <?php wp_category_checklist($post_ID) ?> 
     244                <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?> 
    245245        </ul> 
    246246</div> 
  • trunk/wp-admin/includes/template.php

    r1260 r1299  
    149149} 
    150150 
    151 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) { 
     151function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false ) { 
    152152        $walker = new Walker_Category_Checklist; 
    153153        $descendants_and_self = (int) $descendants_and_self; 
     
    155155        $args = array(); 
    156156         
    157         if ( $post_id ) 
     157        if ( is_array( $selected_cats ) ) 
     158                $args['selected_cats'] = $selected_cats; 
     159        elseif ( $post_id ) 
    158160                $args['selected_cats'] = wp_get_post_categories($post_id); 
    159161        else 
    160162                $args['selected_cats'] = array(); 
    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 ) ); 
     163 
     164        if ( is_array( $popular_cats ) ) 
     165                $args['popular_cats'] = $popular_cats; 
     166        else 
     167                $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); 
     168 
    164169        if ( $descendants_and_self ) { 
    165170                $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" ); 
     
    170175        } 
    171176 
    172         $args = array($categories, 0, $args); 
    173         $output = call_user_func_array(array(&$walker, 'walk'), $args); 
    174  
    175         echo $output; 
    176 
    177  
    178 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) { 
     177        // 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) 
     178        $checked_categories = array(); 
     179        for ( $i = 0; isset($categories[$i]); $i++ ) { 
     180                if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) { 
     181                        $checked_categories[] = $categories[$i]; 
     182                        unset($categories[$i]); 
     183                } 
     184        } 
     185 
     186        // Put checked cats on top 
     187        echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); 
     188        // Then the rest of them 
     189        echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); 
     190
     191 
     192function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { 
    179193        global $post_ID; 
    180194        if ( $post_ID ) 
     
    187201        foreach ( (array) $categories as $category ) { 
    188202                $popular_ids[] = $category->term_id; 
     203                if ( !$echo ) // hack for AJAX use 
     204                        continue; 
    189205                $id = "popular-category-$category->term_id"; 
    190206                ?> 
  • trunk/wp-admin/js/post.js

    r1260 r1299  
    119119                noSyncChecks = false; 
    120120        }; 
     121        var popularCats = jQuery('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(','); 
    121122        var catAddBefore = function( s ) { 
    122                 s.data += '&' + jQuery( '#categorychecklist :checked' ).serialize(); 
     123                s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize(); 
    123124                return s; 
    124125        }; 
     
    150151        jQuery('#category-add-toggle').click( function() { 
    151152                jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' ); 
    152                 categoryTabs.tabsClick( 1 ); 
     153                // categoryTabs.tabs( 'select', '#categories-all' ); // this is broken (in the UI beta?) 
     154                categoryTabs.find( 'a[href="#categories-all"]' ).click(); 
    153155                jQuery('#newcat').focus(); 
    154156                return false; 
  • trunk/wp-includes/script-loader.php

    r1266 r1299  
    145145                                'cancel' => __('Cancel'), 
    146146                        ) ); 
    147                         $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080422' ); 
     147                        $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' ); 
    148148                        $this->localize( 'post', 'postL10n', array( 
    149149                                'tagsUsed' =>  __('Tags used on this post:'),