WordPress.org

Make WordPress Core

Ticket #19780: 19780.3.diff

File 19780.3.diff, 8.7 KB (added by lkwdwrd, 5 years ago)
  • wp-admin/admin-header.php

     
    9393?>
    9494</head>
    9595<body class="wp-admin wp-core-ui no-js <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>">
     96<?php wp_dropdown_terms( array() ); ?>
    9697<script type="text/javascript">
    9798        document.body.className = document.body.className.replace('no-js','js');
    9899</script>
  • wp-includes/category-template.php

     
    263263}
    264264
    265265/**
    266  * Display or retrieve the HTML dropdown list of categories.
     266 * Display or retrieve the HTML dropdown list of terms.
    267267 *
    268268 * The list of arguments is below:
    269  *     'show_option_all' (string) - Text to display for showing all categories.
    270  *     'show_option_none' (string) - Text to display for showing no categories.
    271  *     'orderby' (string) default is 'ID' - What column to use for ordering the
    272  * categories.
    273  *     'order' (string) default is 'ASC' - What direction to order categories.
    274  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
    275  * in the category.
    276  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
     269 *     'show_option_all' (string) - Text to display for showing all terms.
     270 *     'show_option_none' (string) - Text to display for showing no terms.
     271 *     'orderby' (string) default is 'ID' - What column to use for ordering the terms.
     272 *     'order' (string) default is 'ASC' - What direction to order terms.
     273 *     'show_count' (bool|int) default is 0 - Whether to show how many posts are in the terms.
     274 *     'hide_empty' (bool|int) default is 1 - Whether to hide terms that
    277275 * don't have any posts attached to them.
    278276 *     'child_of' (int) default is 0 - See {@link get_categories()}.
    279277 *     'exclude' (string) - See {@link get_categories()}.
     
    284282 *     'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
    285283 *     'class' (string) - The class attribute value for select element.
    286284 *     'selected' (int) - Which category ID is selected.
    287  *     'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
    288285 *
    289286 * The 'hierarchical' argument, which is disabled by default, will override the
    290287 * depth argument, unless it is true. When the argument is false, it will
    291  * display all of the categories. When it is enabled it will use the value in
     288 * display all of the terms. When it is enabled it will use the value in
    292289 * the 'depth' argument.
    293290 *
    294  * @since 2.1.0
    295  *
     291 * @since 3.7.0
     292 *
     293 * @param string $tax The taxonomy to create the dropdown for.
    296294 * @param string|array $args Optional. Override default arguments.
    297295 * @return string HTML content only if 'echo' argument is 0.
    298296 */
    299 function wp_dropdown_categories( $args = '' ) {
     297function wp_dropdown_terms( $taxonomy, $args = '' ) {
    300298        $defaults = array(
    301299                'show_option_all' => '', 'show_option_none' => '',
    302300                'orderby' => 'id', 'order' => 'ASC',
    303                 'show_count' => 0,
    304                 'hide_empty' => 1, 'child_of' => 0,
     301                'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0,
    305302                'exclude' => '', 'echo' => 1,
    306303                'selected' => 0, 'hierarchical' => 0,
    307304                'name' => 'cat', 'id' => '',
    308305                'class' => 'postform', 'depth' => 0,
    309                 'tab_index' => 0, 'taxonomy' => 'category',
    310                 'hide_if_empty' => false
     306                'tab_index' => 0, 'hide_if_empty' => false
    311307        );
    312308
    313309        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
    314310
    315         // Back compat.
    316         if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
    317                 _deprecated_argument( __FUNCTION__, '3.0', '' );
    318                 $args['taxonomy'] = 'link_category';
    319         }
    320 
    321311        $r = wp_parse_args( $args, $defaults );
    322312
    323         if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
     313        if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
    324314                $r['pad_counts'] = true;
    325315        }
    326316
    327         extract( $r );
     317        // Back compat.
     318        if ( ! empty( $r['show_option_all'] ) )
     319                $r['show_option_all'] = apply_filters( 'list_cats', $r['show_option_all'] );
     320        if ( ! empty( $r['show_option_none'] ) )
     321                $r['show_option_none'] = apply_filters( 'list_cats', $r['show_option_none'] );
    328322
    329         $tab_index_attribute = '';
    330         if ( (int) $tab_index > 0 )
    331                 $tab_index_attribute = " tabindex=\"$tab_index\"";
     323        $terms = get_terms( $taxonomy, $r );
     324        $name = esc_attr( $r['name'] );
     325        $class = esc_attr( $r['class'] );
     326        $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
     327        $tab_index_attribute = ( (int) $r['tab_index'] > 0 ) ? " tabindex='{$r['tab_index']}'" : '';
     328        $show_option_all = esc_html( apply_filters( 'list_terms_show_all', $r['show_option_all'] ) );
     329        $show_option_none = esc_html( apply_filters( 'list_terms_show_none', $r['show_option_none'] ) );
     330        $depth = ( $r['hierarchical'] ) ? $r['depth'] : -1; // Walk the depth only if heirarchical.
    332331
    333         $categories = get_terms( $taxonomy, $r );
    334         $name = esc_attr( $name );
    335         $class = esc_attr( $class );
    336         $id = $id ? esc_attr( $id ) : $name;
     332        $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
    337333
    338         if ( ! $r['hide_if_empty'] || ! empty($categories) )
    339                 $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
    340         else
    341                 $output = '';
     334        if ( empty( $terms ) ) {
     335                if ( $r['hide_if_empty'] )
     336                        return '';
     337                elseif ( $show_option_none )
     338                        $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
     339        } else {
    342340
    343         if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
    344                 $show_option_none = apply_filters( 'list_cats', $show_option_none );
    345                 $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
    346         }
    347 
    348         if ( ! empty( $categories ) ) {
    349 
    350341                if ( $show_option_all ) {
    351                         $show_option_all = apply_filters( 'list_cats', $show_option_all );
    352                         $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
     342                        $selected = ( '0' === strval( $r['selected'] ) ) ? " selected='selected'" : '';
    353343                        $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
    354344                }
    355345
    356346                if ( $show_option_none ) {
    357                         $show_option_none = apply_filters( 'list_cats', $show_option_none );
    358347                        $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
    359348                        $output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
    360349                }
    361350
    362                 if ( $hierarchical )
    363                         $depth = $r['depth'];  // Walk the full depth.
    364                 else
    365                         $depth = -1; // Flat.
    366 
    367                 $output .= walk_category_dropdown_tree( $categories, $depth, $r );
     351                $output .= walk_category_dropdown_tree( $terms, $depth, $r );
    368352        }
     353       
     354        $output .= "</select>\n";
    369355
    370         if ( ! $r['hide_if_empty'] || ! empty($categories) )
    371                 $output .= "</select>\n";
    372 
     356        // Back compat.
    373357        $output = apply_filters( 'wp_dropdown_cats', $output );
     358        $output = apply_filters( 'wp_dropdown_terms', $output );
    374359
    375         if ( $echo )
     360        if ( $r['echo'] )
    376361                echo $output;
    377362
    378363        return $output;
    379364}
    380365
    381366/**
    382  * Display or retrieve the HTML list of categories.
     367 * Display or retrieve the HTML dropdown list of categories.
    383368 *
     369 * The list of arguments matches {@link wp_dropdown_terms()}.
     370 *
     371 * @since 2.1.0
     372 *
     373 * @param string|array $args Optional. Override default arguments.
     374 * @return string HTML content only if 'echo' argument is 0.
     375 */
     376function wp_dropdown_categories( $args = '' ) {
     377        $taxonomy = 'category';
     378
     379        // Back compat.
     380        if ( isset( $args['type'] ) && 'link' === $args['type'] ) {
     381                _deprecated_argument( __FUNCTION__, '3.0', '' );
     382                $taxonomy = 'link_category';
     383        } elseif ( isset( $args['taxonomy'] ) && ! empty( $args['taxonomy'] ) ) {
     384                _deprecated_argument( __FUNCTION__, '3.7', '' );
     385                $taxonomy = $args['taxonomy'];
     386                unset( $args['taxonomy'] );
     387        }
     388
     389        return wp_dropdown_terms( $args, $taxonomy );
     390}
     391
     392/**
     393 * Display or retrieve the HTML list of a taxonomy's terms.
     394 *
    384395 * The list of arguments is below:
    385396 *     'show_option_all' (string) - Text to display for showing all categories.
    386397 *     'orderby' (string) default is 'ID' - What column to use for ordering the
     
    491502}
    492503
    493504/**
     505 * Display or retrieve the HTML list of a taxonomy's terms.
     506 *
     507 * The list of arguments matches wp_list_categories() with the exception of
     508 * 'taxonomy', which is its own function argument here.
     509 *
     510 * @since 3.5
     511 *
     512 * @param string $taxonomy Taxonomy name
     513 * @param string|array $args Optional. Override default arguments.
     514 * @return string HTML content only if 'echo' argument is 0.
     515 */
     516function wp_list_terms( $taxonomy, $args = '' ) {
     517        $args = wp_parse_args( $args );
     518        $args['taxonomy'] = $taxonomy;
     519
     520        return wp_list_categories( $args );
     521}
     522
     523/**
    494524 * Display tag cloud.
    495525 *
    496526 * The text size is set by the 'smallest' and 'largest' arguments, which will