cat_is_ancestor_of(). fixes #3387
git-svn-id: http://svn.automattic.com/wordpress/trunk@4525 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
814a2b0c1c
commit
889ff09208
|
@ -108,7 +108,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 ) || $category_parent == $cat_ID )
|
||||
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) )
|
||||
|
|
|
@ -225,6 +225,21 @@ function get_cat_name($cat_id) {
|
|||
return $category->cat_name;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue