3 * Widget API: WP_Widget_Calendar class
11 * Core class used to implement the Calendar widget.
17 class WP_Widget_Calendar extends WP_Widget {
19 * Ensure that the ID attribute only appears in the markup once
27 private static $instance = 0;
30 * Sets up a new Calendar widget instance.
35 public function __construct() {
37 'classname' => 'widget_calendar',
38 'description' => __( 'A calendar of your site’s Posts.' ),
39 'customize_selective_refresh' => true,
41 parent::__construct( 'calendar', __( 'Calendar' ), $widget_ops );
45 * Outputs the content for the current Calendar widget instance.
50 * @param array $args Display arguments including 'before_title', 'after_title',
51 * 'before_widget', and 'after_widget'.
52 * @param array $instance The settings for the particular instance of the widget.
54 public function widget( $args, $instance ) {
55 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
56 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
58 echo $args['before_widget'];
60 echo $args['before_title'] . $title . $args['after_title'];
62 if ( 0 === self::$instance ) {
63 echo '<div id="calendar_wrap" class="calendar_wrap">';
65 echo '<div class="calendar_wrap">';
69 echo $args['after_widget'];
75 * Handles updating settings for the current Calendar widget instance.
80 * @param array $new_instance New settings for this instance as input by the user via
82 * @param array $old_instance Old settings for this instance.
83 * @return array Updated settings to save.
85 public function update( $new_instance, $old_instance ) {
86 $instance = $old_instance;
87 $instance['title'] = sanitize_text_field( $new_instance['title'] );
93 * Outputs the settings form for the Calendar widget.
98 * @param array $instance Current settings.
100 public function form( $instance ) {
101 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
102 $title = sanitize_text_field( $instance['title'] );
104 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
105 <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>