WordPress.org

Make WordPress Core

Ticket #15581: 15581.diff

File 15581.diff, 3.1 KB (added by ryan, 2 years ago)

Refreshed

  • wp-includes/category.php

     
    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 
    223  
    224213/** 
    225214 * Sanitizes category data based on context. 
    226215 * 
     
    235224        return sanitize_term( $category, 'category', $context ); 
    236225} 
    237226 
    238  
    239227/** 
    240228 * Sanitizes data in single category key field. 
    241229 * 
     
    254242 
    255243/* Tags */ 
    256244 
    257  
    258245/** 
    259246 * Retrieves all post tags. 
    260247 * 
     
    277264        return $tags; 
    278265} 
    279266 
    280  
    281267/** 
    282268 * Retrieve post tag by tag ID or tag object. 
    283269 * 
     
    301287        return get_term( $tag, 'post_tag', $output, $filter ); 
    302288} 
    303289 
    304  
    305290/* Cache */ 
    306291 
    307  
    308292/** 
    309293 * Remove the category cache data based on ID. 
    310294 * 
     
    317301        clean_term_cache( $id, 'category' ); 
    318302} 
    319303 
    320  
    321304/** 
    322305 * Update category structure to old pre 2.3 from new taxonomy structure. 
    323306 * 
     
    355338        } 
    356339} 
    357340 
    358  
    359341?> 
  • wp-includes/taxonomy.php

     
    14951495} 
    14961496 
    14971497/** 
     1498 * Check if a term is an ancestor of another term. 
     1499 * 
     1500 * You can use either an id or the term object for both parameters. 
     1501 * 
     1502 * @since 3.4.0 
     1503 * 
     1504 * @param int|object $term1 ID or object to check if this is the parent term. 
     1505 * @param int|object $term2 The child term. 
     1506 * @param string $taxonomy Taxonomy name that $term1 and $term2 belong to. 
     1507 * @return bool Whether $term2 is child of $term1 
     1508 */ 
     1509function term_is_ancestor_of( $term1, $term2, $taxonomy ) { 
     1510        if ( ! isset( $term1->term_id ) ) 
     1511                $term1 = get_term( $term1, $taxonomy ); 
     1512        if ( ! isset( $term2->parent ) ) 
     1513                $term2 = get_term( $term2, $taxonomy ); 
     1514 
     1515        if ( empty( $term1->term_id ) || empty( $term2->parent ) ) 
     1516                return false; 
     1517        if ( $term2->parent == $term1->term_id ) 
     1518                return true; 
     1519 
     1520        return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy ); 
     1521} 
     1522 
     1523/** 
    14981524 * Sanitize Term all fields. 
    14991525 * 
    15001526 * Relies on sanitize_term_field() to sanitize the term. The difference is that 
  • wp-admin/includes/taxonomy.php

     
    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');