WordPress.org

Make WordPress Core

Ticket #15029: determine_ancestor_resource_type.15029.diff

File determine_ancestor_resource_type.15029.diff, 2.1 KB (added by filosofo, 4 years ago)
  • wp-includes/taxonomy.php

     
    27952795/** 
    27962796 * Get an array of ancestor IDs for a given object. 
    27972797 * 
     2798 * @since 3.0.0 
     2799 * 
    27982800 * @param int $object_id The ID of the object 
    27992801 * @param string $object_type The type of object for which we'll be retrieving ancestors. 
     2802 * @param string $resource_type. (Optional).  Forces the resorce type used (post_type or taxonomy) 
     2803 *      to overcome ambiguities. 
    28002804 * @return array of ancestors from lowest to highest in the hierarchy. 
    28012805 */ 
    2802 function get_ancestors($object_id = 0, $object_type = '') { 
     2806function get_ancestors($object_id = 0, $object_type = '', $resource_type = null ) { 
    28032807        $object_id = (int) $object_id; 
    28042808  
    28052809        $ancestors = array(); 
     
    28082812                return apply_filters('get_ancestors', $ancestors, $object_id, $object_type); 
    28092813        } 
    28102814                 
    2811         if ( is_taxonomy_hierarchical( $object_type ) ) { 
     2815        if ( 'taxonomy' == $resource_type || is_taxonomy_hierarchical( $object_type ) ) { 
    28122816                $term = get_term($object_id, $object_type); 
    28132817                while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { 
    28142818                        $ancestors[] = (int) $term->parent; 
    28152819                        $term = get_term($term->parent, $object_type); 
    28162820                } 
    2817         } elseif ( null !== get_post_type_object( $object_type ) ) { 
     2821        } elseif ( 'post_type' == $resource_type || null !== get_post_type_object( $object_type ) ) { 
    28182822                $object = get_post($object_id); 
    28192823                if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) )  
    28202824                        $ancestors = $object->ancestors; 
  • wp-admin/admin-ajax.php

     
    560560 
    561561        $level = 0; 
    562562        if ( is_taxonomy_hierarchical($taxonomy) ) { 
    563                 $level = count( get_ancestors( $tag->term_id, $taxonomy ) ); 
     563                $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) ); 
    564564                ob_start(); 
    565565                $wp_list_table->single_row( $tag, $level ); 
    566566                $noparents = ob_get_clean();