Docs: Improve documentation for the __construct(), widget(), update(), and form() methods in WP_Widget_Archives.

Props leemon.
Fixes #34016. See #34013.

Built from https://develop.svn.wordpress.org/trunk@34620


git-svn-id: http://core.svn.wordpress.org/trunk@34584 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Drew Jaynes 2015-09-27 01:11:25 +00:00
parent a05eb043c3
commit c1796c55c3
2 changed files with 37 additions and 16 deletions

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34619';
$wp_version = '4.4-alpha-34620';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -16,14 +16,26 @@
*/
class WP_Widget_Archives extends WP_Widget {
/**
* Sets up a new Archives widget instance.
*
* @since 2.8.0
* @access public
*/
public function __construct() {
$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') );
parent::__construct('archives', __('Archives'), $widget_ops);
}
/**
* @param array $args
* @param array $instance
* Outputs the content for the current Archives widget 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 ) {
$c = ! empty( $instance['count'] ) ? '1' : '0';
@ -39,7 +51,7 @@ class WP_Widget_Archives extends WP_Widget {
if ( $d ) {
$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
?>
?>
<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;'>
<?php
@ -81,11 +93,9 @@ class WP_Widget_Archives extends WP_Widget {
<?php wp_get_archives( $dropdown_args ); ?>
</select>
<?php
} else {
?>
<?php } else { ?>
<ul>
<?php
<?php
/**
* Filter the arguments for the Archives widget.
*
@ -99,18 +109,24 @@ class WP_Widget_Archives extends WP_Widget {
'type' => 'monthly',
'show_post_count' => $c
) ) );
?>
?>
</ul>
<?php
<?php
}
echo $args['after_widget'];
}
/**
* @param array $new_instance
* @param array $old_instance
* @return array
* Handles updating settings for the current Archives widget instance.
*
* @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 ) {
$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 ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
$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>
<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/>
<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>
<?php
<?php
}
}