- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/widgets/class-wp-widget-tag-cloud.php
r41867 r42343 24 24 public function __construct() { 25 25 $widget_ops = array( 26 'description' => __( 'A cloud of your most used tags.' ),26 'description' => __( 'A cloud of your most used tags.' ), 27 27 'customize_selective_refresh' => true, 28 28 ); … … 48 48 $title = __( 'Tags' ); 49 49 } else { 50 $tax = get_taxonomy( $current_taxonomy );50 $tax = get_taxonomy( $current_taxonomy ); 51 51 $title = $tax->labels->name; 52 52 } … … 67 67 * @param array $instance Array of settings for the current widget. 68 68 */ 69 $tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 70 'taxonomy' => $current_taxonomy, 71 'echo' => false, 72 'show_count' => $show_count, 73 ), $instance ) ); 69 $tag_cloud = wp_tag_cloud( 70 apply_filters( 71 'widget_tag_cloud_args', array( 72 'taxonomy' => $current_taxonomy, 73 'echo' => false, 74 'show_count' => $show_count, 75 ), $instance 76 ) 77 ); 74 78 75 79 if ( empty( $tag_cloud ) ) { … … 104 108 */ 105 109 public function update( $new_instance, $old_instance ) { 106 $instance = array();107 $instance['title'] = sanitize_text_field( $new_instance['title'] );108 $instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0;109 $instance['taxonomy'] = stripslashes( $new_instance['taxonomy']);110 $instance = array(); 111 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 112 $instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0; 113 $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] ); 110 114 return $instance; 111 115 } … … 119 123 */ 120 124 public function form( $instance ) { 121 $current_taxonomy = $this->_get_current_taxonomy($instance);122 $title_id = $this->get_field_id( 'title' );123 $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;125 $current_taxonomy = $this->_get_current_taxonomy( $instance ); 126 $title_id = $this->get_field_id( 'title' ); 127 $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false; 124 128 $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 125 129 126 echo '<p><label for="' . $title_id . '">' . __( 'Title:' ) . '</label>127 <input type="text" class="widefat" id="' . $title_id . '" name="' . $this->get_field_name( 'title' ) .'" value="' . $instance['title'] .'" />130 echo '<p><label for="' . $title_id . '">' . __( 'Title:' ) . '</label> 131 <input type="text" class="widefat" id="' . $title_id . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $instance['title'] . '" /> 128 132 </p>'; 129 133 130 134 $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' ); 131 $id = $this->get_field_id( 'taxonomy' );132 $name = $this->get_field_name( 'taxonomy' );133 $input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';135 $id = $this->get_field_id( 'taxonomy' ); 136 $name = $this->get_field_name( 'taxonomy' ); 137 $input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />'; 134 138 135 139 $count_checkbox = sprintf( … … 143 147 switch ( count( $taxonomies ) ) { 144 148 145 // No tag cloud supporting taxonomies found, display error message 146 case 0: 147 echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>'; 148 printf( $input, '' ); 149 break; 150 151 // Just a single tag cloud supporting taxonomy found, no need to display a select. 152 case 1: 153 $keys = array_keys( $taxonomies ); 154 $taxonomy = reset( $keys ); 155 printf( $input, esc_attr( $taxonomy ) ); 156 echo $count_checkbox; 157 break; 158 159 // More than one tag cloud supporting taxonomy found, display a select. 160 default: 161 printf( 162 '<p><label for="%1$s">%2$s</label>' . 163 '<select class="widefat" id="%1$s" name="%3$s">', 164 $id, 165 __( 'Taxonomy:' ), 166 $name 167 ); 168 169 foreach ( $taxonomies as $taxonomy => $tax ) { 149 // No tag cloud supporting taxonomies found, display error message 150 case 0: 151 echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>'; 152 printf( $input, '' ); 153 break; 154 155 // Just a single tag cloud supporting taxonomy found, no need to display a select. 156 case 1: 157 $keys = array_keys( $taxonomies ); 158 $taxonomy = reset( $keys ); 159 printf( $input, esc_attr( $taxonomy ) ); 160 echo $count_checkbox; 161 break; 162 163 // More than one tag cloud supporting taxonomy found, display a select. 164 default: 170 165 printf( 171 '<option value="%s"%s>%s</option>', 172 esc_attr( $taxonomy ), 173 selected( $taxonomy, $current_taxonomy, false ), 174 $tax->labels->name 166 '<p><label for="%1$s">%2$s</label>' . 167 '<select class="widefat" id="%1$s" name="%3$s">', 168 $id, 169 __( 'Taxonomy:' ), 170 $name 175 171 ); 176 } 177 178 echo '</select></p>' . $count_checkbox; 172 173 foreach ( $taxonomies as $taxonomy => $tax ) { 174 printf( 175 '<option value="%s"%s>%s</option>', 176 esc_attr( $taxonomy ), 177 selected( $taxonomy, $current_taxonomy, false ), 178 $tax->labels->name 179 ); 180 } 181 182 echo '</select></p>' . $count_checkbox; 179 183 } 180 184 } … … 188 192 * @return string Name of the current taxonomy if set, otherwise 'post_tag'. 189 193 */ 190 public function _get_current_taxonomy( $instance) {191 if ( ! empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )194 public function _get_current_taxonomy( $instance ) { 195 if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) ) { 192 196 return $instance['taxonomy']; 197 } 193 198 194 199 return 'post_tag';
Note: See TracChangeset
for help on using the changeset viewer.