[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Taxonomy API: Walker_CategoryDropdown class 4 * 5 * @package WordPress 6 * @subpackage Template 7 * @since 4.4.0 8 */ 9 10 /** 11 * Core class used to create an HTML dropdown list of Categories. 12 * 13 * @since 2.1.0 14 * 15 * @see Walker 16 */ 17 class Walker_CategoryDropdown extends Walker { 18 19 /** 20 * What the class handles. 21 * 22 * @since 2.1.0 23 * @var string 24 * 25 * @see Walker::$tree_type 26 */ 27 public $tree_type = 'category'; 28 29 /** 30 * Database fields to use. 31 * 32 * @since 2.1.0 33 * @todo Decouple this 34 * @var string[] 35 * 36 * @see Walker::$db_fields 37 */ 38 public $db_fields = array( 39 'parent' => 'parent', 40 'id' => 'term_id', 41 ); 42 43 /** 44 * Starts the element output. 45 * 46 * @since 2.1.0 47 * @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id` 48 * to match parent class for PHP 8 named parameter support. 49 * 50 * @see Walker::start_el() 51 * 52 * @param string $output Used to append additional content (passed by reference). 53 * @param WP_Term $data_object Category data object. 54 * @param int $depth Depth of category. Used for padding. 55 * @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist. 56 * See wp_dropdown_categories(). 57 * @param int $current_object_id Optional. ID of the current category. Default 0. 58 */ 59 public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) { 60 // Restores the more descriptive, specific name for use within this method. 61 $category = $data_object; 62 $pad = str_repeat( ' ', $depth * 3 ); 63 64 /** This filter is documented in wp-includes/category-template.php */ 65 $cat_name = apply_filters( 'list_cats', $category->name, $category ); 66 67 if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) { 68 $value_field = $args['value_field']; 69 } else { 70 $value_field = 'term_id'; 71 } 72 73 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . '"'; 74 75 // Type-juggling causes false matches, so we force everything to a string. 76 if ( (string) $category->{$value_field} === (string) $args['selected'] ) { 77 $output .= ' selected="selected"'; 78 } 79 $output .= '>'; 80 $output .= $pad . $cat_name; 81 if ( $args['show_count'] ) { 82 $output .= ' (' . number_format_i18n( $category->count ) . ')'; 83 } 84 $output .= "</option>\n"; 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |