From 7f5a8e6680f18e41b85cdcca68f6a3063d70c0c4 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 29 Aug 2015 19:46:23 +0000 Subject: [PATCH] In `wp_list_categories()`, 'current_category' should accept an array of values. This allows the 'current-cat' or 'current-cat-parent' classes to be applied to more than one item in the list. Props vilkatis. Fixes #33565. Built from https://develop.svn.wordpress.org/trunk@33804 git-svn-id: http://core.svn.wordpress.org/trunk@33772 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 23 ++++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 797d07a20f..e621067e67 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -461,7 +461,8 @@ function wp_dropdown_categories( $args = '' ) { * Display or retrieve the HTML list of categories. * * @since 2.1.0 - * @since 4.4.0 Introduced the `hide_title_if_empty` argument. + * @since 4.4.0 Introduced the `hide_title_if_empty` argument. The `current_category` argument was modified to + * optionally accept an array of values. * * @param string|array $args { * Array of optional arguments. @@ -488,7 +489,8 @@ function wp_dropdown_categories( $args = '' ) { * @type array|string $exclude_tree Array or comma/space-separated string of term IDs to exclude, along * with their descendants. See {@link get_terms()}. Default empty string. * @type bool|int $echo True to echo markup, false to return it. Default 1. - * @type int $current_category Category that should get the 'current-cat' class. Default 0. + * @type int|array $current_category ID of category, or array of IDs of categories, that should get the + * 'current-cat' class. Default 0. * @type bool $hierarchical Whether to include terms that have non-empty descendants. * See {@link get_terms()}. Default true. * @type string $title_li Text to use for the list title `
  • ` element. Pass an empty string @@ -1121,11 +1123,18 @@ class Walker_Category extends Walker { ); if ( ! empty( $args['current_category'] ) ) { - $_current_category = get_term( $args['current_category'], $category->taxonomy ); - if ( $category->term_id == $args['current_category'] ) { - $css_classes[] = 'current-cat'; - } elseif ( $category->term_id == $_current_category->parent ) { - $css_classes[] = 'current-cat-parent'; + // 'current_category' can be an array, so we use `get_terms()`. + $_current_terms = get_terms( $category->taxonomy, array( + 'include' => $args['current_category'], + 'hide_empty' => false, + ) ); + + foreach ( $_current_terms as $_current_term ) { + if ( $category->term_id == $_current_term->term_id ) { + $css_classes[] = 'current-cat'; + } elseif ( $category->term_id == $_current_term->parent ) { + $css_classes[] = 'current-cat-parent'; + } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index ed4559ef72..11ffc69989 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-33803'; +$wp_version = '4.4-alpha-33804'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.