[wp-cvs] wordpress/wp-admin admin-functions.php,1.30,1.31
Jason Verber
jverber at users.sourceforge.net
Wed Jun 16 16:40:49 UTC 2004
Update of /cvsroot/cafelog/wordpress/wp-admin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28461/wp-admin
Modified Files:
admin-functions.php
Log Message:
Fix for bug #0000048: nested categories now display correctly in admin regardless of the order of their IDs
Index: admin-functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/admin-functions.php,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** admin-functions.php 15 Jun 2004 23:24:35 -0000 1.30
--- admin-functions.php 16 Jun 2004 16:40:40 -0000 1.31
***************
*** 19,23 ****
}
! function get_nested_categories($default = 0) {
global $post_ID, $mode, $wpdb;
--- 19,57 ----
}
! function return_categories_list( $parent = 0, $sortbyname = FALSE )
! {
! /*
! * This function returns an list of all categories
! * that have $parent as their parent
! * if no parent is specified we will assume top level caegories
! * are required.
! */
! global $wpdb;
!
! // select sort order
! $sort = "cat_id";
! if( TRUE == $sortbyname )
! {
! $sort = "cat_name";
! }
!
! // First query the database
! $cats_tmp = $wpdb->get_results("SELECT cat_id FROM $wpdb->categories WHERE category_parent = $parent ORDER BY $sort");
!
! // Now strip this down to a simple array of IDs
! $cats = array();
! if( count($cats_tmp) > 0 )
! {
! foreach( $cats_tmp as $cat )
! {
! $cats[] = $cat->cat_id;
! }
! }
!
! // Return the list of categories
! return $cats;
! }
!
! function get_nested_categories($default = 0, $parent = 0) {
global $post_ID, $mode, $wpdb;
***************
*** 25,48 ****
$checked_categories = $wpdb->get_col("
SELECT category_id
! FROM $wpdb->categories, $wpdb->post2cat
WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
");
} else {
$checked_categories[] = $default;
}
! $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY category_parent DESC, cat_name ASC");
$result = array();
! foreach($categories as $category) {
! $array_category = get_object_vars($category);
! $me = 0 + $category->cat_ID;
! $parent = 0 + $category->category_parent;
! if (isset($result[$me])) $array_category['children'] = $result[$me];
! $array_category['checked'] = in_array($category->cat_ID, $checked_categories);
! $array_category['cat_name'] = stripslashes($category->cat_name);
! $result[$parent][] = $array_category;
}
! return $result[0];
}
--- 59,88 ----
$checked_categories = $wpdb->get_col("
SELECT category_id
! FROM $wpdb->categories, $wpdb->post2cat
WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
");
+
+ if(count($checked_categories) == 0)
+ {
+ // No selected categories, strange
+ $checked_categories[] = $default;
+ }
+
} else {
$checked_categories[] = $default;
}
! $cats = return_categories_list($parent, TRUE);
$result = array();
!
! foreach($cats as $cat)
! {
! $result[$cat]['children'] = get_nested_categories($default, $cat);
! $result[$cat]['cat_ID'] = $cat;
! $result[$cat]['checked'] = in_array($cat, $checked_categories);
! $result[$cat]['cat_name'] = stripslashes(get_the_category_by_ID($cat));
}
! return $result;
}
More information about the cvs
mailing list