[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
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 ); 37 parent::__construct( 'calendar', __( 'Calendar' ), $widget_ops ); 38 } 39 40 /** 41 * Outputs the content for the current Calendar widget instance. 42 * 43 * @since 2.8.0 44 * 45 * @param array $args Display arguments including 'before_title', 'after_title', 46 * 'before_widget', and 'after_widget'. 47 * @param array $instance The settings for the particular instance of the widget. 48 */ 49 public function widget( $args, $instance ) { 50 $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; 51 52 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ 53 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 54 55 echo $args['before_widget']; 56 if ( $title ) { 57 echo $args['before_title'] . $title . $args['after_title']; 58 } 59 if ( 0 === self::$instance ) { 60 echo '<div id="calendar_wrap" class="calendar_wrap">'; 61 } else { 62 echo '<div class="calendar_wrap">'; 63 } 64 get_calendar(); 65 echo '</div>'; 66 echo $args['after_widget']; 67 68 self::$instance++; 69 } 70 71 /** 72 * Handles updating settings for the current Calendar widget instance. 73 * 74 * @since 2.8.0 75 * 76 * @param array $new_instance New settings for this instance as input by the user via 77 * WP_Widget::form(). 78 * @param array $old_instance Old settings for this instance. 79 * @return array Updated settings to save. 80 */ 81 public function update( $new_instance, $old_instance ) { 82 $instance = $old_instance; 83 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 84 85 return $instance; 86 } 87 88 /** 89 * Outputs the settings form for the Calendar widget. 90 * 91 * @since 2.8.0 92 * 93 * @param array $instance Current settings. 94 */ 95 public function form( $instance ) { 96 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 97 ?> 98 <p> 99 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 100 <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'] ); ?>" /> 101 </p> 102 <?php 103 } 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 22 01:00:03 2021 | Cross-referenced by PHPXref 0.7.1 |