diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 5d7ba224cc207..7f5ef265c6fbc 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -158,12 +158,8 @@ public static function parse_settings( $editor_id, $settings ) { */ public static function editor( $content, $editor_id, $settings = array() ) { $set = self::parse_settings( $editor_id, $settings ); - $editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"'; - $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; $default_editor = 'html'; $buttons = ''; - $autocomplete = ''; - $editor_id_attr = esc_attr( $editor_id ); if ( $set['drag_drop_upload'] ) { self::$drag_drop_upload = true; @@ -180,8 +176,6 @@ public static function editor( $content, $editor_id, $settings = array() ) { } if ( self::$this_tinymce ) { - $autocomplete = ' autocomplete="off"'; - if ( self::$this_quicktags ) { $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor(); // 'html' is used for the "Text" editor tab. @@ -189,10 +183,16 @@ public static function editor( $content, $editor_id, $settings = array() ) { $default_editor = 'tinymce'; } - $buttons .= '\n"; - $buttons .= '\n"; + $buttons .= WP_HTML::render( << + +HTML, + array( + 'id' => $editor_id, + 'text_label' => _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ), + 'visual_label' => _x( 'Visual', 'Name for the Visual editor tab' ), + ) + ); } else { $default_editor = 'tinymce'; } @@ -201,11 +201,13 @@ public static function editor( $content, $editor_id, $settings = array() ) { $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active'; $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class; - if ( $set['_content_editor_dfw'] ) { - $wrap_class .= ' has-dfw'; - } - - echo '
'; + echo WP_HTML::render( + '
', + array( + 'id' => $editor_id, + 'has_dfw' => $set['_content_editor_dfw'] ? 'has-dfw' : '', + ) + ); if ( self::$editor_buttons_css ) { wp_print_styles( 'editor-buttons' ); @@ -217,7 +219,10 @@ public static function editor( $content, $editor_id, $settings = array() ) { } if ( ! empty( $buttons ) || $set['media_buttons'] ) { - echo '
'; + echo WP_HTML::render( + '
', + array( 'id' => $editor_id ) + ); if ( $set['media_buttons'] ) { self::$has_medialib = true; @@ -226,7 +231,10 @@ public static function editor( $content, $editor_id, $settings = array() ) { require ABSPATH . 'wp-admin/includes/media.php'; } - echo '
'; + echo WP_HTML::render( + '
', + array( 'id' => $editor_id ) + ); /** * Fires after the default media button(s) are displayed. @@ -249,10 +257,13 @@ public static function editor( $content, $editor_id, $settings = array() ) { if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && 'post' === $GLOBALS['current_screen']->base ) { $toolbar_id = 'ed_toolbar'; } else { - $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar'; + $toolbar_id = 'qt_' . $editor_id . '_toolbar'; } - $quicktags_toolbar = '
'; + $quicktags_toolbar = WP_HTML::render( + '
', + array( 'id' => $toolbar_id ) + ); } /** @@ -264,10 +275,28 @@ public static function editor( $content, $editor_id, $settings = array() ) { */ $the_editor = apply_filters( 'the_editor', - '
' . + WP_HTML::render( + '
', + array( 'id' => $editor_id ) + ) . $quicktags_toolbar . - '%s
' + WP_HTML::render( + <<<'HTML' + +HTML, + array( + 'autocomplete' => self::$this_tinymce ? 'off' : null, + 'editor_class' => trim( "{$set['editor_class']} wp-editor-area" ), + 'height' => ! empty( $set['editor_height'] ) + ? array( 'style' => "height: {$set['editor_height']}px;" ) + : array( 'rows' => (string) $set['textarea_rows'] ), + 'id' => $editor_id, + 'name' => $set['textarea_name'], + 'tabindex' => $set['tabindex'] ? (string) $set['tabindex'] : null, + ) + ) . + '
' ); // Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat). @@ -300,12 +329,16 @@ public static function editor( $content, $editor_id, $settings = array() ) { $content = apply_filters_deprecated( 'richedit_pre', array( $content ), '4.3.0', 'format_for_editor' ); } - if ( false !== stripos( $content, 'textarea' ) ) { - $content = preg_replace( '%next_tag( 'TEXTAREA' ) ) { + if ( $editor_id === $processor->get_attribute( 'id' ) ) { + $processor->set_modifiable_text( $content ); + break; + } } + $the_editor = $processor->get_updated_html(); - printf( $the_editor, $content ); - echo "\n
\n\n"; + echo "{$the_editor}\n
\n\n"; self::editor_settings( $editor_id, $set ); } diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index fe4ac3cba3b64..fa86d8a28dec6 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -2826,6 +2826,50 @@ public function get_modifiable_text() { return $decoded; } + /** + * Sets the modifiable text for the matched token, if possible. + * + * @param string $text Replace the modifiable text with this string. + * @return bool Whether the modifiable text was updated. + */ + public function set_modifiable_text( $text ) { + if ( null === $this->text_starts_at || ! is_string( $text ) ) { + return false; + } + + switch ( $this->get_token_name() ) { + case '#text': + $this->lexical_updates[] = new WP_HTML_Text_Replacement( + $this->text_starts_at, + $this->text_length, + esc_html( $text ) + ); + break; + + case 'TEXTAREA': + $this->lexical_updates[] = new WP_HTML_Text_Replacement( + $this->text_starts_at, + $this->text_length, + preg_replace( '~lexical_updates[] = new WP_HTML_Text_Replacement( + $this->text_starts_at, + $this->text_length, + preg_replace( '~get_updated_html(); + return true; + } + /** * Updates or creates a new attribute on the currently matched tag with the passed value. *