WordPress.org

Make WordPress Core

Ticket #15029: determine_ancestor_resource_type.15029.3.diff

File determine_ancestor_resource_type.15029.3.diff, 2.2 KB (added by filosofo, 8 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 resource 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 (
     2816                'taxonomy' == $resource_type ||
     2817                ( null === $resource_type && is_taxonomy_hierarchical( $object_type ) )
     2818        ) {
    28122819                $term = get_term($object_id, $object_type);
    28132820                while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
    28142821                        $ancestors[] = (int) $term->parent;
    28152822                        $term = get_term($term->parent, $object_type);
    28162823                }
    2817         } elseif ( null !== get_post_type_object( $object_type ) ) {
     2824        } elseif (
     2825                'post_type' == $resource_type ||
     2826                null === $resource_type && null !== get_post_type_object( $object_type )
     2827        ) {
    28182828                $object = get_post($object_id);
    28192829                if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) )
    28202830                        $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();