WordPress.org

Make WordPress Core

Ticket #15581: garyc40-15581.patch

File garyc40-15581.patch, 2.5 KB (added by garyc40, 7 years ago)

there's a patch for that

  • wp-admin/includes/taxonomy.php

    diff --git wp-admin/includes/taxonomy.php wp-admin/includes/taxonomy.php
    index 12e231a..d44de2f 100644
    function wp_insert_category($catarr, $wp_error = false) { 
    117117        if ( $parent < 0 )
    118118                $parent = 0;
    119119
    120         if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
     120        if ( empty( $parent ) || ! term_exists( $parent, $taxonomy ) || ( $cat_ID && term_is_ancestor_of( $cat_ID, $parent, $taxonomy ) ) )
    121121                $parent = 0;
    122122
    123123        $args = compact('name', 'slug', 'parent', 'description');
  • wp-includes/category.php

    diff --git wp-includes/category.php wp-includes/category.php
    index 4d02277..819d1f8 100644
    function get_cat_name( $cat_id ) { 
    207207 * @return bool Whether $cat2 is child of $cat1
    208208 */
    209209function cat_is_ancestor_of( $cat1, $cat2 ) {
    210         if ( ! isset($cat1->term_id) )
    211                 $cat1 = &get_category( $cat1 );
    212         if ( ! isset($cat2->parent) )
    213                 $cat2 = &get_category( $cat2 );
    214 
    215         if ( empty($cat1->term_id) || empty($cat2->parent) )
    216                 return false;
    217         if ( $cat2->parent == $cat1->term_id )
    218                 return true;
    219 
    220         return cat_is_ancestor_of( $cat1, get_category( $cat2->parent ) );
     210        return term_is_ancestor_of( $cat1, $cat2, 'category' );
    221211}
    222212
    223213
  • wp-includes/taxonomy.php

    diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
    index 72d387a..b3fae51 100644
    function term_exists($term, $taxonomy = '', $parent = 0) { 
    14311431}
    14321432
    14331433/**
     1434 * Check if a term is an ancestor of another term.
     1435 *
     1436 * You can use either an id or the term object for both parameters. If you
     1437 * use an integer the term will be retrieved.
     1438 *
     1439 * @since 3.2.0
     1440 *
     1441 * @param int|object $term1 ID or object to check if this is the parent term.
     1442 * @param int|object $term2 The child term.
     1443 * @param string $taxonomy Taxonomy name that $term1 and $term2 belong to.
     1444 * @return bool Whether $term2 is child of $term1
     1445 */
     1446function term_is_ancestor_of( $term1, $term2, $taxonomy ) {
     1447        if ( ! isset($term1->term_id) )
     1448                $term1 = &get_term( $term1, $taxonomy );
     1449        if ( ! isset($term2->parent) )
     1450                $term2 = &get_term( $term2, $taxonomy );
     1451
     1452        if ( empty($term1->term_id) || empty($term2->parent) )
     1453                return false;
     1454        if ( $term2->parent == $term1->term_id )
     1455                return true;
     1456
     1457        return term_is_ancestor_of( $cat1, get_term( $cat2->parent, $taxonomy ) );
     1458}
     1459
     1460/**
    14341461 * Sanitize Term all fields.
    14351462 *
    14361463 * Relys on sanitize_term_field() to sanitize the term. The difference is that