equal
deleted
inserted
replaced
6 */ |
6 */ |
7 |
7 |
8 /** |
8 /** |
9 * Renders the `core/archives` block on server. |
9 * Renders the `core/archives` block on server. |
10 * |
10 * |
|
11 * @since 5.0.0 |
|
12 * |
11 * @see WP_Widget_Archives |
13 * @see WP_Widget_Archives |
12 * |
14 * |
13 * @param array $attributes The block attributes. |
15 * @param array $attributes The block attributes. |
14 * |
16 * |
15 * @return string Returns the post content with archives added. |
17 * @return string Returns the post content with archives added. |
16 */ |
18 */ |
17 function render_block_core_archives( $attributes ) { |
19 function render_block_core_archives( $attributes ) { |
18 $show_post_count = ! empty( $attributes['showPostCounts'] ); |
20 $show_post_count = ! empty( $attributes['showPostCounts'] ); |
19 $type = isset( $attributes['type'] ) ? $attributes['type'] : 'monthly'; |
21 $type = isset( $attributes['type'] ) ? $attributes['type'] : 'monthly'; |
20 $class = ''; |
22 |
|
23 $class = 'wp-block-archives-list'; |
21 |
24 |
22 if ( ! empty( $attributes['displayAsDropdown'] ) ) { |
25 if ( ! empty( $attributes['displayAsDropdown'] ) ) { |
23 |
26 |
24 $class .= ' wp-block-archives-dropdown'; |
27 $class = 'wp-block-archives-dropdown'; |
25 |
28 |
26 $dropdown_id = wp_unique_id( 'wp-block-archives-' ); |
29 $dropdown_id = wp_unique_id( 'wp-block-archives-' ); |
27 $title = __( 'Archives' ); |
30 $title = __( 'Archives' ); |
28 |
31 |
29 /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
32 /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
38 |
41 |
39 $dropdown_args['echo'] = 0; |
42 $dropdown_args['echo'] = 0; |
40 |
43 |
41 $archives = wp_get_archives( $dropdown_args ); |
44 $archives = wp_get_archives( $dropdown_args ); |
42 |
45 |
43 $classnames = esc_attr( $class ); |
46 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) ); |
44 |
|
45 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); |
|
46 |
47 |
47 switch ( $dropdown_args['type'] ) { |
48 switch ( $dropdown_args['type'] ) { |
48 case 'yearly': |
49 case 'yearly': |
49 $label = __( 'Select Year' ); |
50 $label = __( 'Select Year' ); |
50 break; |
51 break; |
60 default: |
61 default: |
61 $label = __( 'Select Post' ); |
62 $label = __( 'Select Post' ); |
62 break; |
63 break; |
63 } |
64 } |
64 |
65 |
65 $block_content = '<label for="' . esc_attr( $dropdown_id ) . '">' . esc_html( $title ) . '</label> |
66 $show_label = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : ''; |
66 <select id="' . esc_attr( $dropdown_id ) . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> |
67 |
67 <option value="">' . esc_html( $label ) . '</option>' . $archives . '</select>'; |
68 $block_content = '<label for="' . $dropdown_id . '" class="wp-block-archives__label' . $show_label . '">' . esc_html( $title ) . '</label> |
|
69 <select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> |
|
70 <option value="">' . esc_html( $label ) . '</option>' . $archives . '</select>'; |
68 |
71 |
69 return sprintf( |
72 return sprintf( |
70 '<div %1$s>%2$s</div>', |
73 '<div %1$s>%2$s</div>', |
71 $wrapper_attributes, |
74 $wrapper_attributes, |
72 $block_content |
75 $block_content |
73 ); |
76 ); |
74 } |
77 } |
75 |
|
76 $class .= ' wp-block-archives-list'; |
|
77 |
78 |
78 /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
79 /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ |
79 $archives_args = apply_filters( |
80 $archives_args = apply_filters( |
80 'widget_archives_args', |
81 'widget_archives_args', |
81 array( |
82 array( |
105 ); |
106 ); |
106 } |
107 } |
107 |
108 |
108 /** |
109 /** |
109 * Register archives block. |
110 * Register archives block. |
|
111 * |
|
112 * @since 5.0.0 |
110 */ |
113 */ |
111 function register_block_core_archives() { |
114 function register_block_core_archives() { |
112 register_block_type_from_metadata( |
115 register_block_type_from_metadata( |
113 __DIR__ . '/archives', |
116 __DIR__ . '/archives', |
114 array( |
117 array( |