summaryrefslogtreecommitdiffstats
path: root/wp-admin
diff options
context:
space:
mode:
authorryan <ryan@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-05-19 22:17:49 +0000
committerryan <ryan@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-05-19 22:17:49 +0000
commitbb785c8b708131cf80d8e9b8215f41a5196bd09b (patch)
treee1d65e7ec4f97a2f11ff8abb5b69bab565207821 /wp-admin
parent80788a01b4ded035ff65ce65def9ad6f57822c89 (diff)
downloadwordpress-mu-bb785c8b708131cf80d8e9b8215f41a5196bd09b.tar.gz
wordpress-mu-bb785c8b708131cf80d8e9b8215f41a5196bd09b.tar.xz
wordpress-mu-bb785c8b708131cf80d8e9b8215f41a5196bd09b.zip
Put checked categories at the top of the checklist. Props mdawaffe. see #WP7000
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1299 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin')
-rw-r--r--wp-admin/admin-ajax.php5
-rw-r--r--wp-admin/edit-form-advanced.php2
-rw-r--r--wp-admin/includes/template.php34
-rw-r--r--wp-admin/js/post.js6
4 files changed, 34 insertions, 13 deletions
diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index 4e34333..663880e 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -150,6 +150,9 @@ case 'add-category' : // On the Fly
$parent = 0;
$post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
$checked_categories = array_map( 'absint', (array) $post_category );
+ $popular_ids = isset( $_POST['popular_ids'] ) ?
+ array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) :
+ false;
$x = new WP_Ajax_Response();
foreach ( $names as $cat_name ) {
@@ -163,7 +166,7 @@ case 'add-category' : // On the Fly
continue;
$category = get_category( $cat_id );
ob_start();
- wp_category_checklist( 0, $cat_id, $checked_categories );
+ wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids );
$data = ob_get_contents();
ob_end_clean();
$x->add( array(
diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index e12917d..7d1ff7d 100644
--- a/wp-admin/edit-form-advanced.php
+++ b/wp-admin/edit-form-advanced.php
@@ -241,7 +241,7 @@ endif; ?>
<div id="categories-all" class="ui-tabs-panel">
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
- <?php wp_category_checklist($post_ID) ?>
+ <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
</ul>
</div>
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php
index db80bf8..19f11f6 100644
--- a/wp-admin/includes/template.php
+++ b/wp-admin/includes/template.php
@@ -148,19 +148,24 @@ class Walker_Category_Checklist extends Walker {
}
}
-function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) {
+function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false ) {
$walker = new Walker_Category_Checklist;
$descendants_and_self = (int) $descendants_and_self;
$args = array();
- if ( $post_id )
+ if ( is_array( $selected_cats ) )
+ $args['selected_cats'] = $selected_cats;
+ elseif ( $post_id )
$args['selected_cats'] = wp_get_post_categories($post_id);
else
$args['selected_cats'] = array();
- if ( is_array( $selected_cats ) )
- $args['selected_cats'] = $selected_cats;
- $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
+
+ if ( is_array( $popular_cats ) )
+ $args['popular_cats'] = $popular_cats;
+ else
+ $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
+
if ( $descendants_and_self ) {
$categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
$self = get_category( $descendants_and_self );
@@ -169,13 +174,22 @@ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $select
$categories = get_categories('get=all');
}
- $args = array($categories, 0, $args);
- $output = call_user_func_array(array(&$walker, 'walk'), $args);
+ // 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)
+ $checked_categories = array();
+ for ( $i = 0; isset($categories[$i]); $i++ ) {
+ if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) {
+ $checked_categories[] = $categories[$i];
+ unset($categories[$i]);
+ }
+ }
- echo $output;
+ // Put checked cats on top
+ echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
+ // Then the rest of them
+ echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
}
-function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
+function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
global $post_ID;
if ( $post_ID )
$checked_categories = wp_get_post_categories($post_ID);
@@ -186,6 +200,8 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
$popular_ids = array();
foreach ( (array) $categories as $category ) {
$popular_ids[] = $category->term_id;
+ if ( !$echo ) // hack for AJAX use
+ continue;
$id = "popular-category-$category->term_id";
?>
diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js
index c938af3..9b3313c 100644
--- a/wp-admin/js/post.js
+++ b/wp-admin/js/post.js
@@ -118,8 +118,9 @@ jQuery(document).ready( function() {
jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
noSyncChecks = false;
};
+ var popularCats = jQuery('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
var catAddBefore = function( s ) {
- s.data += '&' + jQuery( '#categorychecklist :checked' ).serialize();
+ s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
return s;
};
var catAddAfter = function( r, s ) {
@@ -149,7 +150,8 @@ jQuery(document).ready( function() {
} );
jQuery('#category-add-toggle').click( function() {
jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
- categoryTabs.tabsClick( 1 );
+ // categoryTabs.tabs( 'select', '#categories-all' ); // this is broken (in the UI beta?)
+ categoryTabs.find( 'a[href="#categories-all"]' ).click();
jQuery('#newcat').focus();
return false;
} );