mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Put checked categories at the top of the checlist. Props mdawaffe. fixes #7000 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@7956 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3ce00adc38
commit
01acf41355
@ -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(
|
||||
|
@ -260,7 +260,7 @@ function post_categories_meta_box($post) {
|
||||
|
||||
<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>
|
||||
<?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";
|
||||
?>
|
||||
|
||||
|
@ -120,8 +120,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 ) {
|
||||
@ -151,7 +152,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;
|
||||
} );
|
||||
|
@ -145,7 +145,7 @@ class WP_Scripts {
|
||||
'save' => __('Save'),
|
||||
'cancel' => __('Cancel'),
|
||||
) );
|
||||
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080422' );
|
||||
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' );
|
||||
$this->localize( 'post', 'postL10n', array(
|
||||
'tagsUsed' => __('Tags used on this post:'),
|
||||
'add' => attribute_escape(__('Add')),
|
||||
|
Loading…
Reference in New Issue
Block a user