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,
|
2021-05-25 04:27:57 -04:00
|
|
|
'show_instance_in_rest' => true,
|
2016-03-21 17:59:29 -04:00
|
|
|
);
|
|
|
|
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 ) {
|
2020-07-06 16:44:02 -04:00
|
|
|
$default_title = __( 'Pages' );
|
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : $default_title;
|
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
|
|
|
|
2021-04-28 16:55:03 -04:00
|
|
|
$output = wp_list_pages(
|
2019-10-27 15:35:01 -04:00
|
|
|
/**
|
|
|
|
* Filters the arguments for the Pages widget.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
* @since 4.9.0 Added the `$instance` parameter.
|
|
|
|
*
|
|
|
|
* @see wp_list_pages()
|
|
|
|
*
|
|
|
|
* @param array $args An array of arguments to retrieve the pages list.
|
|
|
|
* @param array $instance Array of settings for the current widget.
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
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
|
|
|
|
2021-04-28 16:55:03 -04:00
|
|
|
if ( ! empty( $output ) ) {
|
2015-09-01 09:49:21 -04:00
|
|
|
echo $args['before_widget'];
|
|
|
|
if ( $title ) {
|
|
|
|
echo $args['before_title'] . $title . $args['after_title'];
|
|
|
|
}
|
2020-07-06 16:44:02 -04:00
|
|
|
|
|
|
|
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
|
|
|
|
|
2020-07-07 13:06:04 -04:00
|
|
|
/** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
|
2020-07-06 16:44:02 -04:00
|
|
|
$format = apply_filters( 'navigation_widgets_format', $format );
|
|
|
|
|
|
|
|
if ( 'html5' === $format ) {
|
|
|
|
// The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
|
|
|
|
$title = trim( strip_tags( $title ) );
|
|
|
|
$aria_label = $title ? $title : $default_title;
|
|
|
|
echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
|
|
|
|
}
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2020-07-06 16:44:02 -04:00
|
|
|
|
|
|
|
<ul>
|
2021-04-28 16:55:03 -04:00
|
|
|
<?php echo $output; ?>
|
2020-07-06 16:44:02 -04:00
|
|
|
</ul>
|
|
|
|
|
2018-08-16 21:51:36 -04:00
|
|
|
<?php
|
2020-07-08 09:44:04 -04:00
|
|
|
if ( 'html5' === $format ) {
|
|
|
|
echo '</nav>';
|
|
|
|
}
|
|
|
|
|
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'] );
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ), true ) ) {
|
2015-09-01 09:49:21 -04:00
|
|
|
$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 ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// 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>
|
2020-04-17 05:38:07 -04:00
|
|
|
|
2015-09-01 09:49:21 -04:00
|
|
|
<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>
|
2020-04-17 05:38:07 -04:00
|
|
|
|
2015-09-01 09:49:21 -04:00
|
|
|
<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
|
|
|
}
|
|
|
|
|
|
|
|
}
|