Make WordPress Core

Ticket #7000: 7000.diff

File 7000.diff, 5.9 KB (added by mdawaffe, 17 years ago)
  • wp-includes/script-loader.php

     
    145145                                'save' => __('Save'),
    146146                                'cancel' => __('Cancel'),
    147147                        ) );
    148                         $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080422' );
     148                        $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' );
    149149                        $this->localize( 'post', 'postL10n', array(
    150150                                'tagsUsed' =>  __('Tags used on this post:'),
    151151                                'add' => attribute_escape(__('Add')),
  • wp-admin/admin-ajax.php

     
    150150                $parent = 0;
    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();
    155158        foreach ( $names as $cat_name ) {
     
    163166                        continue;
    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();
    169172                $x->add( array(
  • wp-admin/includes/template.php

     
    148148        }
    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;
    154154
    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" );
    166171                $self = get_category( $descendants_and_self );
     
    169174                $categories = get_categories('get=all');
    170175        }
    171176
    172         $args = array($categories, 0, $args);
    173         $output = call_user_func_array(array(&$walker, 'walk'), $args);
     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        }
    174185
    175         echo $output;
     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));
    176190}
    177191
    178 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
     192function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
    179193        global $post_ID;
    180194        if ( $post_ID )
    181195                $checked_categories = wp_get_post_categories($post_ID);
     
    186200        $popular_ids = array();
    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                ?>
    191207
  • wp-admin/js/post.js

     
    120120                jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
    121121                noSyncChecks = false;
    122122        };
     123        var popularCats = jQuery('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
    123124        var catAddBefore = function( s ) {
    124                 s.data += '&' + jQuery( '#categorychecklist :checked' ).serialize();
     125                s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
    125126                return s;
    126127        };
    127128        var catAddAfter = function( r, s ) {
     
    151152        } );
    152153        jQuery('#category-add-toggle').click( function() {
    153154                jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
    154                 categoryTabs.tabsClick( 1 );
     155                // categoryTabs.tabs( 'select', '#categories-all' ); // this is broken (in the UI beta?)
     156                categoryTabs.find( 'a[href="#categories-all"]' ).click();
    155157                jQuery('#newcat').focus();
    156158                return false;
    157159        } );
  • wp-admin/edit-form-advanced.php

     
    260260
    261261<div id="categories-all" class="ui-tabs-panel">
    262262        <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    263                 <?php wp_category_checklist($post->ID) ?>
     263                <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
    264264        </ul>
    265265</div>
    266266<?php