[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/widgets/ -> class-wp-widget-calendar.php (source)

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


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref