2015-09-01 09:49:21 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-09-22 10:49:24 -04:00
|
|
|
* Widget API: WP_Widget_Pages class
|
2015-09-01 09:49:21 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Widgets
|
2015-09-22 10:49:24 -04:00
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class used to implement a Pages widget.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @see WP_Widget
|
2015-09-01 09:49:21 -04:00
|
|
|
*/
|
|
|
|
class WP_Widget_Pages extends WP_Widget {
|
|
|
|
|
2015-09-26 20:54:24 -04:00
|
|
|
/**
|
|
|
|
* Sets up a new Pages widget instance.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*/
|
2015-09-01 09:49:21 -04:00
|
|
|
public function __construct() {
|
2016-03-21 17:59:29 -04:00
|
|
|
$widget_ops = array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'classname' => 'widget_pages',
|
|
|
|
'description' => __( 'A list of your site’s Pages.' ),
|
2016-03-21 17:59:29 -04:00
|
|
|
'customize_selective_refresh' => true,
|
|
|
|
);
|
|
|
|
parent::__construct( 'pages', __( 'Pages' ), $widget_ops );
|
2015-09-01 09:49:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-26 20:54:24 -04:00
|
|
|
* Outputs the content for the current Pages widget instance.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param array $args Display arguments including 'before_title', 'after_title',
|
|
|
|
* 'before_widget', and 'after_widget'.
|
|
|
|
* @param array $instance Settings for the current Pages widget instance.
|
2015-09-01 09:49:21 -04:00
|
|
|
*/
|
|
|
|
public function widget( $args, $instance ) {
|
2017-10-15 17:43:47 -04:00
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Pages' );
|
2015-09-01 09:49:21 -04:00
|
|
|
|
|
|
|
/**
|
2016-05-22 14:06:28 -04:00
|
|
|
* Filters the widget title.
|
2015-09-01 09:49:21 -04:00
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string $title The widget title. Default 'Pages'.
|
2017-10-02 18:02:47 -04:00
|
|
|
* @param array $instance Array of settings for the current widget.
|
2015-09-01 09:49:21 -04:00
|
|
|
* @param mixed $id_base The widget ID.
|
|
|
|
*/
|
2017-10-15 17:43:47 -04:00
|
|
|
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
2015-09-01 09:49:21 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
|
2015-09-01 09:49:21 -04:00
|
|
|
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
|
|
|
|
|
2019-10-06 11:28:03 -04:00
|
|
|
if ( 'menu_order' === $sortby ) {
|
2015-09-01 09:49:21 -04:00
|
|
|
$sortby = 'menu_order, post_title';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2015-09-01 09:49:21 -04:00
|
|
|
|
|
|
|
/**
|
2016-05-22 14:06:28 -04:00
|
|
|
* Filters the arguments for the Pages widget.
|
2015-09-01 09:49:21 -04:00
|
|
|
*
|
|
|
|
* @since 2.8.0
|
2017-10-02 18:02:47 -04:00
|
|
|
* @since 4.9.0 Added the `$instance` parameter.
|
2015-09-01 09:49:21 -04:00
|
|
|
*
|
|
|
|
* @see wp_list_pages()
|
|
|
|
*
|
2017-10-02 18:02:47 -04:00
|
|
|
* @param array $args An array of arguments to retrieve the pages list.
|
|
|
|
* @param array $instance Array of settings for the current widget.
|
2015-09-01 09:49:21 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$out = wp_list_pages(
|
|
|
|
apply_filters(
|
2018-08-16 21:51:36 -04:00
|
|
|
'widget_pages_args',
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'title_li' => '',
|
|
|
|
'echo' => 0,
|
|
|
|
'sort_column' => $sortby,
|
|
|
|
'exclude' => $exclude,
|
2018-08-16 21:51:36 -04:00
|
|
|
),
|
|
|
|
$instance
|
2017-11-30 18:11:00 -05:00
|
|
|
)
|
|
|
|
);
|
2015-09-01 09:49:21 -04:00
|
|
|
|
|
|
|
if ( ! empty( $out ) ) {
|
|
|
|
echo $args['before_widget'];
|
|
|
|
if ( $title ) {
|
|
|
|
echo $args['before_title'] . $title . $args['after_title'];
|
|
|
|
}
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2015-09-01 09:49:21 -04:00
|
|
|
<ul>
|
|
|
|
<?php echo $out; ?>
|
|
|
|
</ul>
|
2018-08-16 21:51:36 -04:00
|
|
|
<?php
|
2015-09-01 09:49:21 -04:00
|
|
|
echo $args['after_widget'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-26 20:54:24 -04:00
|
|
|
* Handles updating settings for the current Pages widget instance.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param array $new_instance New settings for this instance as input by the user via
|
|
|
|
* WP_Widget::form().
|
|
|
|
* @param array $old_instance Old settings for this instance.
|
|
|
|
* @return array Updated settings to save.
|
2015-09-01 09:49:21 -04:00
|
|
|
*/
|
|
|
|
public function update( $new_instance, $old_instance ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$instance = $old_instance;
|
2015-09-01 09:49:21 -04:00
|
|
|
$instance['title'] = sanitize_text_field( $new_instance['title'] );
|
|
|
|
if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
|
|
|
|
$instance['sortby'] = $new_instance['sortby'];
|
|
|
|
} else {
|
|
|
|
$instance['sortby'] = 'menu_order';
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-26 20:54:24 -04:00
|
|
|
* Outputs the settings form for the Pages widget.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param array $instance Current settings.
|
2015-09-01 09:49:21 -04:00
|
|
|
*/
|
|
|
|
public function form( $instance ) {
|
|
|
|
//Defaults
|
2017-11-30 18:11:00 -05:00
|
|
|
$instance = wp_parse_args(
|
2018-08-16 21:51:36 -04:00
|
|
|
(array) $instance,
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'sortby' => 'post_title',
|
|
|
|
'title' => '',
|
|
|
|
'exclude' => '',
|
|
|
|
)
|
|
|
|
);
|
2015-09-26 20:54:24 -04:00
|
|
|
?>
|
2015-09-01 09:49:21 -04:00
|
|
|
<p>
|
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>
|
2017-11-30 18:11:00 -05:00
|
|
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
|
2015-09-01 09:49:21 -04:00
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>
|
|
|
|
<select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">
|
2017-11-30 18:11:00 -05:00
|
|
|
<option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e( 'Page title' ); ?></option>
|
|
|
|
<option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e( 'Page order' ); ?></option>
|
2015-09-01 09:49:21 -04:00
|
|
|
<option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
|
|
|
|
</select>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label>
|
|
|
|
<input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat" />
|
|
|
|
<br />
|
|
|
|
<small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
|
|
|
|
</p>
|
2015-09-26 20:54:24 -04:00
|
|
|
<?php
|
2015-09-01 09:49:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|