Docs: Improve documentation for the __construct()
, widget()
, update()
, and form()
methods in WP_Widget_Archives
.
Props leemon. Fixes #34016. See #34013. git-svn-id: https://develop.svn.wordpress.org/trunk@34620 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9909c7ff2b
commit
982d5b99ea
@ -16,14 +16,26 @@
|
|||||||
*/
|
*/
|
||||||
class WP_Widget_Archives extends WP_Widget {
|
class WP_Widget_Archives extends WP_Widget {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up a new Archives widget instance.
|
||||||
|
*
|
||||||
|
* @since 2.8.0
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') );
|
$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') );
|
||||||
parent::__construct('archives', __('Archives'), $widget_ops);
|
parent::__construct('archives', __('Archives'), $widget_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $args
|
* Outputs the content for the current Archives widget instance.
|
||||||
* @param array $instance
|
*
|
||||||
|
* @since 2.8.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param array $args Display arguments including 'before_title', 'after_title',
|
||||||
|
* 'before_widget', and 'after_widget'.
|
||||||
|
* @param array $instance Settings for the current Archives widget instance.
|
||||||
*/
|
*/
|
||||||
public function widget( $args, $instance ) {
|
public function widget( $args, $instance ) {
|
||||||
$c = ! empty( $instance['count'] ) ? '1' : '0';
|
$c = ! empty( $instance['count'] ) ? '1' : '0';
|
||||||
@ -39,7 +51,7 @@ class WP_Widget_Archives extends WP_Widget {
|
|||||||
|
|
||||||
if ( $d ) {
|
if ( $d ) {
|
||||||
$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
|
$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
|
||||||
?>
|
?>
|
||||||
<label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
|
<label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
|
||||||
<select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
|
<select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
|
||||||
<?php
|
<?php
|
||||||
@ -81,11 +93,9 @@ class WP_Widget_Archives extends WP_Widget {
|
|||||||
<?php wp_get_archives( $dropdown_args ); ?>
|
<?php wp_get_archives( $dropdown_args ); ?>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
<?php
|
<?php } else { ?>
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<ul>
|
<ul>
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Filter the arguments for the Archives widget.
|
* Filter the arguments for the Archives widget.
|
||||||
*
|
*
|
||||||
@ -99,18 +109,24 @@ class WP_Widget_Archives extends WP_Widget {
|
|||||||
'type' => 'monthly',
|
'type' => 'monthly',
|
||||||
'show_post_count' => $c
|
'show_post_count' => $c
|
||||||
) ) );
|
) ) );
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $args['after_widget'];
|
echo $args['after_widget'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $new_instance
|
* Handles updating settings for the current Archives widget instance.
|
||||||
* @param array $old_instance
|
*
|
||||||
* @return array
|
* @since 2.8.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param array $new_instance New settings for this instance as input by the user via
|
||||||
|
* WP_Widget_Archives::form().
|
||||||
|
* @param array $old_instance Old settings for this instance.
|
||||||
|
* @return array Updated settings to save.
|
||||||
*/
|
*/
|
||||||
public function update( $new_instance, $old_instance ) {
|
public function update( $new_instance, $old_instance ) {
|
||||||
$instance = $old_instance;
|
$instance = $old_instance;
|
||||||
@ -123,18 +139,23 @@ class WP_Widget_Archives extends WP_Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $instance
|
* Outputs the settings form for the Archives widget.
|
||||||
|
*
|
||||||
|
* @since 2.8.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param array $instance Current settings.
|
||||||
*/
|
*/
|
||||||
public function form( $instance ) {
|
public function form( $instance ) {
|
||||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
|
||||||
$title = sanitize_text_field( $instance['title'] );
|
$title = sanitize_text_field( $instance['title'] );
|
||||||
?>
|
?>
|
||||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <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>
|
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <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>
|
||||||
<p>
|
<p>
|
||||||
<input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
|
<input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
|
||||||
<br/>
|
<br/>
|
||||||
<input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
|
<input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user