38 * @param array $args Display arguments including 'before_title', 'after_title', |
38 * @param array $args Display arguments including 'before_title', 'after_title', |
39 * 'before_widget', and 'after_widget'. |
39 * 'before_widget', and 'after_widget'. |
40 * @param array $instance Settings for the current Pages widget instance. |
40 * @param array $instance Settings for the current Pages widget instance. |
41 */ |
41 */ |
42 public function widget( $args, $instance ) { |
42 public function widget( $args, $instance ) { |
43 $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Pages' ); |
43 $default_title = __( 'Pages' ); |
|
44 $title = ! empty( $instance['title'] ) ? $instance['title'] : $default_title; |
44 |
45 |
45 /** |
46 /** |
46 * Filters the widget title. |
47 * Filters the widget title. |
47 * |
48 * |
48 * @since 2.6.0 |
49 * @since 2.6.0 |
54 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
55 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
55 |
56 |
56 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; |
57 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; |
57 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; |
58 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; |
58 |
59 |
59 if ( $sortby == 'menu_order' ) { |
60 if ( 'menu_order' === $sortby ) { |
60 $sortby = 'menu_order, post_title'; |
61 $sortby = 'menu_order, post_title'; |
61 } |
62 } |
62 |
63 |
63 /** |
|
64 * Filters the arguments for the Pages widget. |
|
65 * |
|
66 * @since 2.8.0 |
|
67 * @since 4.9.0 Added the `$instance` parameter. |
|
68 * |
|
69 * @see wp_list_pages() |
|
70 * |
|
71 * @param array $args An array of arguments to retrieve the pages list. |
|
72 * @param array $instance Array of settings for the current widget. |
|
73 */ |
|
74 $out = wp_list_pages( |
64 $out = wp_list_pages( |
|
65 /** |
|
66 * Filters the arguments for the Pages widget. |
|
67 * |
|
68 * @since 2.8.0 |
|
69 * @since 4.9.0 Added the `$instance` parameter. |
|
70 * |
|
71 * @see wp_list_pages() |
|
72 * |
|
73 * @param array $args An array of arguments to retrieve the pages list. |
|
74 * @param array $instance Array of settings for the current widget. |
|
75 */ |
75 apply_filters( |
76 apply_filters( |
76 'widget_pages_args', |
77 'widget_pages_args', |
77 array( |
78 array( |
78 'title_li' => '', |
79 'title_li' => '', |
79 'echo' => 0, |
80 'echo' => 0, |
87 if ( ! empty( $out ) ) { |
88 if ( ! empty( $out ) ) { |
88 echo $args['before_widget']; |
89 echo $args['before_widget']; |
89 if ( $title ) { |
90 if ( $title ) { |
90 echo $args['before_title'] . $title . $args['after_title']; |
91 echo $args['before_title'] . $title . $args['after_title']; |
91 } |
92 } |
|
93 |
|
94 $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; |
|
95 |
|
96 /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */ |
|
97 $format = apply_filters( 'navigation_widgets_format', $format ); |
|
98 |
|
99 if ( 'html5' === $format ) { |
|
100 // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. |
|
101 $title = trim( strip_tags( $title ) ); |
|
102 $aria_label = $title ? $title : $default_title; |
|
103 echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">'; |
|
104 } |
92 ?> |
105 ?> |
93 <ul> |
106 |
94 <?php echo $out; ?> |
107 <ul> |
95 </ul> |
108 <?php echo $out; ?> |
|
109 </ul> |
|
110 |
96 <?php |
111 <?php |
|
112 if ( 'html5' === $format ) { |
|
113 echo '</nav>'; |
|
114 } |
|
115 |
97 echo $args['after_widget']; |
116 echo $args['after_widget']; |
98 } |
117 } |
99 } |
118 } |
100 |
119 |
101 /** |
120 /** |
109 * @return array Updated settings to save. |
128 * @return array Updated settings to save. |
110 */ |
129 */ |
111 public function update( $new_instance, $old_instance ) { |
130 public function update( $new_instance, $old_instance ) { |
112 $instance = $old_instance; |
131 $instance = $old_instance; |
113 $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
132 $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
114 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) { |
133 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ), true ) ) { |
115 $instance['sortby'] = $new_instance['sortby']; |
134 $instance['sortby'] = $new_instance['sortby']; |
116 } else { |
135 } else { |
117 $instance['sortby'] = 'menu_order'; |
136 $instance['sortby'] = 'menu_order'; |
118 } |
137 } |
119 |
138 |
142 ?> |
161 ?> |
143 <p> |
162 <p> |
144 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label> |
163 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label> |
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'] ); ?>" /> |
164 <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'] ); ?>" /> |
146 </p> |
165 </p> |
|
166 |
147 <p> |
167 <p> |
148 <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label> |
168 <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label> |
149 <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat"> |
169 <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat"> |
150 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e( 'Page title' ); ?></option> |
170 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e( 'Page title' ); ?></option> |
151 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e( 'Page order' ); ?></option> |
171 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e( 'Page order' ); ?></option> |
152 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option> |
172 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option> |
153 </select> |
173 </select> |
154 </p> |
174 </p> |
|
175 |
155 <p> |
176 <p> |
156 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label> |
177 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label> |
157 <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" /> |
178 <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" /> |
158 <br /> |
179 <br /> |
159 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small> |
180 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small> |