52 } |
52 } |
53 } |
53 } |
54 |
54 |
55 $show_count = ! empty( $instance['count'] ); |
55 $show_count = ! empty( $instance['count'] ); |
56 |
56 |
57 /** |
|
58 * Filters the taxonomy used in the Tag Cloud widget. |
|
59 * |
|
60 * @since 2.8.0 |
|
61 * @since 3.0.0 Added taxonomy drop-down. |
|
62 * @since 4.9.0 Added the `$instance` parameter. |
|
63 * |
|
64 * @see wp_tag_cloud() |
|
65 * |
|
66 * @param array $args Args used for the tag cloud widget. |
|
67 * @param array $instance Array of settings for the current widget. |
|
68 */ |
|
69 $tag_cloud = wp_tag_cloud( |
57 $tag_cloud = wp_tag_cloud( |
|
58 /** |
|
59 * Filters the taxonomy used in the Tag Cloud widget. |
|
60 * |
|
61 * @since 2.8.0 |
|
62 * @since 3.0.0 Added taxonomy drop-down. |
|
63 * @since 4.9.0 Added the `$instance` parameter. |
|
64 * |
|
65 * @see wp_tag_cloud() |
|
66 * |
|
67 * @param array $args Args used for the tag cloud widget. |
|
68 * @param array $instance Array of settings for the current widget. |
|
69 */ |
70 apply_filters( |
70 apply_filters( |
71 'widget_tag_cloud_args', |
71 'widget_tag_cloud_args', |
72 array( |
72 array( |
73 'taxonomy' => $current_taxonomy, |
73 'taxonomy' => $current_taxonomy, |
74 'echo' => false, |
74 'echo' => false, |
122 * @since 2.8.0 |
122 * @since 2.8.0 |
123 * |
123 * |
124 * @param array $instance Current settings. |
124 * @param array $instance Current settings. |
125 */ |
125 */ |
126 public function form( $instance ) { |
126 public function form( $instance ) { |
127 $current_taxonomy = $this->_get_current_taxonomy( $instance ); |
127 $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
128 $title_id = $this->get_field_id( 'title' ); |
128 $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false; |
129 $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false; |
129 ?> |
130 $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
130 <p> |
131 |
131 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
132 echo '<p><label for="' . $title_id . '">' . __( 'Title:' ) . '</label> |
132 <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" /> |
133 <input type="text" class="widefat" id="' . $title_id . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $instance['title'] . '" /> |
133 </p> |
134 </p>'; |
134 <?php |
135 |
135 $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' ); |
136 $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' ); |
136 $current_taxonomy = $this->_get_current_taxonomy( $instance ); |
137 $id = $this->get_field_id( 'taxonomy' ); |
|
138 $name = $this->get_field_name( 'taxonomy' ); |
|
139 $input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />'; |
|
140 |
|
141 $count_checkbox = sprintf( |
|
142 '<p><input type="checkbox" class="checkbox" id="%1$s" name="%2$s"%3$s /> <label for="%1$s">%4$s</label></p>', |
|
143 $this->get_field_id( 'count' ), |
|
144 $this->get_field_name( 'count' ), |
|
145 checked( $count, true, false ), |
|
146 __( 'Show tag counts' ) |
|
147 ); |
|
148 |
137 |
149 switch ( count( $taxonomies ) ) { |
138 switch ( count( $taxonomies ) ) { |
150 |
139 |
151 // No tag cloud supporting taxonomies found, display error message |
140 // No tag cloud supporting taxonomies found, display error message. |
152 case 0: |
141 case 0: |
153 echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>'; |
142 ?> |
154 printf( $input, '' ); |
143 <input type="hidden" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" value="" /> |
|
144 <p> |
|
145 <?php _e( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ); ?> |
|
146 </p> |
|
147 <?php |
155 break; |
148 break; |
156 |
149 |
157 // Just a single tag cloud supporting taxonomy found, no need to display a select. |
150 // Just a single tag cloud supporting taxonomy found, no need to display a select. |
158 case 1: |
151 case 1: |
159 $keys = array_keys( $taxonomies ); |
152 $keys = array_keys( $taxonomies ); |
160 $taxonomy = reset( $keys ); |
153 $taxonomy = reset( $keys ); |
161 printf( $input, esc_attr( $taxonomy ) ); |
154 ?> |
162 echo $count_checkbox; |
155 <input type="hidden" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" value="<?php echo esc_attr( $taxonomy ); ?>" /> |
|
156 <?php |
163 break; |
157 break; |
164 |
158 |
165 // More than one tag cloud supporting taxonomy found, display a select. |
159 // More than one tag cloud supporting taxonomy found, display a select. |
166 default: |
160 default: |
167 printf( |
161 ?> |
168 '<p><label for="%1$s">%2$s</label>' . |
162 <p> |
169 '<select class="widefat" id="%1$s" name="%3$s">', |
163 <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Taxonomy:' ); ?></label> |
170 $id, |
164 <select class="widefat" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>"> |
171 __( 'Taxonomy:' ), |
165 <?php foreach ( $taxonomies as $taxonomy => $tax ) : ?> |
172 $name |
166 <option value="<?php echo esc_attr( $taxonomy ); ?>" <?php selected( $taxonomy, $current_taxonomy ); ?>> |
173 ); |
167 <?php echo esc_html( $tax->labels->name ); ?> |
174 |
168 </option> |
175 foreach ( $taxonomies as $taxonomy => $tax ) { |
169 <?php endforeach; ?> |
176 printf( |
170 </select> |
177 '<option value="%s"%s>%s</option>', |
171 </p> |
178 esc_attr( $taxonomy ), |
172 <?php |
179 selected( $taxonomy, $current_taxonomy, false ), |
173 } |
180 $tax->labels->name |
174 |
181 ); |
175 if ( count( $taxonomies ) > 0 ) { |
182 } |
176 ?> |
183 |
177 <p> |
184 echo '</select></p>' . $count_checkbox; |
178 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" <?php checked( $count, true ); ?> /> |
|
179 <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show tag counts' ); ?></label> |
|
180 </p> |
|
181 <?php |
185 } |
182 } |
186 } |
183 } |
187 |
184 |
188 /** |
185 /** |
189 * Retrieves the taxonomy for the current Tag cloud widget instance. |
186 * Retrieves the taxonomy for the current Tag cloud widget instance. |