wp/wp-includes/widgets/class-wp-widget-pages.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    21 	 *
    21 	 *
    22 	 * @since 2.8.0
    22 	 * @since 2.8.0
    23 	 */
    23 	 */
    24 	public function __construct() {
    24 	public function __construct() {
    25 		$widget_ops = array(
    25 		$widget_ops = array(
    26 			'classname' => 'widget_pages',
    26 			'classname'                   => 'widget_pages',
    27 			'description' => __( 'A list of your site’s Pages.' ),
    27 			'description'                 => __( 'A list of your site’s Pages.' ),
    28 			'customize_selective_refresh' => true,
    28 			'customize_selective_refresh' => true,
    29 		);
    29 		);
    30 		parent::__construct( 'pages', __( 'Pages' ), $widget_ops );
    30 		parent::__construct( 'pages', __( 'Pages' ), $widget_ops );
    31 	}
    31 	}
    32 
    32 
    51 		 * @param array  $instance Array of settings for the current widget.
    51 		 * @param array  $instance Array of settings for the current widget.
    52 		 * @param mixed  $id_base  The widget ID.
    52 		 * @param mixed  $id_base  The widget ID.
    53 		 */
    53 		 */
    54 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    54 		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    55 
    55 
    56 		$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    56 		$sortby  = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    57 		$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    57 		$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    58 
    58 
    59 		if ( $sortby == 'menu_order' )
    59 		if ( $sortby == 'menu_order' ) {
    60 			$sortby = 'menu_order, post_title';
    60 			$sortby = 'menu_order, post_title';
       
    61 		}
    61 
    62 
    62 		/**
    63 		/**
    63 		 * Filters the arguments for the Pages widget.
    64 		 * Filters the arguments for the Pages widget.
    64 		 *
    65 		 *
    65 		 * @since 2.8.0
    66 		 * @since 2.8.0
    68 		 * @see wp_list_pages()
    69 		 * @see wp_list_pages()
    69 		 *
    70 		 *
    70 		 * @param array $args     An array of arguments to retrieve the pages list.
    71 		 * @param array $args     An array of arguments to retrieve the pages list.
    71 		 * @param array $instance Array of settings for the current widget.
    72 		 * @param array $instance Array of settings for the current widget.
    72 		 */
    73 		 */
    73 		$out = wp_list_pages( apply_filters( 'widget_pages_args', array(
    74 		$out = wp_list_pages(
    74 			'title_li'    => '',
    75 			apply_filters(
    75 			'echo'        => 0,
    76 				'widget_pages_args',
    76 			'sort_column' => $sortby,
    77 				array(
    77 			'exclude'     => $exclude
    78 					'title_li'    => '',
    78 		), $instance ) );
    79 					'echo'        => 0,
       
    80 					'sort_column' => $sortby,
       
    81 					'exclude'     => $exclude,
       
    82 				),
       
    83 				$instance
       
    84 			)
       
    85 		);
    79 
    86 
    80 		if ( ! empty( $out ) ) {
    87 		if ( ! empty( $out ) ) {
    81 			echo $args['before_widget'];
    88 			echo $args['before_widget'];
    82 			if ( $title ) {
    89 			if ( $title ) {
    83 				echo $args['before_title'] . $title . $args['after_title'];
    90 				echo $args['before_title'] . $title . $args['after_title'];
    84 			}
    91 			}
    85 		?>
    92 			?>
    86 		<ul>
    93 		<ul>
    87 			<?php echo $out; ?>
    94 			<?php echo $out; ?>
    88 		</ul>
    95 		</ul>
    89 		<?php
    96 			<?php
    90 			echo $args['after_widget'];
    97 			echo $args['after_widget'];
    91 		}
    98 		}
    92 	}
    99 	}
    93 
   100 
    94 	/**
   101 	/**
   100 	 *                            WP_Widget::form().
   107 	 *                            WP_Widget::form().
   101 	 * @param array $old_instance Old settings for this instance.
   108 	 * @param array $old_instance Old settings for this instance.
   102 	 * @return array Updated settings to save.
   109 	 * @return array Updated settings to save.
   103 	 */
   110 	 */
   104 	public function update( $new_instance, $old_instance ) {
   111 	public function update( $new_instance, $old_instance ) {
   105 		$instance = $old_instance;
   112 		$instance          = $old_instance;
   106 		$instance['title'] = sanitize_text_field( $new_instance['title'] );
   113 		$instance['title'] = sanitize_text_field( $new_instance['title'] );
   107 		if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
   114 		if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
   108 			$instance['sortby'] = $new_instance['sortby'];
   115 			$instance['sortby'] = $new_instance['sortby'];
   109 		} else {
   116 		} else {
   110 			$instance['sortby'] = 'menu_order';
   117 			$instance['sortby'] = 'menu_order';
   122 	 *
   129 	 *
   123 	 * @param array $instance Current settings.
   130 	 * @param array $instance Current settings.
   124 	 */
   131 	 */
   125 	public function form( $instance ) {
   132 	public function form( $instance ) {
   126 		//Defaults
   133 		//Defaults
   127 		$instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
   134 		$instance = wp_parse_args(
       
   135 			(array) $instance,
       
   136 			array(
       
   137 				'sortby'  => 'post_title',
       
   138 				'title'   => '',
       
   139 				'exclude' => '',
       
   140 			)
       
   141 		);
   128 		?>
   142 		?>
   129 		<p>
   143 		<p>
   130 			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>
   144 			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>
   131 			<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'] ); ?>" />
   145 			<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'] ); ?>" />
   132 		</p>
   146 		</p>
   133 		<p>
   147 		<p>
   134 			<label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>
   148 			<label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>
   135 			<select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">
   149 			<select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">
   136 				<option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
   150 				<option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e( 'Page title' ); ?></option>
   137 				<option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
   151 				<option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e( 'Page order' ); ?></option>
   138 				<option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
   152 				<option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
   139 			</select>
   153 			</select>
   140 		</p>
   154 		</p>
   141 		<p>
   155 		<p>
   142 			<label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label>
   156 			<label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label>