WordPress.org

Make WordPress Core


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.