summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wp-admin/admin-db.php2
-rw-r--r--wp-includes/category.php15
2 files changed, 16 insertions, 1 deletions
diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php
index 7a0577c..f5705f5 100644
--- a/wp-admin/admin-db.php
+++ b/wp-admin/admin-db.php
@@ -112,7 +112,7 @@ function wp_insert_category($catarr) {
$category_description = apply_filters('pre_category_description', $category_description);
$category_parent = (int) $category_parent;
- if ( empty($category_parent) || !get_category( $category_parent ) )
+ if ( empty($category_parent) || !get_category( $category_parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $category_parent) ) )
$category_parent = 0;
if ( isset($posts_private) )
diff --git a/wp-includes/category.php b/wp-includes/category.php
index 76382ad..1d3f6e4 100644
--- a/wp-includes/category.php
+++ b/wp-includes/category.php
@@ -232,4 +232,19 @@ function &_get_cat_children($category_id, $categories) {
return $category_list;
}
+function cat_is_ancestor_of($cat1, $cat2) {
+ if ( is_int($cat1) )
+ $cat1 = & get_category($cat1);
+ if ( is_int($cat2) )
+ $cat2 = & get_category($cat2);
+
+ if ( !$cat1->cat_ID || !$cat2->category_parent )
+ return false;
+
+ if ( $cat2->category_parent == $cat1->cat_ID )
+ return true;
+
+ return cat_is_ancestor_of($cat1, get_category($cat2->parent_category));
+}
+
?>