Make WordPress Core


Ignore:
Timestamp:
09/20/2024 01:53:52 AM (2 years ago)
Author:
noisysocks
Message:

Editor: Update packages for 6.7 Beta 1.

Syncs @wordpress/* packages to the wp-6.7 npm tag.

Fixes #61906.
Props peterwilsoncc, gziolo, kevin940726.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/categories.php

    r58187 r59072  
    1010 *
    1111 * @since 5.0.0
     12 * @since 6.7.0 Enable client-side rendering if enhancedPagination context is true.
    1213 *
    13  * @param array $attributes The block attributes.
     14 * @param array    $attributes The block attributes.
     15 * @param string   $content    Block default content.
     16 * @param WP_Block $block      Block instance.
    1417 *
    1518 * @return string Returns the categories list/dropdown markup.
    1619 */
    17 function render_block_core_categories( $attributes ) {
     20function render_block_core_categories( $attributes, $content, $block ) {
    1821        static $block_id = 0;
    1922        ++$block_id;
     23
     24        $taxonomy = get_taxonomy( $attributes['taxonomy'] );
    2025
    2126        $args = array(
    … …  
    2429                'orderby'      => 'name',
    2530                'show_count'   => ! empty( $attributes['showPostCounts'] ),
     31                'taxonomy'     => $attributes['taxonomy'],
    2632                'title_li'     => '',
    2733                'hide_empty'   => empty( $attributes['showEmpty'] ),
    … …  
    3440                $id                       = 'wp-block-categories-' . $block_id;
    3541                $args['id']               = $id;
    36                 $args['show_option_none'] = __( 'Select Category' );
    37                 $wrapper_markup           = '<div %1$s><label class="screen-reader-text" for="' . esc_attr( $id ) . '">' . __( 'Categories' ) . '</label>%2$s</div>';
    38                 $items_markup             = wp_dropdown_categories( $args );
    39                 $type                     = 'dropdown';
     42                $args['name']             = $taxonomy->query_var;
     43                $args['value_field']      = 'slug';
     44                $args['show_option_none'] = sprintf(
     45                        /* translators: %s: taxonomy's singular name */
     46                        __( 'Select %s' ),
     47                        $taxonomy->labels->singular_name
     48                );
     49
     50                $show_label     = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : '';
     51                $default_label  = $taxonomy->label;
     52                $label_text     = ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
     53                $wrapper_markup = '<div %1$s><label class="wp-block-categories__label' . $show_label . '" for="' . esc_attr( $id ) . '">' . $label_text . '</label>%2$s</div>';
     54                $items_markup   = wp_dropdown_categories( $args );
     55                $type           = 'dropdown';
    4056
    4157                if ( ! is_admin() ) {
    … …  
    4965                }
    5066        } else {
     67                $args['show_option_none'] = $taxonomy->labels->no_terms;
     68
    5169                $wrapper_markup = '<ul %1$s>%2$s</ul>';
    5270                $items_markup   = wp_list_categories( $args );
    5371                $type           = 'list';
     72
     73                if ( ! empty( $block->context['enhancedPagination'] ) ) {
     74                        $p = new WP_HTML_Tag_Processor( $items_markup );
     75                        while ( $p->next_tag( 'a' ) ) {
     76                                $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
     77                        }
     78                        $items_markup = $p->get_updated_html();
     79                }
    5480        }
    5581
    … …  
    79105                var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' );
    80106                function onCatChange() {
    81                         if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
    82                                 location.href = "<?php echo esc_url( home_url() ); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
     107                        if ( dropdown.options[ dropdown.selectedIndex ].value !== -1 ) {
     108                                location.href = "<?php echo esc_url( home_url() ); ?>/?" + dropdown.name + '=' + dropdown.options[ dropdown.selectedIndex ].value;
    83109                        }
    84110                }
Note: See TracChangeset for help on using the changeset viewer.