]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/widgets/class-wp-widget-calendar.php
WordPress 4.4
[autoinstalls/wordpress.git] / wp-includes / widgets / class-wp-widget-calendar.php
1 <?php
2 /**
3  * Widget API: WP_Widget_Calendar class
4  *
5  * @package WordPress
6  * @subpackage Widgets
7  * @since 4.4.0
8  */
9
10 /**
11  * Core class used to implement the Calendar widget.
12  *
13  * @since 2.8.0
14  *
15  * @see WP_Widget
16  */
17 class WP_Widget_Calendar extends WP_Widget {
18         /**
19          * Ensure that the ID attribute only appears in the markup once
20          *
21          * @since 4.4.0
22          *
23          * @static
24          * @access private
25          * @var int
26          */
27         private static $instance = 0;
28
29         /**
30          * Sets up a new Calendar widget instance.
31          *
32          * @since 2.8.0
33          * @access public
34          */
35         public function __construct() {
36                 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s Posts.') );
37                 parent::__construct('calendar', __('Calendar'), $widget_ops);
38         }
39
40         /**
41          * Outputs the content for the current Calendar widget instance.
42          *
43          * @since 2.8.0
44          * @access public
45          *
46          * @param array $args     Display arguments including 'before_title', 'after_title',
47          *                        'before_widget', and 'after_widget'.
48          * @param array $instance The settings for the particular instance of the widget.
49          */
50         public function widget( $args, $instance ) {
51                 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
52                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
53
54                 echo $args['before_widget'];
55                 if ( $title ) {
56                         echo $args['before_title'] . $title . $args['after_title'];
57                 }
58                 if ( 0 === self::$instance ) {
59                         echo '<div id="calendar_wrap" class="calendar_wrap">';
60                 } else {
61                         echo '<div class="calendar_wrap">';
62                 }
63                 get_calendar();
64                 echo '</div>';
65                 echo $args['after_widget'];
66
67                 self::$instance++;
68         }
69
70         /**
71          * Handles updating settings for the current Calendar widget instance.
72          *
73          * @since 2.8.0
74          * @access public
75          *
76          * @param array $new_instance New settings for this instance as input by the user via
77          *                            WP_Widget::form().
78          * @param array $old_instance Old settings for this instance.
79          * @return array Updated settings to save.
80          */
81         public function update( $new_instance, $old_instance ) {
82                 $instance = $old_instance;
83                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
84
85                 return $instance;
86         }
87
88         /**
89          * Outputs the settings form for the Calendar widget.
90          *
91          * @since 2.8.0
92          * @access public
93          *
94          * @param array $instance Current settings.
95          */
96         public function form( $instance ) {
97                 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
98                 $title = sanitize_text_field( $instance['title'] );
99                 ?>
100                 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
101                 <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>
102                 <?php
103         }
104 }