You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

109 lines
2.9 KiB

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