WordPress.org

Make WordPress Core

Ticket #17069: 17069.patch

File 17069.patch, 2.7 KB (added by SergeyBiryukov, 7 years ago)
  • wp-includes/category-template.php

     
    3636 * @param bool $link Optional, default is false. Whether to format with link.
    3737 * @param string $separator Optional, default is '/'. How to separate categories.
    3838 * @param bool $nicename Optional, default is false. Whether to use nice name for display.
    39  * @param array $visited Optional. Already linked to categories to prevent duplicates.
     39 * @param array $deprecated Not used.
    4040 * @return string
    4141 */
    42 function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
     42function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $deprecated = array() ) {
     43        return get_term_parents( $id, 'category', $link, $separator, $nicename );
     44}
     45
     46/**
     47 * Retrieve term parents with separator.
     48 *
     49 * @since 3.3.0
     50 *
     51 * @param int $id Term ID.
     52 * @param string $taxonomy Taxonomy name.
     53 * @param bool $link Optional, default is false. Whether to format with link.
     54 * @param string $separator Optional, default is '/'. How to separate categories.
     55 * @param bool $nicename Optional, default is false. Whether to use nice name for display.
     56 * @param array $deprecated Not used.
     57 * @return string
     58 */
     59function get_term_parents( $id, $taxonomy, $link = false, $separator = '/', $nicename = false, $deprecated = array() ) {
     60        $term = &get_term( $id, $taxonomy );
     61        if ( is_wp_error( $term ) )
     62                return $term;
     63
    4364        $chain = '';
    44         $parent = &get_category( $id );
    45         if ( is_wp_error( $parent ) )
    46                 return $parent;
    4765
    48         if ( $nicename )
    49                 $name = $parent->slug;
    50         else
    51                 $name = $parent->name;
     66        $parents = get_ancestors( $id, $taxonomy );
     67        array_unshift( $parents, $id );
    5268
    53         if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
    54                 $visited[] = $parent->parent;
    55                 $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
     69        foreach ( array_reverse( $parents ) as $term_id ) {
     70                $term = &get_term( $term_id, $taxonomy );
     71
     72                $name = ( $nicename ) ? $term->slug : $term->name;
     73                if ( $link )
     74                        $chain .= '<a href="' . get_term_link( $term->slug, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $term->name ) ) . '">' . $name . '</a>' . $separator;
     75                else
     76                        $chain .= $name.$separator;
    5677        }
    5778
    58         if ( $link )
    59                 $chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
    60         else
    61                 $chain .= $name.$separator;
    6279        return $chain;
    6380}
    6481