Make WordPress Core


Ignore:
Timestamp:
10/13/2009 10:02:42 AM (15 years ago)
Author:
azaozz
Message:

Merge post.js with page.js and slug.js, optimize categories and tags JS, standardize postboxes IDs and JS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r12016 r12022  
    488488 * @param unknown_type $popular_cats
    489489 */
    490 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null ) {
     490function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
    491491    if ( empty($walker) || !is_a($walker, 'Walker') )
    492492        $walker = new Walker_Category_Checklist;
     
    516516    }
    517517
    518     // 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)
    519     $checked_categories = array();
    520     $keys = array_keys( $categories );
    521 
    522     foreach( $keys as $k ) {
    523         if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
    524             $checked_categories[] = $categories[$k];
    525             unset( $categories[$k] );
     518    if ( $checked_ontop ) {
     519        // 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)
     520        $checked_categories = array();
     521        $keys = array_keys( $categories );
     522
     523        foreach( $keys as $k ) {
     524            if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
     525                $checked_categories[] = $categories[$k];
     526                unset( $categories[$k] );
     527            }
    526528        }
    527     }
    528 
    529     // Put checked cats on top
    530     echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
     529
     530        // Put checked cats on top
     531        echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
     532    }
    531533    // Then the rest of them
    532534    echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
     
    546548function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
    547549    global $post_ID;
     550
    548551    if ( $post_ID )
    549552        $checked_categories = wp_get_post_categories($post_ID);
    550553    else
    551554        $checked_categories = array();
     555
    552556    $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
    553557
     
    558562            continue;
    559563        $id = "popular-category-$category->term_id";
     564        $checked = in_array( $category->term_id, $checked_categories ) ? 'checked="checked"' : '';
    560565        ?>
    561566
    562567        <li id="<?php echo $id; ?>" class="popular-category">
    563568            <label class="selectit">
    564             <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
     569            <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $category->term_id; ?>" />
    565570                <?php echo esc_html( apply_filters( 'the_category', $category->name ) ); ?>
    566571            </label>
     
    30593064    // Hide slug boxes by default
    30603065    if ( empty($hidden[0]) ) {
    3061         if ( 'page' == $page )
    3062             $hidden = array('pageslugdiv');
    3063         elseif ( 'post' == $page )
    3064             $hidden = array('slugdiv');
     3066        $hidden = array('slugdiv');
    30653067    }
    30663068
Note: See TracChangeset for help on using the changeset viewer.