WordPress.org

Make WordPress Core

Changeset 7956


Ignore:
Timestamp:
05/19/2008 09:35:18 PM (10 years ago)
Author:
ryan
Message:

Put checked categories at the top of the checlist. Props mdawaffe. fixes #7000 for trunk

Location:
trunk
Files:
5 edited

Legend:

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

    r7907 r7956  
    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

    r7948 r7956  
    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>
  • trunk/wp-admin/includes/template.php

    r7930 r7956  
    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

    r7932 r7956  
    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    };
     
    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;
  • trunk/wp-includes/script-loader.php

    r7938 r7956  
    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:'),
Note: See TracChangeset for help on using the changeset viewer.