Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: list_cats

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 5 times in this file.

Line Code
395            * 'show_option_none', 'show_option_all', and various forms of the
396            * term name.
397            *
398            * @since 1.2.0
399            *
400            * @see wp_dropdown_categories()
401            *
402            * @param string $element Taxonomy element to list.
403            */
404           $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
405           $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n";
406      }
407
408      if ( ! empty( $categories ) ) {
409
410           if ( $r['show_option_all'] ) {
411
412                /** This filter is documented in wp-includes/category-template.php */
413                $show_option_all = apply_filters( 'list_cats', $r['show_option_all'] );
414                $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
415                $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
416           }
417
418           if ( $r['show_option_none'] ) {
419
420                /** This filter is documented in wp-includes/category-template.php */
421                $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
422                $selected = selected( $option_none_value, $r['selected'], false );
423                $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n";
424           }
425
426           if ( $r['hierarchical'] ) {
427                $depth = $r['depth'];  // Walk the full depth.
428           } else {
429                $depth = -1; // Flat.
430           }
 
Line Code
978       *
979       * @param string $output   Passed by reference. Used to append additional content.
980       * @param object $category Category data object.
981       * @param int    $depth    Depth of category in reference to parents. Default 0.
982       * @param array  $args     An array of arguments. @see wp_list_categories()
983       * @param int    $id       ID of the current category.
984       */
985      public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
986           /** This filter is documented in wp-includes/category-template.php */
987           $cat_name = apply_filters(
988                'list_cats',
989                esc_attr( $category->name ),
990                $category
991           );
992
993           // Don't generate an element if the category name is empty.
994           if ( ! $cat_name ) {
995                return;
996           }
 
Line Code
1136       * @param object $category Category data object.
1137       * @param int    $depth    Depth of category. Used for padding.
1138       * @param array  $args     Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
1139       *                         See {@see wp_dropdown_categories()}.
1140       */
1141      public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
1142           $pad = str_repeat('&nbsp;', $depth * 3);
1143
1144           /** This filter is documented in wp-includes/category-template.php */
1145           $cat_name = apply_filters( 'list_cats', $category->name, $category );
1146
1147           if ( ! isset( $args['value_field'] ) || ! isset( $category->{$args['value_field']} ) ) {
1148                $args['value_field'] = 'term_id';
1149           }
1150
1151           $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$args['value_field']} ) . "\"";
1152
1153           if ( $category->term_id == $args['selected'] )
1154                $output .= ' selected="selected"';