WordPress.org

Make WordPress Core

Changeset 19678


Ignore:
Timestamp:
01/04/2012 10:44:19 PM (10 years ago)
Author:
ryan
Message:

Introduce term_is_ancestor_of(). Finish taxonomy support for wp_insert_category(). Props garyc40. fixes #15581

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/taxonomy.php

    r19593 r19678  
    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
  • trunk/wp-includes/category.php

    r16412 r19678  
    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 ) );
    221 }
    222 
     210    return term_is_ancestor_of( $cat1, $cat2, 'category' );
     211}
    223212
    224213/**
     
    235224    return sanitize_term( $category, 'category', $context );
    236225}
    237 
    238226
    239227/**
     
    255243/* Tags */
    256244
    257 
    258245/**
    259246 * Retrieves all post tags.
     
    277264    return $tags;
    278265}
    279 
    280266
    281267/**
     
    302288}
    303289
    304 
    305290/* Cache */
    306 
    307291
    308292/**
     
    317301    clean_term_cache( $id, 'category' );
    318302}
    319 
    320303
    321304/**
     
    356339}
    357340
    358 
    359341?>
  • trunk/wp-includes/taxonomy.php

    r19600 r19678  
    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 *
Note: See TracChangeset for help on using the changeset viewer.