From 620704320eb2af18607e6549f2cf01d71e1222c7 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 11 Jul 2019 18:29:09 +0000 Subject: [PATCH] Editor: Make registered editor stylesheets (editor-style.css) available to the front-end. Props webmandesign, azaozz. Fixes #34882. git-svn-id: https://develop.svn.wordpress.org/trunk@45621 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-editor.php | 24 +++++++++++++++--------- src/wp-includes/theme.php | 8 +++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 293cb0138e..fb0a8eb80d 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -540,18 +540,24 @@ final class _WP_Editors { $settings['wpeditimage_disable_captions'] = true; } - $mce_css = $settings['content_css']; - $editor_styles = get_editor_stylesheets(); + $mce_css = $settings['content_css']; - if ( ! empty( $editor_styles ) ) { - // Force urlencoding of commas. - foreach ( $editor_styles as $key => $url ) { - if ( strpos( $url, ',' ) !== false ) { - $editor_styles[ $key ] = str_replace( ',', '%2C', $url ); + // The `editor-style.css` added by the theme is generally intended for the editor instance on the Edit Post screen. + // Plugins that use wp_editor() on the front-end can decide whether to add the theme stylesheet + // by using `get_editor_stylesheets()` and the `mce_css` or `tiny_mce_before_init` filters, see below. + if ( is_admin() ) { + $editor_styles = get_editor_stylesheets(); + + if ( ! empty( $editor_styles ) ) { + // Force urlencoding of commas. + foreach ( $editor_styles as $key => $url ) { + if ( strpos( $url, ',' ) !== false ) { + $editor_styles[ $key ] = str_replace( ',', '%2C', $url ); + } } - } - $mce_css .= ',' . implode( ',', $editor_styles ); + $mce_css .= ',' . implode( ',', $editor_styles ); + } } /** diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index ccfa13974a..fe419ee08f 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -1924,15 +1924,13 @@ function wp_update_custom_css_post( $css, $args = array() ) { * Defaults to 'editor-style.css' */ function add_editor_style( $stylesheet = 'editor-style.css' ) { + global $editor_styles; + add_theme_support( 'editor-style' ); - if ( ! is_admin() ) { - return; - } - - global $editor_styles; $editor_styles = (array) $editor_styles; $stylesheet = (array) $stylesheet; + if ( is_rtl() ) { $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] ); $stylesheet[] = $rtl_stylesheet;