wp/wp-includes/class-walker-category-dropdown.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 18 be944660c56a
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    33 	 * @todo Decouple this
    33 	 * @todo Decouple this
    34 	 * @var array
    34 	 * @var array
    35 	 *
    35 	 *
    36 	 * @see Walker::$db_fields
    36 	 * @see Walker::$db_fields
    37 	 */
    37 	 */
    38 	public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
    38 	public $db_fields = array(
       
    39 		'parent' => 'parent',
       
    40 		'id'     => 'term_id',
       
    41 	);
    39 
    42 
    40 	/**
    43 	/**
    41 	 * Starts the element output.
    44 	 * Starts the element output.
    42 	 *
    45 	 *
    43 	 * @since 2.1.0
    46 	 * @since 2.1.0
    50 	 * @param array  $args     Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
    53 	 * @param array  $args     Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
    51 	 *                         See wp_dropdown_categories().
    54 	 *                         See wp_dropdown_categories().
    52 	 * @param int    $id       Optional. ID of the current category. Default 0 (unused).
    55 	 * @param int    $id       Optional. ID of the current category. Default 0 (unused).
    53 	 */
    56 	 */
    54 	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
    57 	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
    55 		$pad = str_repeat(' ', $depth * 3);
    58 		$pad = str_repeat( ' ', $depth * 3 );
    56 
    59 
    57 		/** This filter is documented in wp-includes/category-template.php */
    60 		/** This filter is documented in wp-includes/category-template.php */
    58 		$cat_name = apply_filters( 'list_cats', $category->name, $category );
    61 		$cat_name = apply_filters( 'list_cats', $category->name, $category );
    59 
    62 
    60 		if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {
    63 		if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {
    61 			$value_field = $args['value_field'];
    64 			$value_field = $args['value_field'];
    62 		} else {
    65 		} else {
    63 			$value_field = 'term_id';
    66 			$value_field = 'term_id';
    64 		}
    67 		}
    65 
    68 
    66 		$output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\"";
    69 		$output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . '"';
    67 
    70 
    68 		// Type-juggling causes false matches, so we force everything to a string.
    71 		// Type-juggling causes false matches, so we force everything to a string.
    69 		if ( (string) $category->{$value_field} === (string) $args['selected'] )
    72 		if ( (string) $category->{$value_field} === (string) $args['selected'] ) {
    70 			$output .= ' selected="selected"';
    73 			$output .= ' selected="selected"';
       
    74 		}
    71 		$output .= '>';
    75 		$output .= '>';
    72 		$output .= $pad.$cat_name;
    76 		$output .= $pad . $cat_name;
    73 		if ( $args['show_count'] )
    77 		if ( $args['show_count'] ) {
    74 			$output .= '&nbsp;&nbsp;('. number_format_i18n( $category->count ) .')';
    78 			$output .= '&nbsp;&nbsp;(' . number_format_i18n( $category->count ) . ')';
       
    79 		}
    75 		$output .= "</option>\n";
    80 		$output .= "</option>\n";
    76 	}
    81 	}
    77 }
    82 }