diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-includes/widgets/class-wp-widget-text.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wp/wp-includes/widgets/class-wp-widget-text.php Mon Oct 14 17:39:30 2019 +0200 @@ -0,0 +1,552 @@ + 'widget_text', + 'description' => __( 'Arbitrary text.' ), + 'customize_selective_refresh' => true, + ); + $control_ops = array( + 'width' => 400, + 'height' => 350, + ); + parent::__construct( 'text', __( 'Text' ), $widget_ops, $control_ops ); + } + + /** + * Add hooks for enqueueing assets when registering all widget instances of this widget class. + * + * @param integer $number Optional. The unique order number of this widget instance + * compared to other instances of the same class. Default -1. + */ + public function _register_one( $number = -1 ) { + parent::_register_one( $number ); + if ( $this->registered ) { + return; + } + $this->registered = true; + + wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) ); + + if ( $this->is_preview() ) { + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) ); + } + + // Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts(). + add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) ); + + // Note that the widgets component in the customizer will also do the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts(). + add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Text', 'render_control_template_scripts' ) ); + } + + /** + * Determines whether a given instance is legacy and should bypass using TinyMCE. + * + * @since 4.8.1 + * + * @param array $instance { + * Instance data. + * + * @type string $text Content. + * @type bool|string $filter Whether autop or content filters should apply. + * @type bool $legacy Whether widget is in legacy mode. + * } + * @return bool Whether Text widget instance contains legacy data. + */ + public function is_legacy_instance( $instance ) { + + // Legacy mode when not in visual mode. + if ( isset( $instance['visual'] ) ) { + return ! $instance['visual']; + } + + // Or, the widget has been added/updated in 4.8.0 then filter prop is 'content' and it is no longer legacy. + if ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ) { + return false; + } + + // If the text is empty, then nothing is preventing migration to TinyMCE. + if ( empty( $instance['text'] ) ) { + return false; + } + + $wpautop = ! empty( $instance['filter'] ); + $has_line_breaks = ( false !== strpos( trim( $instance['text'] ), "\n" ) ); + + // If auto-paragraphs are not enabled and there are line breaks, then ensure legacy mode. + if ( ! $wpautop && $has_line_breaks ) { + return true; + } + + // If an HTML comment is present, assume legacy mode. + if ( false !== strpos( $instance['text'], '