- Timestamp:
- 07/24/2017 10:53:20 PM (7 years ago)
- Location:
- branches/4.8
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.8
-
branches/4.8/src/wp-includes/widgets/class-wp-widget-text.php
r41087 r41133 80 80 public function is_legacy_instance( $instance ) { 81 81 82 // If the widget has been updated while in legacy mode, it stays in legacymode.83 if ( ! empty( $instance['legacy'] ) ) {84 return true;85 } 86 87 // If the widget has been added/updated in 4.8then filter prop is 'content' and it is no longer legacy.82 // Legacy mode when not in visual mode. 83 if ( isset( $instance['visual'] ) ) { 84 return ! $instance['visual']; 85 } 86 87 // Or, the widget has been added/updated in 4.8.0 then filter prop is 'content' and it is no longer legacy. 88 88 if ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ) { 89 89 return false; … … 194 194 195 195 $text = ! empty( $instance['text'] ) ? $instance['text'] : ''; 196 $is_visual_text_widget = ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ); 196 $is_visual_text_widget = ( ! empty( $instance['visual'] ) && ! empty( $instance['filter'] ) ); 197 198 // In 4.8.0 only, visual Text widgets get filter=content, without visual prop; upgrade instance props just-in-time. 199 if ( ! $is_visual_text_widget ) { 200 $is_visual_text_widget = ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ); 201 } 202 if ( $is_visual_text_widget ) { 203 $instance['filter'] = true; 204 $instance['visual'] = true; 205 } 197 206 198 207 /* … … 222 231 $text = apply_filters( 'widget_text', $text, $instance, $this ); 223 232 224 if ( isset( $instance['filter'] ) ) { 225 if ( 'content' === $instance['filter'] ) { 226 227 /** 228 * Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor. 229 * 230 * By default a subset of the_content filters are applied, including wpautop and wptexturize. 231 * 232 * @since 4.8.0 233 * 234 * @param string $text The widget content. 235 * @param array $instance Array of settings for the current widget. 236 * @param WP_Widget_Text $this Current Text widget instance. 237 */ 238 $text = apply_filters( 'widget_text_content', $text, $instance, $this ); 239 240 } elseif ( $instance['filter'] ) { 241 $text = wpautop( $text ); // Back-compat for instances prior to 4.8. 242 } 233 if ( $is_visual_text_widget ) { 234 235 /** 236 * Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor. 237 * 238 * By default a subset of the_content filters are applied, including wpautop and wptexturize. 239 * 240 * @since 4.8.0 241 * 242 * @param string $text The widget content. 243 * @param array $instance Array of settings for the current widget. 244 * @param WP_Widget_Text $this Current Text widget instance. 245 */ 246 $text = apply_filters( 'widget_text_content', $text, $instance, $this ); 247 248 } elseif ( ! empty( $instance['filter'] ) ) { 249 $text = wpautop( $text ); // Back-compat for instances prior to 4.8. 243 250 } 244 251 … … 272 279 */ 273 280 public function update( $new_instance, $old_instance ) { 281 $new_instance = wp_parse_args( $new_instance, array( 282 'title' => '', 283 'text' => '', 284 'filter' => false, // For back-compat. 285 'visual' => null, // Must be explicitly defined. 286 ) ); 287 274 288 $instance = $old_instance; 289 275 290 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 276 291 if ( current_user_can( 'unfiltered_html' ) ) { … … 280 295 } 281 296 282 /* 283 * If the Text widget is in legacy mode, then a hidden input will indicate this 284 * and the new content value for the filter prop will by bypassed. Otherwise, 285 * re-use legacy 'filter' (wpautop) property to now indicate content filters will always apply. 286 * Prior to 4.8, this is a boolean value used to indicate whether or not wpautop should be 287 * applied. By re-using this property, downgrading WordPress from 4.8 to 4.7 will ensure 288 * that the content for Text widgets created with TinyMCE will continue to get wpautop. 289 */ 290 if ( isset( $new_instance['legacy'] ) || isset( $old_instance['legacy'] ) || ( isset( $new_instance['filter'] ) && 'content' !== $new_instance['filter'] ) ) { 291 $instance['filter'] = ! empty( $new_instance['filter'] ); 292 $instance['legacy'] = true; 293 } else { 294 $instance['filter'] = 'content'; 295 unset( $instance['legacy'] ); 297 $instance['filter'] = ! empty( $new_instance['filter'] ); 298 299 // Upgrade 4.8.0 format. 300 if ( isset( $old_instance['filter'] ) && 'content' === $old_instance['filter'] ) { 301 $instance['visual'] = true; 302 } 303 if ( 'content' === $new_instance['filter'] ) { 304 $instance['visual'] = true; 305 } 306 307 if ( isset( $new_instance['visual'] ) ) { 308 $instance['visual'] = ! empty( $new_instance['visual'] ); 309 } 310 311 // Filter is always true in visual mode. 312 if ( ! empty( $instance['visual'] ) ) { 313 $instance['filter'] = true; 296 314 } 297 315 … … 334 352 <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>"> 335 353 <input id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" class="text" type="hidden" value="<?php echo esc_attr( $instance['text'] ); ?>"> 354 <input id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" class="filter" type="hidden" value="on"> 355 <input id="<?php echo $this->get_field_id( 'visual' ); ?>" name="<?php echo $this->get_field_name( 'visual' ); ?>" class="visual" type="hidden" value="on"> 336 356 <?php else : ?> 337 <input name="<?php echo $this->get_field_name( 'legacy' ); ?>" type="hidden" class="legacy" value="true">357 <input id="<?php echo $this->get_field_id( 'visual' ); ?>" name="<?php echo $this->get_field_name( 'visual' ); ?>" class="visual" type="hidden" value=""> 338 358 <p> 339 359 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
Note: See TracChangeset
for help on using the changeset viewer.