1 <?php |
1 <?php |
2 /** |
2 /** |
3 * Default Widgets |
3 * Widget API: Default core widgets |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage Widgets |
6 * @subpackage Widgets |
|
7 * @since 2.8.0 |
7 */ |
8 */ |
8 |
9 |
9 /** |
10 /** WP_Widget_Pages class */ |
10 * Pages widget class |
11 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-pages.php' ); |
11 * |
|
12 * @since 2.8.0 |
|
13 */ |
|
14 class WP_Widget_Pages extends WP_Widget { |
|
15 |
12 |
16 public function __construct() { |
13 /** WP_Widget_Links class */ |
17 $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'A list of your site’s Pages.') ); |
14 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-links.php' ); |
18 parent::__construct('pages', __('Pages'), $widget_ops); |
|
19 } |
|
20 |
15 |
21 public function widget( $args, $instance ) { |
16 /** WP_Widget_Search class */ |
|
17 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-search.php' ); |
22 |
18 |
23 /** |
19 /** WP_Widget_Archives class */ |
24 * Filter the widget title. |
20 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-archives.php' ); |
25 * |
|
26 * @since 2.6.0 |
|
27 * |
|
28 * @param string $title The widget title. Default 'Pages'. |
|
29 * @param array $instance An array of the widget's settings. |
|
30 * @param mixed $id_base The widget ID. |
|
31 */ |
|
32 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base ); |
|
33 |
21 |
34 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; |
22 /** WP_Widget_Media class */ |
35 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; |
23 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media.php' ); |
36 |
24 |
37 if ( $sortby == 'menu_order' ) |
25 /** WP_Widget_Media_Audio class */ |
38 $sortby = 'menu_order, post_title'; |
26 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-audio.php' ); |
39 |
27 |
40 /** |
28 /** WP_Widget_Media_Image class */ |
41 * Filter the arguments for the Pages widget. |
29 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-image.php' ); |
42 * |
|
43 * @since 2.8.0 |
|
44 * |
|
45 * @see wp_list_pages() |
|
46 * |
|
47 * @param array $args An array of arguments to retrieve the pages list. |
|
48 */ |
|
49 $out = wp_list_pages( apply_filters( 'widget_pages_args', array( |
|
50 'title_li' => '', |
|
51 'echo' => 0, |
|
52 'sort_column' => $sortby, |
|
53 'exclude' => $exclude |
|
54 ) ) ); |
|
55 |
30 |
56 if ( ! empty( $out ) ) { |
31 /** WP_Widget_Media_Video class */ |
57 echo $args['before_widget']; |
32 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-video.php' ); |
58 if ( $title ) { |
|
59 echo $args['before_title'] . $title . $args['after_title']; |
|
60 } |
|
61 ?> |
|
62 <ul> |
|
63 <?php echo $out; ?> |
|
64 </ul> |
|
65 <?php |
|
66 echo $args['after_widget']; |
|
67 } |
|
68 } |
|
69 |
33 |
70 public function update( $new_instance, $old_instance ) { |
34 /** WP_Widget_Media_Gallery class */ |
71 $instance = $old_instance; |
35 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-gallery.php' ); |
72 $instance['title'] = strip_tags($new_instance['title']); |
|
73 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) { |
|
74 $instance['sortby'] = $new_instance['sortby']; |
|
75 } else { |
|
76 $instance['sortby'] = 'menu_order'; |
|
77 } |
|
78 |
36 |
79 $instance['exclude'] = strip_tags( $new_instance['exclude'] ); |
37 /** WP_Widget_Meta class */ |
|
38 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-meta.php' ); |
80 |
39 |
81 return $instance; |
40 /** WP_Widget_Calendar class */ |
82 } |
41 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-calendar.php' ); |
83 |
42 |
84 public function form( $instance ) { |
43 /** WP_Widget_Text class */ |
85 //Defaults |
44 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-text.php' ); |
86 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') ); |
|
87 $title = esc_attr( $instance['title'] ); |
|
88 $exclude = esc_attr( $instance['exclude'] ); |
|
89 ?> |
|
90 <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 $title; ?>" /></p> |
|
91 <p> |
|
92 <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label> |
|
93 <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat"> |
|
94 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option> |
|
95 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option> |
|
96 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option> |
|
97 </select> |
|
98 </p> |
|
99 <p> |
|
100 <label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" /> |
|
101 <br /> |
|
102 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small> |
|
103 </p> |
|
104 <?php |
|
105 } |
|
106 |
45 |
107 } |
46 /** WP_Widget_Categories class */ |
|
47 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-categories.php' ); |
108 |
48 |
109 /** |
49 /** WP_Widget_Recent_Posts class */ |
110 * Links widget class |
50 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-recent-posts.php' ); |
111 * |
|
112 * @since 2.8.0 |
|
113 */ |
|
114 class WP_Widget_Links extends WP_Widget { |
|
115 |
51 |
116 public function __construct() { |
52 /** WP_Widget_Recent_Comments class */ |
117 $widget_ops = array('description' => __( "Your blogroll" ) ); |
53 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-recent-comments.php' ); |
118 parent::__construct('links', __('Links'), $widget_ops); |
|
119 } |
|
120 |
54 |
121 public function widget( $args, $instance ) { |
55 /** WP_Widget_RSS class */ |
|
56 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-rss.php' ); |
122 |
57 |
123 $show_description = isset($instance['description']) ? $instance['description'] : false; |
58 /** WP_Widget_Tag_Cloud class */ |
124 $show_name = isset($instance['name']) ? $instance['name'] : false; |
59 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-tag-cloud.php' ); |
125 $show_rating = isset($instance['rating']) ? $instance['rating'] : false; |
|
126 $show_images = isset($instance['images']) ? $instance['images'] : true; |
|
127 $category = isset($instance['category']) ? $instance['category'] : false; |
|
128 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; |
|
129 $order = $orderby == 'rating' ? 'DESC' : 'ASC'; |
|
130 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; |
|
131 |
60 |
132 $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] ); |
61 /** WP_Nav_Menu_Widget class */ |
|
62 require_once( ABSPATH . WPINC . '/widgets/class-wp-nav-menu-widget.php' ); |
133 |
63 |
134 /** |
64 /** WP_Widget_Custom_HTML class */ |
135 * Filter the arguments for the Links widget. |
65 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-custom-html.php' ); |
136 * |
|
137 * @since 2.6.0 |
|
138 * |
|
139 * @see wp_list_bookmarks() |
|
140 * |
|
141 * @param array $args An array of arguments to retrieve the links list. |
|
142 */ |
|
143 wp_list_bookmarks( apply_filters( 'widget_links_args', array( |
|
144 'title_before' => $args['before_title'], 'title_after' => $args['after_title'], |
|
145 'category_before' => $before_widget, 'category_after' => $args['after_widget'], |
|
146 'show_images' => $show_images, 'show_description' => $show_description, |
|
147 'show_name' => $show_name, 'show_rating' => $show_rating, |
|
148 'category' => $category, 'class' => 'linkcat widget', |
|
149 'orderby' => $orderby, 'order' => $order, |
|
150 'limit' => $limit, |
|
151 ) ) ); |
|
152 } |
|
153 |
|
154 public function update( $new_instance, $old_instance ) { |
|
155 $new_instance = (array) $new_instance; |
|
156 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); |
|
157 foreach ( $instance as $field => $val ) { |
|
158 if ( isset($new_instance[$field]) ) |
|
159 $instance[$field] = 1; |
|
160 } |
|
161 |
|
162 $instance['orderby'] = 'name'; |
|
163 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) |
|
164 $instance['orderby'] = $new_instance['orderby']; |
|
165 |
|
166 $instance['category'] = intval( $new_instance['category'] ); |
|
167 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; |
|
168 |
|
169 return $instance; |
|
170 } |
|
171 |
|
172 public function form( $instance ) { |
|
173 |
|
174 //Defaults |
|
175 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); |
|
176 $link_cats = get_terms( 'link_category' ); |
|
177 if ( ! $limit = intval( $instance['limit'] ) ) |
|
178 $limit = -1; |
|
179 ?> |
|
180 <p> |
|
181 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label> |
|
182 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> |
|
183 <option value=""><?php _ex('All Links', 'links widget'); ?></option> |
|
184 <?php |
|
185 foreach ( $link_cats as $link_cat ) { |
|
186 echo '<option value="' . intval( $link_cat->term_id ) . '"' |
|
187 . selected( $instance['category'], $link_cat->term_id, false ) |
|
188 . '>' . $link_cat->name . "</option>\n"; |
|
189 } |
|
190 ?> |
|
191 </select> |
|
192 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label> |
|
193 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat"> |
|
194 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option> |
|
195 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option> |
|
196 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option> |
|
197 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option> |
|
198 </select> |
|
199 </p> |
|
200 <p> |
|
201 <input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> |
|
202 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br /> |
|
203 <input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" /> |
|
204 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br /> |
|
205 <input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" /> |
|
206 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br /> |
|
207 <input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" /> |
|
208 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label> |
|
209 </p> |
|
210 <p> |
|
211 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label> |
|
212 <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" /> |
|
213 </p> |
|
214 <?php |
|
215 } |
|
216 } |
|
217 |
|
218 /** |
|
219 * Search widget class |
|
220 * |
|
221 * @since 2.8.0 |
|
222 */ |
|
223 class WP_Widget_Search extends WP_Widget { |
|
224 |
|
225 public function __construct() { |
|
226 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") ); |
|
227 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); |
|
228 } |
|
229 |
|
230 public function widget( $args, $instance ) { |
|
231 |
|
232 /** This filter is documented in wp-includes/default-widgets.php */ |
|
233 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
234 |
|
235 echo $args['before_widget']; |
|
236 if ( $title ) { |
|
237 echo $args['before_title'] . $title . $args['after_title']; |
|
238 } |
|
239 |
|
240 // Use current theme search form if it exists |
|
241 get_search_form(); |
|
242 |
|
243 echo $args['after_widget']; |
|
244 } |
|
245 |
|
246 public function form( $instance ) { |
|
247 $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); |
|
248 $title = $instance['title']; |
|
249 ?> |
|
250 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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); ?>" /></label></p> |
|
251 <?php |
|
252 } |
|
253 |
|
254 public function update( $new_instance, $old_instance ) { |
|
255 $instance = $old_instance; |
|
256 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => '')); |
|
257 $instance['title'] = strip_tags($new_instance['title']); |
|
258 return $instance; |
|
259 } |
|
260 |
|
261 } |
|
262 |
|
263 /** |
|
264 * Archives widget class |
|
265 * |
|
266 * @since 2.8.0 |
|
267 */ |
|
268 class WP_Widget_Archives extends WP_Widget { |
|
269 |
|
270 public function __construct() { |
|
271 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') ); |
|
272 parent::__construct('archives', __('Archives'), $widget_ops); |
|
273 } |
|
274 |
|
275 public function widget( $args, $instance ) { |
|
276 $c = ! empty( $instance['count'] ) ? '1' : '0'; |
|
277 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
|
278 |
|
279 /** This filter is documented in wp-includes/default-widgets.php */ |
|
280 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); |
|
281 |
|
282 echo $args['before_widget']; |
|
283 if ( $title ) { |
|
284 echo $args['before_title'] . $title . $args['after_title']; |
|
285 } |
|
286 |
|
287 if ( $d ) { |
|
288 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; |
|
289 ?> |
|
290 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label> |
|
291 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> |
|
292 <?php |
|
293 /** |
|
294 * Filter the arguments for the Archives widget drop-down. |
|
295 * |
|
296 * @since 2.8.0 |
|
297 * |
|
298 * @see wp_get_archives() |
|
299 * |
|
300 * @param array $args An array of Archives widget drop-down arguments. |
|
301 */ |
|
302 $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array( |
|
303 'type' => 'monthly', |
|
304 'format' => 'option', |
|
305 'show_post_count' => $c |
|
306 ) ); |
|
307 |
|
308 switch ( $dropdown_args['type'] ) { |
|
309 case 'yearly': |
|
310 $label = __( 'Select Year' ); |
|
311 break; |
|
312 case 'monthly': |
|
313 $label = __( 'Select Month' ); |
|
314 break; |
|
315 case 'daily': |
|
316 $label = __( 'Select Day' ); |
|
317 break; |
|
318 case 'weekly': |
|
319 $label = __( 'Select Week' ); |
|
320 break; |
|
321 default: |
|
322 $label = __( 'Select Post' ); |
|
323 break; |
|
324 } |
|
325 ?> |
|
326 |
|
327 <option value=""><?php echo esc_attr( $label ); ?></option> |
|
328 <?php wp_get_archives( $dropdown_args ); ?> |
|
329 |
|
330 </select> |
|
331 <?php |
|
332 } else { |
|
333 ?> |
|
334 <ul> |
|
335 <?php |
|
336 /** |
|
337 * Filter the arguments for the Archives widget. |
|
338 * |
|
339 * @since 2.8.0 |
|
340 * |
|
341 * @see wp_get_archives() |
|
342 * |
|
343 * @param array $args An array of Archives option arguments. |
|
344 */ |
|
345 wp_get_archives( apply_filters( 'widget_archives_args', array( |
|
346 'type' => 'monthly', |
|
347 'show_post_count' => $c |
|
348 ) ) ); |
|
349 ?> |
|
350 </ul> |
|
351 <?php |
|
352 } |
|
353 |
|
354 echo $args['after_widget']; |
|
355 } |
|
356 |
|
357 public function update( $new_instance, $old_instance ) { |
|
358 $instance = $old_instance; |
|
359 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); |
|
360 $instance['title'] = strip_tags($new_instance['title']); |
|
361 $instance['count'] = $new_instance['count'] ? 1 : 0; |
|
362 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0; |
|
363 |
|
364 return $instance; |
|
365 } |
|
366 |
|
367 public function form( $instance ) { |
|
368 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); |
|
369 $title = strip_tags($instance['title']); |
|
370 $count = $instance['count'] ? 'checked="checked"' : ''; |
|
371 $dropdown = $instance['dropdown'] ? 'checked="checked"' : ''; |
|
372 ?> |
|
373 <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> |
|
374 <p> |
|
375 <input class="checkbox" type="checkbox" <?php echo $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> |
|
376 <br/> |
|
377 <input class="checkbox" type="checkbox" <?php echo $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> |
|
378 </p> |
|
379 <?php |
|
380 } |
|
381 } |
|
382 |
|
383 /** |
|
384 * Meta widget class |
|
385 * |
|
386 * Displays log in/out, RSS feed links, etc. |
|
387 * |
|
388 * @since 2.8.0 |
|
389 */ |
|
390 class WP_Widget_Meta extends WP_Widget { |
|
391 |
|
392 public function __construct() { |
|
393 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") ); |
|
394 parent::__construct('meta', __('Meta'), $widget_ops); |
|
395 } |
|
396 |
|
397 public function widget( $args, $instance ) { |
|
398 |
|
399 /** This filter is documented in wp-includes/default-widgets.php */ |
|
400 $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base ); |
|
401 |
|
402 echo $args['before_widget']; |
|
403 if ( $title ) { |
|
404 echo $args['before_title'] . $title . $args['after_title']; |
|
405 } |
|
406 ?> |
|
407 <ul> |
|
408 <?php wp_register(); ?> |
|
409 <li><?php wp_loginout(); ?></li> |
|
410 <li><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> |
|
411 <li><a href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> |
|
412 <?php |
|
413 /** |
|
414 * Filter the "Powered by WordPress" text in the Meta widget. |
|
415 * |
|
416 * @since 3.6.0 |
|
417 * |
|
418 * @param string $title_text Default title text for the WordPress.org link. |
|
419 */ |
|
420 echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>', |
|
421 esc_url( __( 'https://wordpress.org/' ) ), |
|
422 esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ), |
|
423 _x( 'WordPress.org', 'meta widget link text' ) |
|
424 ) ); |
|
425 |
|
426 wp_meta(); |
|
427 ?> |
|
428 </ul> |
|
429 <?php |
|
430 echo $args['after_widget']; |
|
431 } |
|
432 |
|
433 public function update( $new_instance, $old_instance ) { |
|
434 $instance = $old_instance; |
|
435 $instance['title'] = strip_tags($new_instance['title']); |
|
436 |
|
437 return $instance; |
|
438 } |
|
439 |
|
440 public function form( $instance ) { |
|
441 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
|
442 $title = strip_tags($instance['title']); |
|
443 ?> |
|
444 <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> |
|
445 <?php |
|
446 } |
|
447 } |
|
448 |
|
449 /** |
|
450 * Calendar widget class |
|
451 * |
|
452 * @since 2.8.0 |
|
453 */ |
|
454 class WP_Widget_Calendar extends WP_Widget { |
|
455 |
|
456 public function __construct() { |
|
457 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s Posts.') ); |
|
458 parent::__construct('calendar', __('Calendar'), $widget_ops); |
|
459 } |
|
460 |
|
461 public function widget( $args, $instance ) { |
|
462 |
|
463 /** This filter is documented in wp-includes/default-widgets.php */ |
|
464 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
465 |
|
466 echo $args['before_widget']; |
|
467 if ( $title ) { |
|
468 echo $args['before_title'] . $title . $args['after_title']; |
|
469 } |
|
470 echo '<div id="calendar_wrap">'; |
|
471 get_calendar(); |
|
472 echo '</div>'; |
|
473 echo $args['after_widget']; |
|
474 } |
|
475 |
|
476 public function update( $new_instance, $old_instance ) { |
|
477 $instance = $old_instance; |
|
478 $instance['title'] = strip_tags($new_instance['title']); |
|
479 |
|
480 return $instance; |
|
481 } |
|
482 |
|
483 public function form( $instance ) { |
|
484 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
|
485 $title = strip_tags($instance['title']); |
|
486 ?> |
|
487 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|
488 <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> |
|
489 <?php |
|
490 } |
|
491 } |
|
492 |
|
493 /** |
|
494 * Text widget class |
|
495 * |
|
496 * @since 2.8.0 |
|
497 */ |
|
498 class WP_Widget_Text extends WP_Widget { |
|
499 |
|
500 public function __construct() { |
|
501 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.')); |
|
502 $control_ops = array('width' => 400, 'height' => 350); |
|
503 parent::__construct('text', __('Text'), $widget_ops, $control_ops); |
|
504 } |
|
505 |
|
506 public function widget( $args, $instance ) { |
|
507 |
|
508 /** This filter is documented in wp-includes/default-widgets.php */ |
|
509 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
510 |
|
511 /** |
|
512 * Filter the content of the Text widget. |
|
513 * |
|
514 * @since 2.3.0 |
|
515 * |
|
516 * @param string $widget_text The widget content. |
|
517 * @param WP_Widget $instance WP_Widget instance. |
|
518 */ |
|
519 $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); |
|
520 echo $args['before_widget']; |
|
521 if ( ! empty( $title ) ) { |
|
522 echo $args['before_title'] . $title . $args['after_title']; |
|
523 } ?> |
|
524 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div> |
|
525 <?php |
|
526 echo $args['after_widget']; |
|
527 } |
|
528 |
|
529 public function update( $new_instance, $old_instance ) { |
|
530 $instance = $old_instance; |
|
531 $instance['title'] = strip_tags($new_instance['title']); |
|
532 if ( current_user_can('unfiltered_html') ) |
|
533 $instance['text'] = $new_instance['text']; |
|
534 else |
|
535 $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed |
|
536 $instance['filter'] = ! empty( $new_instance['filter'] ); |
|
537 return $instance; |
|
538 } |
|
539 |
|
540 public function form( $instance ) { |
|
541 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) ); |
|
542 $title = strip_tags($instance['title']); |
|
543 $text = esc_textarea($instance['text']); |
|
544 ?> |
|
545 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|
546 <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> |
|
547 |
|
548 <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea> |
|
549 |
|
550 <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p> |
|
551 <?php |
|
552 } |
|
553 } |
|
554 |
|
555 /** |
|
556 * Categories widget class |
|
557 * |
|
558 * @since 2.8.0 |
|
559 */ |
|
560 class WP_Widget_Categories extends WP_Widget { |
|
561 |
|
562 public function __construct() { |
|
563 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) ); |
|
564 parent::__construct('categories', __('Categories'), $widget_ops); |
|
565 } |
|
566 |
|
567 public function widget( $args, $instance ) { |
|
568 |
|
569 /** This filter is documented in wp-includes/default-widgets.php */ |
|
570 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base ); |
|
571 |
|
572 $c = ! empty( $instance['count'] ) ? '1' : '0'; |
|
573 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; |
|
574 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
|
575 |
|
576 echo $args['before_widget']; |
|
577 if ( $title ) { |
|
578 echo $args['before_title'] . $title . $args['after_title']; |
|
579 } |
|
580 |
|
581 $cat_args = array( |
|
582 'orderby' => 'name', |
|
583 'show_count' => $c, |
|
584 'hierarchical' => $h |
|
585 ); |
|
586 |
|
587 if ( $d ) { |
|
588 static $first_dropdown = true; |
|
589 |
|
590 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}"; |
|
591 $first_dropdown = false; |
|
592 |
|
593 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>'; |
|
594 |
|
595 $cat_args['show_option_none'] = __( 'Select Category' ); |
|
596 $cat_args['id'] = $dropdown_id; |
|
597 |
|
598 /** |
|
599 * Filter the arguments for the Categories widget drop-down. |
|
600 * |
|
601 * @since 2.8.0 |
|
602 * |
|
603 * @see wp_dropdown_categories() |
|
604 * |
|
605 * @param array $cat_args An array of Categories widget drop-down arguments. |
|
606 */ |
|
607 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) ); |
|
608 ?> |
|
609 |
|
610 <script type='text/javascript'> |
|
611 /* <![CDATA[ */ |
|
612 (function() { |
|
613 var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" ); |
|
614 function onCatChange() { |
|
615 if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) { |
|
616 location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value; |
|
617 } |
|
618 } |
|
619 dropdown.onchange = onCatChange; |
|
620 })(); |
|
621 /* ]]> */ |
|
622 </script> |
|
623 |
|
624 <?php |
|
625 } else { |
|
626 ?> |
|
627 <ul> |
|
628 <?php |
|
629 $cat_args['title_li'] = ''; |
|
630 |
|
631 /** |
|
632 * Filter the arguments for the Categories widget. |
|
633 * |
|
634 * @since 2.8.0 |
|
635 * |
|
636 * @param array $cat_args An array of Categories widget options. |
|
637 */ |
|
638 wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) ); |
|
639 ?> |
|
640 </ul> |
|
641 <?php |
|
642 } |
|
643 |
|
644 echo $args['after_widget']; |
|
645 } |
|
646 |
|
647 public function update( $new_instance, $old_instance ) { |
|
648 $instance = $old_instance; |
|
649 $instance['title'] = strip_tags($new_instance['title']); |
|
650 $instance['count'] = !empty($new_instance['count']) ? 1 : 0; |
|
651 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0; |
|
652 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0; |
|
653 |
|
654 return $instance; |
|
655 } |
|
656 |
|
657 public function form( $instance ) { |
|
658 //Defaults |
|
659 $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); |
|
660 $title = esc_attr( $instance['title'] ); |
|
661 $count = isset($instance['count']) ? (bool) $instance['count'] :false; |
|
662 $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false; |
|
663 $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false; |
|
664 ?> |
|
665 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label> |
|
666 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
667 |
|
668 <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> /> |
|
669 <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br /> |
|
670 |
|
671 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> /> |
|
672 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br /> |
|
673 |
|
674 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> /> |
|
675 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p> |
|
676 <?php |
|
677 } |
|
678 |
|
679 } |
|
680 |
|
681 /** |
|
682 * Recent_Posts widget class |
|
683 * |
|
684 * @since 2.8.0 |
|
685 */ |
|
686 class WP_Widget_Recent_Posts extends WP_Widget { |
|
687 |
|
688 public function __construct() { |
|
689 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site’s most recent Posts.") ); |
|
690 parent::__construct('recent-posts', __('Recent Posts'), $widget_ops); |
|
691 $this->alt_option_name = 'widget_recent_entries'; |
|
692 |
|
693 add_action( 'save_post', array($this, 'flush_widget_cache') ); |
|
694 add_action( 'deleted_post', array($this, 'flush_widget_cache') ); |
|
695 add_action( 'switch_theme', array($this, 'flush_widget_cache') ); |
|
696 } |
|
697 |
|
698 public function widget($args, $instance) { |
|
699 $cache = array(); |
|
700 if ( ! $this->is_preview() ) { |
|
701 $cache = wp_cache_get( 'widget_recent_posts', 'widget' ); |
|
702 } |
|
703 |
|
704 if ( ! is_array( $cache ) ) { |
|
705 $cache = array(); |
|
706 } |
|
707 |
|
708 if ( ! isset( $args['widget_id'] ) ) { |
|
709 $args['widget_id'] = $this->id; |
|
710 } |
|
711 |
|
712 if ( isset( $cache[ $args['widget_id'] ] ) ) { |
|
713 echo $cache[ $args['widget_id'] ]; |
|
714 return; |
|
715 } |
|
716 |
|
717 ob_start(); |
|
718 |
|
719 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' ); |
|
720 |
|
721 /** This filter is documented in wp-includes/default-widgets.php */ |
|
722 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
723 |
|
724 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; |
|
725 if ( ! $number ) |
|
726 $number = 5; |
|
727 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; |
|
728 |
|
729 /** |
|
730 * Filter the arguments for the Recent Posts widget. |
|
731 * |
|
732 * @since 3.4.0 |
|
733 * |
|
734 * @see WP_Query::get_posts() |
|
735 * |
|
736 * @param array $args An array of arguments used to retrieve the recent posts. |
|
737 */ |
|
738 $r = new WP_Query( apply_filters( 'widget_posts_args', array( |
|
739 'posts_per_page' => $number, |
|
740 'no_found_rows' => true, |
|
741 'post_status' => 'publish', |
|
742 'ignore_sticky_posts' => true |
|
743 ) ) ); |
|
744 |
|
745 if ($r->have_posts()) : |
|
746 ?> |
|
747 <?php echo $args['before_widget']; ?> |
|
748 <?php if ( $title ) { |
|
749 echo $args['before_title'] . $title . $args['after_title']; |
|
750 } ?> |
|
751 <ul> |
|
752 <?php while ( $r->have_posts() ) : $r->the_post(); ?> |
|
753 <li> |
|
754 <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a> |
|
755 <?php if ( $show_date ) : ?> |
|
756 <span class="post-date"><?php echo get_the_date(); ?></span> |
|
757 <?php endif; ?> |
|
758 </li> |
|
759 <?php endwhile; ?> |
|
760 </ul> |
|
761 <?php echo $args['after_widget']; ?> |
|
762 <?php |
|
763 // Reset the global $the_post as this query will have stomped on it |
|
764 wp_reset_postdata(); |
|
765 |
|
766 endif; |
|
767 |
|
768 if ( ! $this->is_preview() ) { |
|
769 $cache[ $args['widget_id'] ] = ob_get_flush(); |
|
770 wp_cache_set( 'widget_recent_posts', $cache, 'widget' ); |
|
771 } else { |
|
772 ob_end_flush(); |
|
773 } |
|
774 } |
|
775 |
|
776 public function update( $new_instance, $old_instance ) { |
|
777 $instance = $old_instance; |
|
778 $instance['title'] = strip_tags($new_instance['title']); |
|
779 $instance['number'] = (int) $new_instance['number']; |
|
780 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; |
|
781 $this->flush_widget_cache(); |
|
782 |
|
783 $alloptions = wp_cache_get( 'alloptions', 'options' ); |
|
784 if ( isset($alloptions['widget_recent_entries']) ) |
|
785 delete_option('widget_recent_entries'); |
|
786 |
|
787 return $instance; |
|
788 } |
|
789 |
|
790 public function flush_widget_cache() { |
|
791 wp_cache_delete('widget_recent_posts', 'widget'); |
|
792 } |
|
793 |
|
794 public function form( $instance ) { |
|
795 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
796 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; |
|
797 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; |
|
798 ?> |
|
799 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
|
800 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
801 |
|
802 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label> |
|
803 <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> |
|
804 |
|
805 <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" /> |
|
806 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p> |
|
807 <?php |
|
808 } |
|
809 } |
|
810 |
|
811 /** |
|
812 * Recent_Comments widget class |
|
813 * |
|
814 * @since 2.8.0 |
|
815 */ |
|
816 class WP_Widget_Recent_Comments extends WP_Widget { |
|
817 |
|
818 public function __construct() { |
|
819 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'Your site’s most recent comments.' ) ); |
|
820 parent::__construct('recent-comments', __('Recent Comments'), $widget_ops); |
|
821 $this->alt_option_name = 'widget_recent_comments'; |
|
822 |
|
823 if ( is_active_widget(false, false, $this->id_base) ) |
|
824 add_action( 'wp_head', array($this, 'recent_comments_style') ); |
|
825 |
|
826 add_action( 'comment_post', array($this, 'flush_widget_cache') ); |
|
827 add_action( 'edit_comment', array($this, 'flush_widget_cache') ); |
|
828 add_action( 'transition_comment_status', array($this, 'flush_widget_cache') ); |
|
829 } |
|
830 |
|
831 public function recent_comments_style() { |
|
832 |
|
833 /** |
|
834 * Filter the Recent Comments default widget styles. |
|
835 * |
|
836 * @since 3.1.0 |
|
837 * |
|
838 * @param bool $active Whether the widget is active. Default true. |
|
839 * @param string $id_base The widget ID. |
|
840 */ |
|
841 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876 |
|
842 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) ) |
|
843 return; |
|
844 ?> |
|
845 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style> |
|
846 <?php |
|
847 } |
|
848 |
|
849 public function flush_widget_cache() { |
|
850 wp_cache_delete('widget_recent_comments', 'widget'); |
|
851 } |
|
852 |
|
853 public function widget( $args, $instance ) { |
|
854 global $comments, $comment; |
|
855 |
|
856 $cache = array(); |
|
857 if ( ! $this->is_preview() ) { |
|
858 $cache = wp_cache_get('widget_recent_comments', 'widget'); |
|
859 } |
|
860 if ( ! is_array( $cache ) ) { |
|
861 $cache = array(); |
|
862 } |
|
863 |
|
864 if ( ! isset( $args['widget_id'] ) ) |
|
865 $args['widget_id'] = $this->id; |
|
866 |
|
867 if ( isset( $cache[ $args['widget_id'] ] ) ) { |
|
868 echo $cache[ $args['widget_id'] ]; |
|
869 return; |
|
870 } |
|
871 |
|
872 $output = ''; |
|
873 |
|
874 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' ); |
|
875 |
|
876 /** This filter is documented in wp-includes/default-widgets.php */ |
|
877 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
878 |
|
879 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; |
|
880 if ( ! $number ) |
|
881 $number = 5; |
|
882 |
|
883 /** |
|
884 * Filter the arguments for the Recent Comments widget. |
|
885 * |
|
886 * @since 3.4.0 |
|
887 * |
|
888 * @see WP_Comment_Query::query() for information on accepted arguments. |
|
889 * |
|
890 * @param array $comment_args An array of arguments used to retrieve the recent comments. |
|
891 */ |
|
892 $comments = get_comments( apply_filters( 'widget_comments_args', array( |
|
893 'number' => $number, |
|
894 'status' => 'approve', |
|
895 'post_status' => 'publish' |
|
896 ) ) ); |
|
897 |
|
898 $output .= $args['before_widget']; |
|
899 if ( $title ) { |
|
900 $output .= $args['before_title'] . $title . $args['after_title']; |
|
901 } |
|
902 |
|
903 $output .= '<ul id="recentcomments">'; |
|
904 if ( $comments ) { |
|
905 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) |
|
906 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); |
|
907 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); |
|
908 |
|
909 foreach ( (array) $comments as $comment) { |
|
910 $output .= '<li class="recentcomments">'; |
|
911 /* translators: comments widget: 1: comment author, 2: post link */ |
|
912 $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ), |
|
913 '<span class="comment-author-link">' . get_comment_author_link() . '</span>', |
|
914 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>' |
|
915 ); |
|
916 $output .= '</li>'; |
|
917 } |
|
918 } |
|
919 $output .= '</ul>'; |
|
920 $output .= $args['after_widget']; |
|
921 |
|
922 echo $output; |
|
923 |
|
924 if ( ! $this->is_preview() ) { |
|
925 $cache[ $args['widget_id'] ] = $output; |
|
926 wp_cache_set( 'widget_recent_comments', $cache, 'widget' ); |
|
927 } |
|
928 } |
|
929 |
|
930 public function update( $new_instance, $old_instance ) { |
|
931 $instance = $old_instance; |
|
932 $instance['title'] = strip_tags($new_instance['title']); |
|
933 $instance['number'] = absint( $new_instance['number'] ); |
|
934 $this->flush_widget_cache(); |
|
935 |
|
936 $alloptions = wp_cache_get( 'alloptions', 'options' ); |
|
937 if ( isset($alloptions['widget_recent_comments']) ) |
|
938 delete_option('widget_recent_comments'); |
|
939 |
|
940 return $instance; |
|
941 } |
|
942 |
|
943 public function form( $instance ) { |
|
944 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
945 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; |
|
946 ?> |
|
947 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
|
948 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
949 |
|
950 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label> |
|
951 <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> |
|
952 <?php |
|
953 } |
|
954 } |
|
955 |
|
956 /** |
|
957 * RSS widget class |
|
958 * |
|
959 * @since 2.8.0 |
|
960 */ |
|
961 class WP_Widget_RSS extends WP_Widget { |
|
962 |
|
963 public function __construct() { |
|
964 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') ); |
|
965 $control_ops = array( 'width' => 400, 'height' => 200 ); |
|
966 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops ); |
|
967 } |
|
968 |
|
969 public function widget($args, $instance) { |
|
970 |
|
971 if ( isset($instance['error']) && $instance['error'] ) |
|
972 return; |
|
973 |
|
974 $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; |
|
975 while ( stristr($url, 'http') != $url ) |
|
976 $url = substr($url, 1); |
|
977 |
|
978 if ( empty($url) ) |
|
979 return; |
|
980 |
|
981 // self-url destruction sequence |
|
982 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) |
|
983 return; |
|
984 |
|
985 $rss = fetch_feed($url); |
|
986 $title = $instance['title']; |
|
987 $desc = ''; |
|
988 $link = ''; |
|
989 |
|
990 if ( ! is_wp_error($rss) ) { |
|
991 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); |
|
992 if ( empty($title) ) |
|
993 $title = esc_html(strip_tags($rss->get_title())); |
|
994 $link = esc_url(strip_tags($rss->get_permalink())); |
|
995 while ( stristr($link, 'http') != $link ) |
|
996 $link = substr($link, 1); |
|
997 } |
|
998 |
|
999 if ( empty($title) ) |
|
1000 $title = empty($desc) ? __('Unknown Feed') : $desc; |
|
1001 |
|
1002 /** This filter is documented in wp-includes/default-widgets.php */ |
|
1003 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
1004 |
|
1005 $url = esc_url(strip_tags($url)); |
|
1006 $icon = includes_url('images/rss.png'); |
|
1007 if ( $title ) |
|
1008 $title = "<a class='rsswidget' href='$url'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link'>$title</a>"; |
|
1009 |
|
1010 echo $args['before_widget']; |
|
1011 if ( $title ) { |
|
1012 echo $args['before_title'] . $title . $args['after_title']; |
|
1013 } |
|
1014 wp_widget_rss_output( $rss, $instance ); |
|
1015 echo $args['after_widget']; |
|
1016 |
|
1017 if ( ! is_wp_error($rss) ) |
|
1018 $rss->__destruct(); |
|
1019 unset($rss); |
|
1020 } |
|
1021 |
|
1022 public function update($new_instance, $old_instance) { |
|
1023 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); |
|
1024 return wp_widget_rss_process( $new_instance, $testurl ); |
|
1025 } |
|
1026 |
|
1027 public function form($instance) { |
|
1028 |
|
1029 if ( empty($instance) ) |
|
1030 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 ); |
|
1031 $instance['number'] = $this->number; |
|
1032 |
|
1033 wp_widget_rss_form( $instance ); |
|
1034 } |
|
1035 } |
|
1036 |
|
1037 /** |
|
1038 * Display the RSS entries in a list. |
|
1039 * |
|
1040 * @since 2.5.0 |
|
1041 * |
|
1042 * @param string|array|object $rss RSS url. |
|
1043 * @param array $args Widget arguments. |
|
1044 */ |
|
1045 function wp_widget_rss_output( $rss, $args = array() ) { |
|
1046 if ( is_string( $rss ) ) { |
|
1047 $rss = fetch_feed($rss); |
|
1048 } elseif ( is_array($rss) && isset($rss['url']) ) { |
|
1049 $args = $rss; |
|
1050 $rss = fetch_feed($rss['url']); |
|
1051 } elseif ( !is_object($rss) ) { |
|
1052 return; |
|
1053 } |
|
1054 |
|
1055 if ( is_wp_error($rss) ) { |
|
1056 if ( is_admin() || current_user_can('manage_options') ) |
|
1057 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; |
|
1058 return; |
|
1059 } |
|
1060 |
|
1061 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); |
|
1062 $args = wp_parse_args( $args, $default_args ); |
|
1063 |
|
1064 $items = (int) $args['items']; |
|
1065 if ( $items < 1 || 20 < $items ) |
|
1066 $items = 10; |
|
1067 $show_summary = (int) $args['show_summary']; |
|
1068 $show_author = (int) $args['show_author']; |
|
1069 $show_date = (int) $args['show_date']; |
|
1070 |
|
1071 if ( !$rss->get_item_quantity() ) { |
|
1072 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; |
|
1073 $rss->__destruct(); |
|
1074 unset($rss); |
|
1075 return; |
|
1076 } |
|
1077 |
|
1078 echo '<ul>'; |
|
1079 foreach ( $rss->get_items( 0, $items ) as $item ) { |
|
1080 $link = $item->get_link(); |
|
1081 while ( stristr( $link, 'http' ) != $link ) { |
|
1082 $link = substr( $link, 1 ); |
|
1083 } |
|
1084 $link = esc_url( strip_tags( $link ) ); |
|
1085 |
|
1086 $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); |
|
1087 if ( empty( $title ) ) { |
|
1088 $title = __( 'Untitled' ); |
|
1089 } |
|
1090 |
|
1091 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); |
|
1092 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); |
|
1093 |
|
1094 $summary = ''; |
|
1095 if ( $show_summary ) { |
|
1096 $summary = $desc; |
|
1097 |
|
1098 // Change existing [...] to […]. |
|
1099 if ( '[...]' == substr( $summary, -5 ) ) { |
|
1100 $summary = substr( $summary, 0, -5 ) . '[…]'; |
|
1101 } |
|
1102 |
|
1103 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; |
|
1104 } |
|
1105 |
|
1106 $date = ''; |
|
1107 if ( $show_date ) { |
|
1108 $date = $item->get_date( 'U' ); |
|
1109 |
|
1110 if ( $date ) { |
|
1111 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; |
|
1112 } |
|
1113 } |
|
1114 |
|
1115 $author = ''; |
|
1116 if ( $show_author ) { |
|
1117 $author = $item->get_author(); |
|
1118 if ( is_object($author) ) { |
|
1119 $author = $author->get_name(); |
|
1120 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; |
|
1121 } |
|
1122 } |
|
1123 |
|
1124 if ( $link == '' ) { |
|
1125 echo "<li>$title{$date}{$summary}{$author}</li>"; |
|
1126 } elseif ( $show_summary ) { |
|
1127 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; |
|
1128 } else { |
|
1129 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; |
|
1130 } |
|
1131 } |
|
1132 echo '</ul>'; |
|
1133 $rss->__destruct(); |
|
1134 unset($rss); |
|
1135 } |
|
1136 |
|
1137 /** |
|
1138 * Display RSS widget options form. |
|
1139 * |
|
1140 * The options for what fields are displayed for the RSS form are all booleans |
|
1141 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', |
|
1142 * 'show_date'. |
|
1143 * |
|
1144 * @since 2.5.0 |
|
1145 * |
|
1146 * @param array|string $args Values for input fields. |
|
1147 * @param array $inputs Override default display options. |
|
1148 */ |
|
1149 function wp_widget_rss_form( $args, $inputs = null ) { |
|
1150 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); |
|
1151 $inputs = wp_parse_args( $inputs, $default_inputs ); |
|
1152 |
|
1153 $args['number'] = esc_attr( $args['number'] ); |
|
1154 $args['title'] = isset( $args['title'] ) ? esc_attr( $args['title'] ) : ''; |
|
1155 $args['url'] = isset( $args['url'] ) ? esc_url( $args['url'] ) : ''; |
|
1156 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0; |
|
1157 |
|
1158 if ( $args['items'] < 1 || 20 < $args['items'] ) { |
|
1159 $args['items'] = 10; |
|
1160 } |
|
1161 |
|
1162 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; |
|
1163 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; |
|
1164 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; |
|
1165 |
|
1166 if ( ! empty( $args['error'] ) ) { |
|
1167 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>'; |
|
1168 } |
|
1169 |
|
1170 if ( $inputs['url'] ) : |
|
1171 ?> |
|
1172 <p><label for="rss-url-<?php echo $args['number']; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label> |
|
1173 <input class="widefat" id="rss-url-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][url]" type="text" value="<?php echo $args['url']; ?>" /></p> |
|
1174 <?php endif; if ( $inputs['title'] ) : ?> |
|
1175 <p><label for="rss-title-<?php echo $args['number']; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label> |
|
1176 <input class="widefat" id="rss-title-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][title]" type="text" value="<?php echo $args['title']; ?>" /></p> |
|
1177 <?php endif; if ( $inputs['items'] ) : ?> |
|
1178 <p><label for="rss-items-<?php echo $args['number']; ?>"><?php _e( 'How many items would you like to display?' ); ?></label> |
|
1179 <select id="rss-items-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][items]"> |
|
1180 <?php |
|
1181 for ( $i = 1; $i <= 20; ++$i ) { |
|
1182 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>"; |
|
1183 } |
|
1184 ?> |
|
1185 </select></p> |
|
1186 <?php endif; if ( $inputs['show_summary'] ) : ?> |
|
1187 <p><input id="rss-show-summary-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> /> |
|
1188 <label for="rss-show-summary-<?php echo $args['number']; ?>"><?php _e( 'Display item content?' ); ?></label></p> |
|
1189 <?php endif; if ( $inputs['show_author'] ) : ?> |
|
1190 <p><input id="rss-show-author-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> /> |
|
1191 <label for="rss-show-author-<?php echo $args['number']; ?>"><?php _e( 'Display item author if available?' ); ?></label></p> |
|
1192 <?php endif; if ( $inputs['show_date'] ) : ?> |
|
1193 <p><input id="rss-show-date-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/> |
|
1194 <label for="rss-show-date-<?php echo $args['number']; ?>"><?php _e( 'Display item date?' ); ?></label></p> |
|
1195 <?php |
|
1196 endif; |
|
1197 foreach ( array_keys($default_inputs) as $input ) : |
|
1198 if ( 'hidden' === $inputs[$input] ) : |
|
1199 $id = str_replace( '_', '-', $input ); |
|
1200 ?> |
|
1201 <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][<?php echo $input; ?>]" value="<?php echo $args[ $input ]; ?>" /> |
|
1202 <?php |
|
1203 endif; |
|
1204 endforeach; |
|
1205 } |
|
1206 |
|
1207 /** |
|
1208 * Process RSS feed widget data and optionally retrieve feed items. |
|
1209 * |
|
1210 * The feed widget can not have more than 20 items or it will reset back to the |
|
1211 * default, which is 10. |
|
1212 * |
|
1213 * The resulting array has the feed title, feed url, feed link (from channel), |
|
1214 * feed items, error (if any), and whether to show summary, author, and date. |
|
1215 * All respectively in the order of the array elements. |
|
1216 * |
|
1217 * @since 2.5.0 |
|
1218 * |
|
1219 * @param array $widget_rss RSS widget feed data. Expects unescaped data. |
|
1220 * @param bool $check_feed Optional, default is true. Whether to check feed for errors. |
|
1221 * @return array |
|
1222 */ |
|
1223 function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
|
1224 $items = (int) $widget_rss['items']; |
|
1225 if ( $items < 1 || 20 < $items ) |
|
1226 $items = 10; |
|
1227 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); |
|
1228 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; |
|
1229 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; |
|
1230 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0; |
|
1231 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; |
|
1232 |
|
1233 if ( $check_feed ) { |
|
1234 $rss = fetch_feed($url); |
|
1235 $error = false; |
|
1236 $link = ''; |
|
1237 if ( is_wp_error($rss) ) { |
|
1238 $error = $rss->get_error_message(); |
|
1239 } else { |
|
1240 $link = esc_url(strip_tags($rss->get_permalink())); |
|
1241 while ( stristr($link, 'http') != $link ) |
|
1242 $link = substr($link, 1); |
|
1243 |
|
1244 $rss->__destruct(); |
|
1245 unset($rss); |
|
1246 } |
|
1247 } |
|
1248 |
|
1249 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); |
|
1250 } |
|
1251 |
|
1252 /** |
|
1253 * Tag cloud widget class |
|
1254 * |
|
1255 * @since 2.8.0 |
|
1256 */ |
|
1257 class WP_Widget_Tag_Cloud extends WP_Widget { |
|
1258 |
|
1259 public function __construct() { |
|
1260 $widget_ops = array( 'description' => __( "A cloud of your most used tags.") ); |
|
1261 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops); |
|
1262 } |
|
1263 |
|
1264 public function widget( $args, $instance ) { |
|
1265 $current_taxonomy = $this->_get_current_taxonomy($instance); |
|
1266 if ( !empty($instance['title']) ) { |
|
1267 $title = $instance['title']; |
|
1268 } else { |
|
1269 if ( 'post_tag' == $current_taxonomy ) { |
|
1270 $title = __('Tags'); |
|
1271 } else { |
|
1272 $tax = get_taxonomy($current_taxonomy); |
|
1273 $title = $tax->labels->name; |
|
1274 } |
|
1275 } |
|
1276 |
|
1277 /** This filter is documented in wp-includes/default-widgets.php */ |
|
1278 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
1279 |
|
1280 echo $args['before_widget']; |
|
1281 if ( $title ) { |
|
1282 echo $args['before_title'] . $title . $args['after_title']; |
|
1283 } |
|
1284 echo '<div class="tagcloud">'; |
|
1285 |
|
1286 /** |
|
1287 * Filter the taxonomy used in the Tag Cloud widget. |
|
1288 * |
|
1289 * @since 2.8.0 |
|
1290 * @since 3.0.0 Added taxonomy drop-down. |
|
1291 * |
|
1292 * @see wp_tag_cloud() |
|
1293 * |
|
1294 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'. |
|
1295 */ |
|
1296 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( |
|
1297 'taxonomy' => $current_taxonomy |
|
1298 ) ) ); |
|
1299 |
|
1300 echo "</div>\n"; |
|
1301 echo $args['after_widget']; |
|
1302 } |
|
1303 |
|
1304 public function update( $new_instance, $old_instance ) { |
|
1305 $instance = array(); |
|
1306 $instance['title'] = strip_tags(stripslashes($new_instance['title'])); |
|
1307 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']); |
|
1308 return $instance; |
|
1309 } |
|
1310 |
|
1311 public function form( $instance ) { |
|
1312 $current_taxonomy = $this->_get_current_taxonomy($instance); |
|
1313 ?> |
|
1314 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label> |
|
1315 <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p> |
|
1316 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label> |
|
1317 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>"> |
|
1318 <?php foreach ( get_taxonomies() as $taxonomy ) : |
|
1319 $tax = get_taxonomy($taxonomy); |
|
1320 if ( !$tax->show_tagcloud || empty($tax->labels->name) ) |
|
1321 continue; |
|
1322 ?> |
|
1323 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option> |
|
1324 <?php endforeach; ?> |
|
1325 </select></p><?php |
|
1326 } |
|
1327 |
|
1328 public function _get_current_taxonomy($instance) { |
|
1329 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) |
|
1330 return $instance['taxonomy']; |
|
1331 |
|
1332 return 'post_tag'; |
|
1333 } |
|
1334 } |
|
1335 |
|
1336 /** |
|
1337 * Navigation Menu widget class |
|
1338 * |
|
1339 * @since 3.0.0 |
|
1340 */ |
|
1341 class WP_Nav_Menu_Widget extends WP_Widget { |
|
1342 |
|
1343 public function __construct() { |
|
1344 $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') ); |
|
1345 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops ); |
|
1346 } |
|
1347 |
|
1348 public function widget($args, $instance) { |
|
1349 // Get menu |
|
1350 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; |
|
1351 |
|
1352 if ( !$nav_menu ) |
|
1353 return; |
|
1354 |
|
1355 /** This filter is documented in wp-includes/default-widgets.php */ |
|
1356 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
1357 |
|
1358 echo $args['before_widget']; |
|
1359 |
|
1360 if ( !empty($instance['title']) ) |
|
1361 echo $args['before_title'] . $instance['title'] . $args['after_title']; |
|
1362 |
|
1363 $nav_menu_args = array( |
|
1364 'fallback_cb' => '', |
|
1365 'menu' => $nav_menu |
|
1366 ); |
|
1367 |
|
1368 /** |
|
1369 * Filter the arguments for the Custom Menu widget. |
|
1370 * |
|
1371 * @since 4.2.0 |
|
1372 * |
|
1373 * @param array $nav_menu_args { |
|
1374 * An array of arguments passed to wp_nav_menu() to retrieve a custom menu. |
|
1375 * |
|
1376 * @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty. |
|
1377 * @type mixed $menu Menu ID, slug, or name. |
|
1378 * } |
|
1379 * @param stdClass $nav_menu Nav menu object for the current menu. |
|
1380 * @param array $args Display arguments for the current widget. |
|
1381 */ |
|
1382 wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) ); |
|
1383 |
|
1384 echo $args['after_widget']; |
|
1385 } |
|
1386 |
|
1387 public function update( $new_instance, $old_instance ) { |
|
1388 $instance = array(); |
|
1389 if ( ! empty( $new_instance['title'] ) ) { |
|
1390 $instance['title'] = strip_tags( stripslashes($new_instance['title']) ); |
|
1391 } |
|
1392 if ( ! empty( $new_instance['nav_menu'] ) ) { |
|
1393 $instance['nav_menu'] = (int) $new_instance['nav_menu']; |
|
1394 } |
|
1395 return $instance; |
|
1396 } |
|
1397 |
|
1398 public function form( $instance ) { |
|
1399 $title = isset( $instance['title'] ) ? $instance['title'] : ''; |
|
1400 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; |
|
1401 |
|
1402 // Get menus |
|
1403 $menus = wp_get_nav_menus(); |
|
1404 |
|
1405 // If no menus exists, direct the user to go and create some. |
|
1406 if ( !$menus ) { |
|
1407 echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>'; |
|
1408 return; |
|
1409 } |
|
1410 ?> |
|
1411 <p> |
|
1412 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label> |
|
1413 <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" /> |
|
1414 </p> |
|
1415 <p> |
|
1416 <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label> |
|
1417 <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>"> |
|
1418 <option value="0"><?php _e( '— Select —' ) ?></option> |
|
1419 <?php |
|
1420 foreach ( $menus as $menu ) { |
|
1421 echo '<option value="' . $menu->term_id . '"' |
|
1422 . selected( $nav_menu, $menu->term_id, false ) |
|
1423 . '>'. esc_html( $menu->name ) . '</option>'; |
|
1424 } |
|
1425 ?> |
|
1426 </select> |
|
1427 </p> |
|
1428 <?php |
|
1429 } |
|
1430 } |
|
1431 |
|
1432 /** |
|
1433 * Register all of the default WordPress widgets on startup. |
|
1434 * |
|
1435 * Calls 'widgets_init' action after all of the WordPress widgets have been |
|
1436 * registered. |
|
1437 * |
|
1438 * @since 2.2.0 |
|
1439 */ |
|
1440 function wp_widgets_init() { |
|
1441 if ( !is_blog_installed() ) |
|
1442 return; |
|
1443 |
|
1444 register_widget('WP_Widget_Pages'); |
|
1445 |
|
1446 register_widget('WP_Widget_Calendar'); |
|
1447 |
|
1448 register_widget('WP_Widget_Archives'); |
|
1449 |
|
1450 if ( get_option( 'link_manager_enabled' ) ) |
|
1451 register_widget('WP_Widget_Links'); |
|
1452 |
|
1453 register_widget('WP_Widget_Meta'); |
|
1454 |
|
1455 register_widget('WP_Widget_Search'); |
|
1456 |
|
1457 register_widget('WP_Widget_Text'); |
|
1458 |
|
1459 register_widget('WP_Widget_Categories'); |
|
1460 |
|
1461 register_widget('WP_Widget_Recent_Posts'); |
|
1462 |
|
1463 register_widget('WP_Widget_Recent_Comments'); |
|
1464 |
|
1465 register_widget('WP_Widget_RSS'); |
|
1466 |
|
1467 register_widget('WP_Widget_Tag_Cloud'); |
|
1468 |
|
1469 register_widget('WP_Nav_Menu_Widget'); |
|
1470 |
|
1471 /** |
|
1472 * Fires after all default WordPress widgets have been registered. |
|
1473 * |
|
1474 * @since 2.2.0 |
|
1475 */ |
|
1476 do_action( 'widgets_init' ); |
|
1477 } |
|
1478 |
|
1479 add_action('init', 'wp_widgets_init', 1); |
|