PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/default-widgets.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 1158 lines | 834 code | 194 blank | 130 comment | 119 complexity | 2e0df0bc8a8e88b1af79958a1f80601d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Default Widgets
  4. *
  5. * @package WordPress
  6. * @subpackage Widgets
  7. */
  8. /**
  9. * Pages widget class
  10. *
  11. * @since 2.8.0
  12. */
  13. class WP_Widget_Pages extends WP_Widget {
  14. function __construct() {
  15. $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site&#8217;s WordPress Pages') );
  16. parent::__construct('pages', __('Pages'), $widget_ops);
  17. }
  18. function widget( $args, $instance ) {
  19. extract( $args );
  20. $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base);
  21. $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
  22. $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
  23. if ( $sortby == 'menu_order' )
  24. $sortby = 'menu_order, post_title';
  25. $out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) );
  26. if ( !empty( $out ) ) {
  27. echo $before_widget;
  28. if ( $title)
  29. echo $before_title . $title . $after_title;
  30. ?>
  31. <ul>
  32. <?php echo $out; ?>
  33. </ul>
  34. <?php
  35. echo $after_widget;
  36. }
  37. }
  38. function update( $new_instance, $old_instance ) {
  39. $instance = $old_instance;
  40. $instance['title'] = strip_tags($new_instance['title']);
  41. if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
  42. $instance['sortby'] = $new_instance['sortby'];
  43. } else {
  44. $instance['sortby'] = 'menu_order';
  45. }
  46. $instance['exclude'] = strip_tags( $new_instance['exclude'] );
  47. return $instance;
  48. }
  49. function form( $instance ) {
  50. //Defaults
  51. $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
  52. $title = esc_attr( $instance['title'] );
  53. $exclude = esc_attr( $instance['exclude'] );
  54. ?>
  55. <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>
  56. <p>
  57. <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label>
  58. <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
  59. <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
  60. <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
  61. <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
  62. </select>
  63. </p>
  64. <p>
  65. <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" />
  66. <br />
  67. <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
  68. </p>
  69. <?php
  70. }
  71. }
  72. /**
  73. * Links widget class
  74. *
  75. * @since 2.8.0
  76. */
  77. class WP_Widget_Links extends WP_Widget {
  78. function __construct() {
  79. $widget_ops = array('description' => __( "Your blogroll" ) );
  80. parent::__construct('links', __('Links'), $widget_ops);
  81. }
  82. function widget( $args, $instance ) {
  83. extract($args, EXTR_SKIP);
  84. $show_description = isset($instance['description']) ? $instance['description'] : false;
  85. $show_name = isset($instance['name']) ? $instance['name'] : false;
  86. $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
  87. $show_images = isset($instance['images']) ? $instance['images'] : true;
  88. $category = isset($instance['category']) ? $instance['category'] : false;
  89. if ( is_admin() && !$category ) {
  90. // Display All Links widget as such in the widgets screen
  91. echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget;
  92. return;
  93. }
  94. $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
  95. wp_list_bookmarks(apply_filters('widget_links_args', array(
  96. 'title_before' => $before_title, 'title_after' => $after_title,
  97. 'category_before' => $before_widget, 'category_after' => $after_widget,
  98. 'show_images' => $show_images, 'show_description' => $show_description,
  99. 'show_name' => $show_name, 'show_rating' => $show_rating,
  100. 'category' => $category, 'class' => 'linkcat widget'
  101. )));
  102. }
  103. function update( $new_instance, $old_instance ) {
  104. $new_instance = (array) $new_instance;
  105. $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
  106. foreach ( $instance as $field => $val ) {
  107. if ( isset($new_instance[$field]) )
  108. $instance[$field] = 1;
  109. }
  110. $instance['category'] = intval($new_instance['category']);
  111. return $instance;
  112. }
  113. function form( $instance ) {
  114. //Defaults
  115. $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
  116. $link_cats = get_terms( 'link_category');
  117. ?>
  118. <p>
  119. <label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
  120. <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
  121. <option value=""><?php _e('All Links'); ?></option>
  122. <?php
  123. foreach ( $link_cats as $link_cat ) {
  124. echo '<option value="' . intval($link_cat->term_id) . '"'
  125. . ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
  126. . '>' . $link_cat->name . "</option>\n";
  127. }
  128. ?>
  129. </select></p>
  130. <p>
  131. <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'); ?>" />
  132. <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
  133. <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'); ?>" />
  134. <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
  135. <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'); ?>" />
  136. <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
  137. <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'); ?>" />
  138. <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
  139. </p>
  140. <?php
  141. }
  142. }
  143. /**
  144. * Search widget class
  145. *
  146. * @since 2.8.0
  147. */
  148. class WP_Widget_Search extends WP_Widget {
  149. function __construct() {
  150. $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
  151. parent::__construct('search', __('Search'), $widget_ops);
  152. }
  153. function widget( $args, $instance ) {
  154. extract($args);
  155. $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
  156. echo $before_widget;
  157. if ( $title )
  158. echo $before_title . $title . $after_title;
  159. // Use current theme search form if it exists
  160. get_search_form();
  161. echo $after_widget;
  162. }
  163. function form( $instance ) {
  164. $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
  165. $title = $instance['title'];
  166. ?>
  167. <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>
  168. <?php
  169. }
  170. function update( $new_instance, $old_instance ) {
  171. $instance = $old_instance;
  172. $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
  173. $instance['title'] = strip_tags($new_instance['title']);
  174. return $instance;
  175. }
  176. }
  177. /**
  178. * Archives widget class
  179. *
  180. * @since 2.8.0
  181. */
  182. class WP_Widget_Archives extends WP_Widget {
  183. function __construct() {
  184. $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site&#8217;s posts') );
  185. parent::__construct('archives', __('Archives'), $widget_ops);
  186. }
  187. function widget( $args, $instance ) {
  188. extract($args);
  189. $c = $instance['count'] ? '1' : '0';
  190. $d = $instance['dropdown'] ? '1' : '0';
  191. $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
  192. echo $before_widget;
  193. if ( $title )
  194. echo $before_title . $title . $after_title;
  195. if ( $d ) {
  196. ?>
  197. <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__('Select Month')); ?></option> <?php wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select>
  198. <?php
  199. } else {
  200. ?>
  201. <ul>
  202. <?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
  203. </ul>
  204. <?php
  205. }
  206. echo $after_widget;
  207. }
  208. function update( $new_instance, $old_instance ) {
  209. $instance = $old_instance;
  210. $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
  211. $instance['title'] = strip_tags($new_instance['title']);
  212. $instance['count'] = $new_instance['count'] ? 1 : 0;
  213. $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
  214. return $instance;
  215. }
  216. function form( $instance ) {
  217. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
  218. $title = strip_tags($instance['title']);
  219. $count = $instance['count'] ? 'checked="checked"' : '';
  220. $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
  221. ?>
  222. <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>
  223. <p>
  224. <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>
  225. <br/>
  226. <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>
  227. </p>
  228. <?php
  229. }
  230. }
  231. /**
  232. * Meta widget class
  233. *
  234. * Displays log in/out, RSS feed links, etc.
  235. *
  236. * @since 2.8.0
  237. */
  238. class WP_Widget_Meta extends WP_Widget {
  239. function __construct() {
  240. $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
  241. parent::__construct('meta', __('Meta'), $widget_ops);
  242. }
  243. function widget( $args, $instance ) {
  244. extract($args);
  245. $title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
  246. echo $before_widget;
  247. if ( $title )
  248. echo $before_title . $title . $after_title;
  249. ?>
  250. <ul>
  251. <?php wp_register(); ?>
  252. <li><?php wp_loginout(); ?></li>
  253. <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
  254. <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
  255. <li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
  256. <?php wp_meta(); ?>
  257. </ul>
  258. <?php
  259. echo $after_widget;
  260. }
  261. function update( $new_instance, $old_instance ) {
  262. $instance = $old_instance;
  263. $instance['title'] = strip_tags($new_instance['title']);
  264. return $instance;
  265. }
  266. function form( $instance ) {
  267. $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  268. $title = strip_tags($instance['title']);
  269. ?>
  270. <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>
  271. <?php
  272. }
  273. }
  274. /**
  275. * Calendar widget class
  276. *
  277. * @since 2.8.0
  278. */
  279. class WP_Widget_Calendar extends WP_Widget {
  280. function __construct() {
  281. $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s posts') );
  282. parent::__construct('calendar', __('Calendar'), $widget_ops);
  283. }
  284. function widget( $args, $instance ) {
  285. extract($args);
  286. $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
  287. echo $before_widget;
  288. if ( $title )
  289. echo $before_title . $title . $after_title;
  290. echo '<div id="calendar_wrap">';
  291. get_calendar();
  292. echo '</div>';
  293. echo $after_widget;
  294. }
  295. function update( $new_instance, $old_instance ) {
  296. $instance = $old_instance;
  297. $instance['title'] = strip_tags($new_instance['title']);
  298. return $instance;
  299. }
  300. function form( $instance ) {
  301. $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  302. $title = strip_tags($instance['title']);
  303. ?>
  304. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  305. <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>
  306. <?php
  307. }
  308. }
  309. /**
  310. * Text widget class
  311. *
  312. * @since 2.8.0
  313. */
  314. class WP_Widget_Text extends WP_Widget {
  315. function __construct() {
  316. $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
  317. $control_ops = array('width' => 400, 'height' => 350);
  318. parent::__construct('text', __('Text'), $widget_ops, $control_ops);
  319. }
  320. function widget( $args, $instance ) {
  321. extract($args);
  322. $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
  323. $text = apply_filters( 'widget_text', $instance['text'], $instance );
  324. echo $before_widget;
  325. if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
  326. <div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
  327. <?php
  328. echo $after_widget;
  329. }
  330. function update( $new_instance, $old_instance ) {
  331. $instance = $old_instance;
  332. $instance['title'] = strip_tags($new_instance['title']);
  333. if ( current_user_can('unfiltered_html') )
  334. $instance['text'] = $new_instance['text'];
  335. else
  336. $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
  337. $instance['filter'] = isset($new_instance['filter']);
  338. return $instance;
  339. }
  340. function form( $instance ) {
  341. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
  342. $title = strip_tags($instance['title']);
  343. $text = esc_textarea($instance['text']);
  344. ?>
  345. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  346. <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>
  347. <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>
  348. <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); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
  349. <?php
  350. }
  351. }
  352. /**
  353. * Categories widget class
  354. *
  355. * @since 2.8.0
  356. */
  357. class WP_Widget_Categories extends WP_Widget {
  358. function __construct() {
  359. $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
  360. parent::__construct('categories', __('Categories'), $widget_ops);
  361. }
  362. function widget( $args, $instance ) {
  363. extract( $args );
  364. $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
  365. $c = $instance['count'] ? '1' : '0';
  366. $h = $instance['hierarchical'] ? '1' : '0';
  367. $d = $instance['dropdown'] ? '1' : '0';
  368. echo $before_widget;
  369. if ( $title )
  370. echo $before_title . $title . $after_title;
  371. $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
  372. if ( $d ) {
  373. $cat_args['show_option_none'] = __('Select Category');
  374. wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
  375. ?>
  376. <script type='text/javascript'>
  377. /* <![CDATA[ */
  378. var dropdown = document.getElementById("cat");
  379. function onCatChange() {
  380. if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
  381. location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
  382. }
  383. }
  384. dropdown.onchange = onCatChange;
  385. /* ]]> */
  386. </script>
  387. <?php
  388. } else {
  389. ?>
  390. <ul>
  391. <?php
  392. $cat_args['title_li'] = '';
  393. wp_list_categories(apply_filters('widget_categories_args', $cat_args));
  394. ?>
  395. </ul>
  396. <?php
  397. }
  398. echo $after_widget;
  399. }
  400. function update( $new_instance, $old_instance ) {
  401. $instance = $old_instance;
  402. $instance['title'] = strip_tags($new_instance['title']);
  403. $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
  404. $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
  405. $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
  406. return $instance;
  407. }
  408. function form( $instance ) {
  409. //Defaults
  410. $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
  411. $title = esc_attr( $instance['title'] );
  412. $count = isset($instance['count']) ? (bool) $instance['count'] :false;
  413. $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
  414. $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
  415. ?>
  416. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
  417. <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>
  418. <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 ); ?> />
  419. <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
  420. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
  421. <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
  422. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
  423. <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
  424. <?php
  425. }
  426. }
  427. /**
  428. * Recent_Posts widget class
  429. *
  430. * @since 2.8.0
  431. */
  432. class WP_Widget_Recent_Posts extends WP_Widget {
  433. function __construct() {
  434. $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
  435. parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
  436. $this->alt_option_name = 'widget_recent_entries';
  437. add_action( 'save_post', array(&$this, 'flush_widget_cache') );
  438. add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
  439. add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
  440. }
  441. function widget($args, $instance) {
  442. $cache = wp_cache_get('widget_recent_posts', 'widget');
  443. if ( !is_array($cache) )
  444. $cache = array();
  445. if ( isset($cache[$args['widget_id']]) ) {
  446. echo $cache[$args['widget_id']];
  447. return;
  448. }
  449. ob_start();
  450. extract($args);
  451. $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
  452. if ( ! $number = absint( $instance['number'] ) )
  453. $number = 10;
  454. $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
  455. if ($r->have_posts()) :
  456. ?>
  457. <?php echo $before_widget; ?>
  458. <?php if ( $title ) echo $before_title . $title . $after_title; ?>
  459. <ul>
  460. <?php while ($r->have_posts()) : $r->the_post(); ?>
  461. <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
  462. <?php endwhile; ?>
  463. </ul>
  464. <?php echo $after_widget; ?>
  465. <?php
  466. // Reset the global $the_post as this query will have stomped on it
  467. wp_reset_postdata();
  468. endif;
  469. $cache[$args['widget_id']] = ob_get_flush();
  470. wp_cache_set('widget_recent_posts', $cache, 'widget');
  471. }
  472. function update( $new_instance, $old_instance ) {
  473. $instance = $old_instance;
  474. $instance['title'] = strip_tags($new_instance['title']);
  475. $instance['number'] = (int) $new_instance['number'];
  476. $this->flush_widget_cache();
  477. $alloptions = wp_cache_get( 'alloptions', 'options' );
  478. if ( isset($alloptions['widget_recent_entries']) )
  479. delete_option('widget_recent_entries');
  480. return $instance;
  481. }
  482. function flush_widget_cache() {
  483. wp_cache_delete('widget_recent_posts', 'widget');
  484. }
  485. function form( $instance ) {
  486. $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
  487. $number = isset($instance['number']) ? absint($instance['number']) : 5;
  488. ?>
  489. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  490. <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>
  491. <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
  492. <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>
  493. <?php
  494. }
  495. }
  496. /**
  497. * Recent_Comments widget class
  498. *
  499. * @since 2.8.0
  500. */
  501. class WP_Widget_Recent_Comments extends WP_Widget {
  502. function __construct() {
  503. $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
  504. parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
  505. $this->alt_option_name = 'widget_recent_comments';
  506. if ( is_active_widget(false, false, $this->id_base) )
  507. add_action( 'wp_head', array(&$this, 'recent_comments_style') );
  508. add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
  509. add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
  510. }
  511. function recent_comments_style() {
  512. if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
  513. || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
  514. return;
  515. ?>
  516. <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
  517. <?php
  518. }
  519. function flush_widget_cache() {
  520. wp_cache_delete('widget_recent_comments', 'widget');
  521. }
  522. function widget( $args, $instance ) {
  523. global $comments, $comment;
  524. $cache = wp_cache_get('widget_recent_comments', 'widget');
  525. if ( ! is_array( $cache ) )
  526. $cache = array();
  527. if ( isset( $cache[$args['widget_id']] ) ) {
  528. echo $cache[$args['widget_id']];
  529. return;
  530. }
  531. extract($args, EXTR_SKIP);
  532. $output = '';
  533. $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
  534. if ( ! $number = absint( $instance['number'] ) )
  535. $number = 5;
  536. $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) );
  537. $output .= $before_widget;
  538. if ( $title )
  539. $output .= $before_title . $title . $after_title;
  540. $output .= '<ul id="recentcomments">';
  541. if ( $comments ) {
  542. foreach ( (array) $comments as $comment) {
  543. $output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
  544. }
  545. }
  546. $output .= '</ul>';
  547. $output .= $after_widget;
  548. echo $output;
  549. $cache[$args['widget_id']] = $output;
  550. wp_cache_set('widget_recent_comments', $cache, 'widget');
  551. }
  552. function update( $new_instance, $old_instance ) {
  553. $instance = $old_instance;
  554. $instance['title'] = strip_tags($new_instance['title']);
  555. $instance['number'] = absint( $new_instance['number'] );
  556. $this->flush_widget_cache();
  557. $alloptions = wp_cache_get( 'alloptions', 'options' );
  558. if ( isset($alloptions['widget_recent_comments']) )
  559. delete_option('widget_recent_comments');
  560. return $instance;
  561. }
  562. function form( $instance ) {
  563. $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
  564. $number = isset($instance['number']) ? absint($instance['number']) : 5;
  565. ?>
  566. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  567. <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>
  568. <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label>
  569. <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>
  570. <?php
  571. }
  572. }
  573. /**
  574. * RSS widget class
  575. *
  576. * @since 2.8.0
  577. */
  578. class WP_Widget_RSS extends WP_Widget {
  579. function __construct() {
  580. $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
  581. $control_ops = array( 'width' => 400, 'height' => 200 );
  582. parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
  583. }
  584. function widget($args, $instance) {
  585. if ( isset($instance['error']) && $instance['error'] )
  586. return;
  587. extract($args, EXTR_SKIP);
  588. $url = $instance['url'];
  589. while ( stristr($url, 'http') != $url )
  590. $url = substr($url, 1);
  591. if ( empty($url) )
  592. return;
  593. // self-url destruction sequence
  594. if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
  595. return;
  596. $rss = fetch_feed($url);
  597. $title = $instance['title'];
  598. $desc = '';
  599. $link = '';
  600. if ( ! is_wp_error($rss) ) {
  601. $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
  602. if ( empty($title) )
  603. $title = esc_html(strip_tags($rss->get_title()));
  604. $link = esc_url(strip_tags($rss->get_permalink()));
  605. while ( stristr($link, 'http') != $link )
  606. $link = substr($link, 1);
  607. }
  608. if ( empty($title) )
  609. $title = empty($desc) ? __('Unknown Feed') : $desc;
  610. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  611. $url = esc_url(strip_tags($url));
  612. $icon = includes_url('images/rss.png');
  613. if ( $title )
  614. $title = "<a class='rsswidget' href='$url' title='" . esc_attr__( 'Syndicate this content' ) ."'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
  615. echo $before_widget;
  616. if ( $title )
  617. echo $before_title . $title . $after_title;
  618. wp_widget_rss_output( $rss, $instance );
  619. echo $after_widget;
  620. if ( ! is_wp_error($rss) )
  621. $rss->__destruct();
  622. unset($rss);
  623. }
  624. function update($new_instance, $old_instance) {
  625. $testurl = ( isset($new_instance['url']) && ($new_instance['url'] != $old_instance['url']) );
  626. return wp_widget_rss_process( $new_instance, $testurl );
  627. }
  628. function form($instance) {
  629. if ( empty($instance) )
  630. $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
  631. $instance['number'] = $this->number;
  632. wp_widget_rss_form( $instance );
  633. }
  634. }
  635. /**
  636. * Display the RSS entries in a list.
  637. *
  638. * @since 2.5.0
  639. *
  640. * @param string|array|object $rss RSS url.
  641. * @param array $args Widget arguments.
  642. */
  643. function wp_widget_rss_output( $rss, $args = array() ) {
  644. if ( is_string( $rss ) ) {
  645. $rss = fetch_feed($rss);
  646. } elseif ( is_array($rss) && isset($rss['url']) ) {
  647. $args = $rss;
  648. $rss = fetch_feed($rss['url']);
  649. } elseif ( !is_object($rss) ) {
  650. return;
  651. }
  652. if ( is_wp_error($rss) ) {
  653. if ( is_admin() || current_user_can('manage_options') )
  654. echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
  655. return;
  656. }
  657. $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
  658. $args = wp_parse_args( $args, $default_args );
  659. extract( $args, EXTR_SKIP );
  660. $items = (int) $items;
  661. if ( $items < 1 || 20 < $items )
  662. $items = 10;
  663. $show_summary = (int) $show_summary;
  664. $show_author = (int) $show_author;
  665. $show_date = (int) $show_date;
  666. if ( !$rss->get_item_quantity() ) {
  667. echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
  668. $rss->__destruct();
  669. unset($rss);
  670. return;
  671. }
  672. echo '<ul>';
  673. foreach ( $rss->get_items(0, $items) as $item ) {
  674. $link = $item->get_link();
  675. while ( stristr($link, 'http') != $link )
  676. $link = substr($link, 1);
  677. $link = esc_url(strip_tags($link));
  678. $title = esc_attr(strip_tags($item->get_title()));
  679. if ( empty($title) )
  680. $title = __('Untitled');
  681. $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
  682. $desc = wp_html_excerpt( $desc, 360 );
  683. // Append ellipsis. Change existing [...] to [&hellip;].
  684. if ( '[...]' == substr( $desc, -5 ) )
  685. $desc = substr( $desc, 0, -5 ) . '[&hellip;]';
  686. elseif ( '[&hellip;]' != substr( $desc, -10 ) )
  687. $desc .= ' [&hellip;]';
  688. $desc = esc_html( $desc );
  689. if ( $show_summary ) {
  690. $summary = "<div class='rssSummary'>$desc</div>";
  691. } else {
  692. $summary = '';
  693. }
  694. $date = '';
  695. if ( $show_date ) {
  696. $date = $item->get_date( 'U' );
  697. if ( $date ) {
  698. $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
  699. }
  700. }
  701. $author = '';
  702. if ( $show_author ) {
  703. $author = $item->get_author();
  704. if ( is_object($author) ) {
  705. $author = $author->get_name();
  706. $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
  707. }
  708. }
  709. if ( $link == '' ) {
  710. echo "<li>$title{$date}{$summary}{$author}</li>";
  711. } else {
  712. echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
  713. }
  714. }
  715. echo '</ul>';
  716. $rss->__destruct();
  717. unset($rss);
  718. }
  719. /**
  720. * Display RSS widget options form.
  721. *
  722. * The options for what fields are displayed for the RSS form are all booleans
  723. * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
  724. * 'show_date'.
  725. *
  726. * @since 2.5.0
  727. *
  728. * @param array|string $args Values for input fields.
  729. * @param array $inputs Override default display options.
  730. */
  731. function wp_widget_rss_form( $args, $inputs = null ) {
  732. $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
  733. $inputs = wp_parse_args( $inputs, $default_inputs );
  734. extract( $args );
  735. extract( $inputs, EXTR_SKIP);
  736. $number = esc_attr( $number );
  737. $title = esc_attr( $title );
  738. $url = esc_url( $url );
  739. $items = (int) $items;
  740. if ( $items < 1 || 20 < $items )
  741. $items = 10;
  742. $show_summary = (int) $show_summary;
  743. $show_author = (int) $show_author;
  744. $show_date = (int) $show_date;
  745. if ( !empty($error) )
  746. echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';
  747. if ( $inputs['url'] ) :
  748. ?>
  749. <p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
  750. <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
  751. <?php endif; if ( $inputs['title'] ) : ?>
  752. <p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
  753. <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
  754. <?php endif; if ( $inputs['items'] ) : ?>
  755. <p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
  756. <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
  757. <?php
  758. for ( $i = 1; $i <= 20; ++$i )
  759. echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
  760. ?>
  761. </select></p>
  762. <?php endif; if ( $inputs['show_summary'] ) : ?>
  763. <p><input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
  764. <label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
  765. <?php endif; if ( $inputs['show_author'] ) : ?>
  766. <p><input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
  767. <label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>
  768. <?php endif; if ( $inputs['show_date'] ) : ?>
  769. <p><input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
  770. <label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>
  771. <?php
  772. endif;
  773. foreach ( array_keys($default_inputs) as $input ) :
  774. if ( 'hidden' === $inputs[$input] ) :
  775. $id = str_replace( '_', '-', $input );
  776. ?>
  777. <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
  778. <?php
  779. endif;
  780. endforeach;
  781. }
  782. /**
  783. * Process RSS feed widget data and optionally retrieve feed items.
  784. *
  785. * The feed widget can not have more than 20 items or it will reset back to the
  786. * default, which is 10.
  787. *
  788. * The resulting array has the feed title, feed url, feed link (from channel),
  789. * feed items, error (if any), and whether to show summary, author, and date.
  790. * All respectively in the order of the array elements.
  791. *
  792. * @since 2.5.0
  793. *
  794. * @param array $widget_rss RSS widget feed data. Expects unescaped data.
  795. * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
  796. * @return array
  797. */
  798. function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
  799. $items = (int) $widget_rss['items'];
  800. if ( $items < 1 || 20 < $items )
  801. $items = 10;
  802. $url = esc_url_raw(strip_tags( $widget_rss['url'] ));
  803. $title = trim(strip_tags( $widget_rss['title'] ));
  804. $show_summary = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;
  805. $show_author = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;
  806. $show_date = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;
  807. if ( $check_feed ) {
  808. $rss = fetch_feed($url);
  809. $error = false;
  810. $link = '';
  811. if ( is_wp_error($rss) ) {
  812. $error = $rss->get_error_message();
  813. } else {
  814. $link = esc_url(strip_tags($rss->get_permalink()));
  815. while ( stristr($link, 'http') != $link )
  816. $link = substr($link, 1);
  817. $rss->__destruct();
  818. unset($rss);
  819. }
  820. }
  821. return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
  822. }
  823. /**
  824. * Tag cloud widget class
  825. *
  826. * @since 2.8.0
  827. */
  828. class WP_Widget_Tag_Cloud extends WP_Widget {
  829. function __construct() {
  830. $widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
  831. parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
  832. }
  833. function widget( $args, $instance ) {
  834. extract($args);
  835. $current_taxonomy = $this->_get_current_taxonomy($instance);
  836. if ( !empty($instance['title']) ) {
  837. $title = $instance['title'];
  838. } else {
  839. if ( 'post_tag' == $current_taxonomy ) {
  840. $title = __('Tags');
  841. } else {
  842. $tax = get_taxonomy($current_taxonomy);
  843. $title = $tax->labels->name;
  844. }
  845. }
  846. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  847. echo $before_widget;
  848. if ( $title )
  849. echo $before_title . $title . $after_title;
  850. echo '<div class="tagcloud">';
  851. wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
  852. echo "</div>\n";
  853. echo $after_widget;
  854. }
  855. function update( $new_instance, $old_instance ) {
  856. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  857. $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
  858. return $instance;
  859. }
  860. function form( $instance ) {
  861. $current_taxonomy = $this->_get_current_taxonomy($instance);
  862. ?>
  863. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  864. <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>
  865. <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
  866. <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
  867. <?php foreach ( get_object_taxonomies('post') as $taxonomy ) :
  868. $tax = get_taxonomy($taxonomy);
  869. if ( !$tax->show_tagcloud || empty($tax->labels->name) )
  870. continue;
  871. ?>
  872. <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
  873. <?php endforeach; ?>
  874. </select></p><?php
  875. }
  876. function _get_current_taxonomy($instance) {
  877. if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
  878. return $instance['taxonomy'];
  879. return 'post_tag';
  880. }
  881. }
  882. /**
  883. * Navigation Menu widget class
  884. *
  885. * @since 3.0.0
  886. */
  887. class WP_Nav_Menu_Widget extends WP_Widget {
  888. function __construct() {
  889. $widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
  890. parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
  891. }
  892. function widget($args, $instance) {
  893. // Get menu
  894. $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
  895. if ( !$nav_menu )
  896. return;
  897. $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
  898. echo $args['before_widget'];
  899. if ( !empty($instance['title']) )
  900. echo $args['before_title'] . $instance['title'] . $args['after_title'];
  901. wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
  902. echo $args['after_widget'];
  903. }
  904. function update( $new_instance, $old_instance ) {
  905. $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
  906. $instance['nav_menu'] = (int) $new_instance['nav_menu'];
  907. return $instance;
  908. }
  909. function form( $instance ) {
  910. $title = isset( $instance['title'] ) ? $instance['title'] : '';
  911. $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
  912. // Get menus
  913. $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
  914. // If no menus exists, direct the user to go and create some.
  915. if ( !$menus ) {
  916. echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
  917. return;
  918. }
  919. ?>
  920. <p>
  921. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  922. <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; ?>" />
  923. </p>
  924. <p>
  925. <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  926. <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
  927. <?php
  928. foreach ( $menus as $menu ) {
  929. $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
  930. echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
  931. }
  932. ?>
  933. </select>
  934. </p>
  935. <?php
  936. }
  937. }
  938. /**
  939. * Register all of the default WordPress widgets on startup.
  940. *
  941. * Calls 'widgets_init' action after all of the WordPress widgets have been
  942. * registered.
  943. *
  944. * @since 2.2.0
  945. */
  946. function wp_widgets_init() {
  947. if ( !is_blog_installed() )
  948. return;
  949. register_widget('WP_Widget_Pages');
  950. register_widget('WP_Widget_Calendar');
  951. register_widget('WP_Widget_Archives');
  952. register_widget('WP_Widget_Links');
  953. register_widget('WP_Widget_Meta');
  954. register_widget('WP_Widget_Search');
  955. register_widget('WP_Widget_Text');
  956. register_widget('WP_Widget_Categories');
  957. register_widget('WP_Widget_Recent_Posts');
  958. register_widget('WP_Widget_Recent_Comments');
  959. register_widget('WP_Widget_RSS');
  960. register_widget('WP_Widget_Tag_Cloud');
  961. register_widget('WP_Nav_Menu_Widget');
  962. do_action('widgets_init');
  963. }
  964. add_action('init', 'wp_widgets_init', 1);