@@ -38,9 +38,22 @@ public function __construct() {
3838 * @since 4.2.0 Creates a unique HTML ID for the `<select>` element
3939 * if more than one instance is displayed on the page.
4040 *
41- * @param array $args Display arguments including 'before_title', 'after_title',
42- * 'before_widget', and 'after_widget'.
43- * @param array $instance Settings for the current Categories widget instance.
41+ * @param array $args {
42+ * Display arguments.
43+ *
44+ * @type string $before_widget HTML markup to prepend to each widget in the sidebar.
45+ * @type string $after_widget HTML markup to append to each widget in the sidebar.
46+ * @type string $before_title HTML markup to prepend to the widget title when displayed.
47+ * @type string $after_title HTML markup to append to the widget title when displayed.
48+ * }
49+ * @param array $instance {
50+ * Settings for the current Categories widget instance.
51+ *
52+ * @type string $title Widget title.
53+ * @type 0|1 $count Whether to show post counts.
54+ * @type 0|1 $hierarchical Whether to show the category hierarchy.
55+ * @type 0|1 $dropdown Whether to display the categories as a drop-down.
56+ * }
4457 */
4558 public function widget ( $ args , $ instance ) {
4659 static $ first_dropdown = true ;
@@ -51,9 +64,15 @@ public function widget( $args, $instance ) {
5164 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
5265 $ title = apply_filters ( 'widget_title ' , $ title , $ instance , $ this ->id_base );
5366
54- $ count = ! empty ( $ instance ['count ' ] ) ? '1 ' : '0 ' ;
55- $ hierarchical = ! empty ( $ instance ['hierarchical ' ] ) ? '1 ' : '0 ' ;
56- $ dropdown = ! empty ( $ instance ['dropdown ' ] ) ? '1 ' : '0 ' ;
67+ /*
68+ * Although update() stores these flags as 0 or 1, they are checked loosely for back-compat:
69+ * the keys are absent for an instance that has not been saved yet, instances saved before
70+ * WordPress 2.8 stored booleans, and the_widget() passes along whatever values its caller
71+ * supplies.
72+ */
73+ $ count = ! empty ( $ instance ['count ' ] );
74+ $ hierarchical = ! empty ( $ instance ['hierarchical ' ] );
75+ $ dropdown = ! empty ( $ instance ['dropdown ' ] );
5776
5877 echo $ args ['before_widget ' ];
5978
@@ -82,11 +101,29 @@ public function widget( $args, $instance ) {
82101 *
83102 * @since 2.8.0
84103 * @since 4.9.0 Added the `$instance` parameter.
104+ * @since 7.2.0 The `show_count` and `hierarchical` arguments in `$cat_args` are now booleans instead of the numeric strings '0' and '1'.
85105 *
86106 * @see wp_dropdown_categories()
87107 *
88- * @param array $cat_args An array of Categories widget drop-down arguments.
89- * @param array $instance Array of settings for the current widget.
108+ * @param array $cat_args {
109+ * An array of Categories widget drop-down arguments. See {@see wp_dropdown_categories()} for
110+ * information on additional accepted arguments.
111+ *
112+ * @type string $orderby Which column to use for ordering categories. See {@see get_terms()}
113+ * for a list of accepted values. Default 'name'.
114+ * @type bool $show_count Whether to include post counts.
115+ * @type bool $hierarchical Whether to traverse the taxonomy hierarchy.
116+ * @type string $show_option_none Text to display for showing no categories. Set to 'Select Category'.
117+ * @type string $id Value for the 'id' attribute of the select element.
118+ * }
119+ * @param array $instance {
120+ * Array of settings for the current widget.
121+ *
122+ * @type string $title Widget title.
123+ * @type 0|1 $count Whether to show post counts.
124+ * @type 0|1 $hierarchical Whether to show the category hierarchy.
125+ * @type 0|1 $dropdown Whether to display the categories as a drop-down.
126+ * }
90127 */
91128 wp_dropdown_categories ( apply_filters ( 'widget_categories_dropdown_args ' , $ cat_args , $ instance ) );
92129
@@ -149,9 +186,26 @@ function onClick() {
149186 *
150187 * @since 2.8.0
151188 * @since 4.9.0 Added the `$instance` parameter.
189+ * @since 7.2.0 The `show_count` and `hierarchical` arguments in `$cat_args` are now booleans instead of the numeric strings '0' and '1'.
190+ *
191+ * @param array $cat_args {
192+ * An array of Categories widget options. See {@see wp_list_categories()} for information on
193+ * additional accepted arguments.
152194 *
153- * @param array $cat_args An array of Categories widget options.
154- * @param array $instance Array of settings for the current widget.
195+ * @type string $orderby Which column to use for ordering categories. See {@see get_terms()}
196+ * for a list of accepted values. Default 'name'.
197+ * @type bool $show_count Whether to include post counts.
198+ * @type bool $hierarchical Whether to traverse the taxonomy hierarchy.
199+ * @type string $title_li Text to use for the list title `<li>` element. Default empty string.
200+ * }
201+ * @param array $instance {
202+ * Array of settings for the current widget.
203+ *
204+ * @type string $title Widget title.
205+ * @type 0|1 $count Whether to show post counts.
206+ * @type 0|1 $hierarchical Whether to show the category hierarchy.
207+ * @type 0|1 $dropdown Whether to display the categories as a drop-down.
208+ * }
155209 */
156210 wp_list_categories ( apply_filters ( 'widget_categories_args ' , $ cat_args , $ instance ) );
157211 ?>
@@ -171,14 +225,36 @@ function onClick() {
171225 *
172226 * @since 2.8.0
173227 *
174- * @param array $new_instance New settings for this instance as input by the user via
175- * WP_Widget::form().
176- * @param array $old_instance Old settings for this instance.
177- * @return array Updated settings to save.
228+ * @param array $new_instance {
229+ * New settings for this instance as input by the user via {@see WP_Widget::form()}. A checkbox
230+ * submits 'on' when checked and is omitted when unchecked. A saved instance resubmitted
231+ * through the REST API passes 0 or 1 instead.
232+ *
233+ * @type string $title Widget title.
234+ * @type 'on'|0|1 $count Whether to show post counts.
235+ * @type 'on'|0|1 $hierarchical Whether to show the category hierarchy.
236+ * @type 'on'|0|1 $dropdown Whether to display the categories as a drop-down.
237+ * }
238+ * @param array $old_instance {
239+ * Old settings for this instance.
240+ *
241+ * @type string $title Widget title.
242+ * @type 0|1 $count Whether to show post counts.
243+ * @type 0|1 $hierarchical Whether to show the category hierarchy.
244+ * @type 0|1 $dropdown Whether to display the categories as a drop-down.
245+ * }
246+ * @return array {
247+ * Updated settings to save.
248+ *
249+ * @type string $title Widget title.
250+ * @type 0|1 $count Whether to show post counts.
251+ * @type 0|1 $hierarchical Whether to show the category hierarchy.
252+ * @type 0|1 $dropdown Whether to display the categories as a drop-down.
253+ * }
178254 */
179255 public function update ( $ new_instance , $ old_instance ) {
180256 $ instance = $ old_instance ;
181- $ instance ['title ' ] = sanitize_text_field ( $ new_instance ['title ' ] );
257+ $ instance ['title ' ] = sanitize_text_field ( $ new_instance ['title ' ] ?? '' );
182258 $ instance ['count ' ] = ! empty ( $ new_instance ['count ' ] ) ? 1 : 0 ;
183259 $ instance ['hierarchical ' ] = ! empty ( $ new_instance ['hierarchical ' ] ) ? 1 : 0 ;
184260 $ instance ['dropdown ' ] = ! empty ( $ new_instance ['dropdown ' ] ) ? 1 : 0 ;
@@ -191,7 +267,14 @@ public function update( $new_instance, $old_instance ) {
191267 *
192268 * @since 2.8.0
193269 *
194- * @param array $instance Current settings.
270+ * @param array $instance {
271+ * Current settings.
272+ *
273+ * @type string $title Widget title.
274+ * @type 0|1 $count Whether to show post counts.
275+ * @type 0|1 $hierarchical Whether to show the category hierarchy.
276+ * @type 0|1 $dropdown Whether to display the categories as a drop-down.
277+ * }
195278 */
196279 public function form ( $ instance ) {
197280 // Defaults.
0 commit comments