home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-includes / widgets / class-wp-widget-calendar.php < prev    next >
Encoding:
PHP Script  |  2017-10-15  |  2.8 KB  |  106 lines

  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.      * @var int
  25.      */
  26.     private static $instance = 0;
  27.  
  28.     /**
  29.      * Sets up a new Calendar widget instance.
  30.      *
  31.      * @since 2.8.0
  32.      */
  33.     public function __construct() {
  34.         $widget_ops = array(
  35.             'classname' => 'widget_calendar',
  36.             'description' => __( 'A calendar of your site’s Posts.' ),
  37.             'customize_selective_refresh' => true,
  38.         );
  39.         parent::__construct( 'calendar', __( 'Calendar' ), $widget_ops );
  40.     }
  41.  
  42.     /**
  43.      * Outputs the content for the current Calendar widget instance.
  44.      *
  45.      * @since 2.8.0
  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.         $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
  53.  
  54.         /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
  55.         $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  56.  
  57.         echo $args['before_widget'];
  58.         if ( $title ) {
  59.             echo $args['before_title'] . $title . $args['after_title'];
  60.         }
  61.         if ( 0 === self::$instance ) {
  62.             echo '<div id="calendar_wrap" class="calendar_wrap">';
  63.         } else {
  64.             echo '<div class="calendar_wrap">';
  65.         }
  66.         get_calendar();
  67.         echo '</div>';
  68.         echo $args['after_widget'];
  69.  
  70.         self::$instance++;
  71.     }
  72.  
  73.     /**
  74.      * Handles updating settings for the current Calendar widget instance.
  75.      *
  76.      * @since 2.8.0
  77.      *
  78.      * @param array $new_instance New settings for this instance as input by the user via
  79.      *                            WP_Widget::form().
  80.      * @param array $old_instance Old settings for this instance.
  81.      * @return array Updated settings to save.
  82.      */
  83.     public function update( $new_instance, $old_instance ) {
  84.         $instance = $old_instance;
  85.         $instance['title'] = sanitize_text_field( $new_instance['title'] );
  86.  
  87.         return $instance;
  88.     }
  89.  
  90.     /**
  91.      * Outputs the settings form for the Calendar widget.
  92.      *
  93.      * @since 2.8.0
  94.      *
  95.      * @param array $instance Current settings.
  96.      */
  97.     public function form( $instance ) {
  98.         $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  99.         $title = sanitize_text_field( $instance['title'] );
  100.         ?>
  101.         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  102.         <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>
  103.         <?php
  104.     }
  105. }
  106.