| @@ -15,16 +15,17 @@ | ||
| 15 | 15 | * @return string Returns the post content with archives added. |
| 16 | 16 | */ |
| 17 | 17 | function gutenberg_render_block_core_archives( $attributes ) { |
| 18 | 18 | $show_post_count = ! empty( $attributes['showPostCounts'] ); |
| 19 | + $type = isset( $attributes['type'] ) ? $attributes['type'] : 'monthly'; | |
| 19 | 20 | |
| 20 | - $class = ''; | |
| 21 | + $class = 'wp-block-archives-list'; | |
| 21 | 22 | |
| 22 | 23 | if ( ! empty( $attributes['displayAsDropdown'] ) ) { |
| 23 | 24 | |
| 24 | - $class .= ' wp-block-archives-dropdown'; | |
| 25 | + $class = 'wp-block-archives-dropdown'; | |
| 25 | 26 | |
| 26 | - $dropdown_id = uniqid( 'wp-block-archives-' ); | |
| 27 | + $dropdown_id = wp_unique_id( 'wp-block-archives-' ); | |
| 27 | 28 | $title = __( 'Archives' ); |
| 28 | 29 | |
| 29 | 30 | /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
| 30 | 31 | $dropdown_args = apply_filters( |
| @@ -29,9 +30,9 @@ | ||
| 29 | 30 | /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
| 30 | 31 | $dropdown_args = apply_filters( |
| 31 | 32 | 'widget_archives_dropdown_args', |
| 32 | 33 | array( |
| 33 | - 'type' => 'monthly', | |
| 34 | + 'type' => $type, | |
| 34 | 35 | 'format' => 'option', |
| 35 | 36 | 'show_post_count' => $show_post_count, |
| 36 | 37 | ) |
| 37 | 38 | ); |
| @@ -39,12 +40,10 @@ | ||
| 39 | 40 | $dropdown_args['echo'] = 0; |
| 40 | 41 | |
| 41 | 42 | $archives = wp_get_archives( $dropdown_args ); |
| 42 | 43 | |
| 43 | - $classnames = esc_attr( $class ); | |
| 44 | + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) ); | |
| 44 | 45 | |
| 45 | - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); | |
| 46 | - | |
| 47 | 46 | switch ( $dropdown_args['type'] ) { |
| 48 | 47 | case 'yearly': |
| 49 | 48 | $label = __( 'Select Year' ); |
| 50 | 49 | break; |
| @@ -61,12 +60,14 @@ | ||
| 61 | 60 | $label = __( 'Select Post' ); |
| 62 | 61 | break; |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | - $block_content = '<label for="' . esc_attr( $dropdown_id ) . '">' . esc_html( $title ) . '</label> | |
| 66 | - <select id="' . esc_attr( $dropdown_id ) . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> | |
| 67 | - <option value="">' . esc_html( $label ) . '</option>' . $archives . '</select>'; | |
| 64 | + $show_label = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : ''; | |
| 68 | 65 | |
| 66 | + $block_content = '<label for="' . $dropdown_id . '" class="wp-block-archives__label' . $show_label . '">' . esc_html( $title ) . '</label> | |
| 67 | + <select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> | |
| 68 | + <option value="">' . esc_html( $label ) . '</option>' . $archives . '</select>'; | |
| 69 | + | |
| 69 | 70 | return sprintf( |
| 70 | 71 | '<div %1$s>%2$s</div>', |
| 71 | 72 | $wrapper_attributes, |
| 72 | 73 | $block_content |
| @@ -72,15 +73,13 @@ | ||
| 72 | 73 | $block_content |
| 73 | 74 | ); |
| 74 | 75 | } |
| 75 | 76 | |
| 76 | - $class .= ' wp-block-archives-list'; | |
| 77 | - | |
| 78 | 77 | /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
| 79 | 78 | $archives_args = apply_filters( |
| 80 | 79 | 'widget_archives_args', |
| 81 | 80 | array( |
| 82 | - 'type' => 'monthly', | |
| 81 | + 'type' => $type, | |
| 83 | 82 | 'show_post_count' => $show_post_count, |
| 84 | 83 | ) |
| 85 | 84 | ); |
| 86 | 85 | |