equal
deleted
inserted
replaced
21 * |
21 * |
22 * @since 2.8.0 |
22 * @since 2.8.0 |
23 */ |
23 */ |
24 public function __construct() { |
24 public function __construct() { |
25 $widget_ops = array( |
25 $widget_ops = array( |
26 'classname' => 'widget_archive', |
26 'classname' => 'widget_archive', |
27 'description' => __( 'A monthly archive of your site’s Posts.' ), |
27 'description' => __( 'A monthly archive of your site’s Posts.' ), |
28 'customize_selective_refresh' => true, |
28 'customize_selective_refresh' => true, |
29 ); |
29 ); |
30 parent::__construct('archives', __('Archives'), $widget_ops); |
30 parent::__construct( 'archives', __( 'Archives' ), $widget_ops ); |
31 } |
31 } |
32 |
32 |
33 /** |
33 /** |
34 * Outputs the content for the current Archives widget instance. |
34 * Outputs the content for the current Archives widget instance. |
35 * |
35 * |
56 |
56 |
57 if ( $d ) { |
57 if ( $d ) { |
58 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; |
58 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; |
59 ?> |
59 ?> |
60 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label> |
60 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label> |
61 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> |
61 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown"> |
62 <?php |
62 <?php |
63 /** |
63 /** |
64 * Filters the arguments for the Archives widget drop-down. |
64 * Filters the arguments for the Archives widget drop-down. |
65 * |
65 * |
66 * @since 2.8.0 |
66 * @since 2.8.0 |
69 * @see wp_get_archives() |
69 * @see wp_get_archives() |
70 * |
70 * |
71 * @param array $args An array of Archives widget drop-down arguments. |
71 * @param array $args An array of Archives widget drop-down arguments. |
72 * @param array $instance Settings for the current Archives widget instance. |
72 * @param array $instance Settings for the current Archives widget instance. |
73 */ |
73 */ |
74 $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array( |
74 $dropdown_args = apply_filters( |
75 'type' => 'monthly', |
75 'widget_archives_dropdown_args', |
76 'format' => 'option', |
76 array( |
77 'show_post_count' => $c |
77 'type' => 'monthly', |
78 ), $instance ); |
78 'format' => 'option', |
|
79 'show_post_count' => $c, |
|
80 ), |
|
81 $instance |
|
82 ); |
79 |
83 |
80 switch ( $dropdown_args['type'] ) { |
84 switch ( $dropdown_args['type'] ) { |
81 case 'yearly': |
85 case 'yearly': |
82 $label = __( 'Select Year' ); |
86 $label = __( 'Select Year' ); |
83 break; |
87 break; |
98 |
102 |
99 <option value=""><?php echo esc_attr( $label ); ?></option> |
103 <option value=""><?php echo esc_attr( $label ); ?></option> |
100 <?php wp_get_archives( $dropdown_args ); ?> |
104 <?php wp_get_archives( $dropdown_args ); ?> |
101 |
105 |
102 </select> |
106 </select> |
|
107 |
|
108 <script type='text/javascript'> |
|
109 /* <![CDATA[ */ |
|
110 (function() { |
|
111 var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" ); |
|
112 function onSelectChange() { |
|
113 if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) { |
|
114 document.location.href = this.options[ this.selectedIndex ].value; |
|
115 } |
|
116 } |
|
117 dropdown.onchange = onSelectChange; |
|
118 })(); |
|
119 /* ]]> */ |
|
120 </script> |
|
121 |
103 <?php } else { ?> |
122 <?php } else { ?> |
104 <ul> |
123 <ul> |
105 <?php |
124 <?php |
106 /** |
125 /** |
107 * Filters the arguments for the Archives widget. |
126 * Filters the arguments for the Archives widget. |
108 * |
127 * |
109 * @since 2.8.0 |
128 * @since 2.8.0 |
110 * @since 4.9.0 Added the `$instance` parameter. |
129 * @since 4.9.0 Added the `$instance` parameter. |
111 * |
130 * |
112 * @see wp_get_archives() |
131 * @see wp_get_archives() |
113 * |
132 * |
114 * @param array $args An array of Archives option arguments. |
133 * @param array $args An array of Archives option arguments. |
115 * @param array $instance Array of settings for the current widget. |
134 * @param array $instance Array of settings for the current widget. |
116 */ |
135 */ |
117 wp_get_archives( apply_filters( 'widget_archives_args', array( |
136 wp_get_archives( |
118 'type' => 'monthly', |
137 apply_filters( |
119 'show_post_count' => $c |
138 'widget_archives_args', |
120 ), $instance ) ); |
139 array( |
121 ?> |
140 'type' => 'monthly', |
|
141 'show_post_count' => $c, |
|
142 ), |
|
143 $instance |
|
144 ) |
|
145 ); |
|
146 ?> |
122 </ul> |
147 </ul> |
123 <?php |
148 <?php |
124 } |
149 } |
125 |
150 |
126 echo $args['after_widget']; |
151 echo $args['after_widget']; |
127 } |
152 } |
128 |
153 |
135 * WP_Widget_Archives::form(). |
160 * WP_Widget_Archives::form(). |
136 * @param array $old_instance Old settings for this instance. |
161 * @param array $old_instance Old settings for this instance. |
137 * @return array Updated settings to save. |
162 * @return array Updated settings to save. |
138 */ |
163 */ |
139 public function update( $new_instance, $old_instance ) { |
164 public function update( $new_instance, $old_instance ) { |
140 $instance = $old_instance; |
165 $instance = $old_instance; |
141 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); |
166 $new_instance = wp_parse_args( |
142 $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
167 (array) $new_instance, |
143 $instance['count'] = $new_instance['count'] ? 1 : 0; |
168 array( |
|
169 'title' => '', |
|
170 'count' => 0, |
|
171 'dropdown' => '', |
|
172 ) |
|
173 ); |
|
174 $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
|
175 $instance['count'] = $new_instance['count'] ? 1 : 0; |
144 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0; |
176 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0; |
145 |
177 |
146 return $instance; |
178 return $instance; |
147 } |
179 } |
148 |
180 |
152 * @since 2.8.0 |
184 * @since 2.8.0 |
153 * |
185 * |
154 * @param array $instance Current settings. |
186 * @param array $instance Current settings. |
155 */ |
187 */ |
156 public function form( $instance ) { |
188 public function form( $instance ) { |
157 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); |
189 $instance = wp_parse_args( |
158 $title = sanitize_text_field( $instance['title'] ); |
190 (array) $instance, |
|
191 array( |
|
192 'title' => '', |
|
193 'count' => 0, |
|
194 'dropdown' => '', |
|
195 ) |
|
196 ); |
159 ?> |
197 ?> |
160 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> |
198 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p> |
161 <p> |
199 <p> |
162 <input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label> |
200 <input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>" /> <label for="<?php echo $this->get_field_id( 'dropdown' ); ?>"><?php _e( 'Display as dropdown' ); ?></label> |
163 <br/> |
201 <br/> |
164 <input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label> |
202 <input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" /> <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show post counts' ); ?></label> |
165 </p> |
203 </p> |
166 <?php |
204 <?php |
167 } |
205 } |
168 } |
206 } |