WP_Widget_Calendar

Core class used to implement the Calendar widget.

Defined (1)

The class is defined in the following location(s).

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