Skip to content

Commit 6207043

Browse files
committed
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
1 parent 944595c commit 6207043

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/wp-includes/class-wp-editor.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -540,18 +540,24 @@ public static function editor_settings( $editor_id, $set ) {
540540
$settings['wpeditimage_disable_captions'] = true;
541541
}
542542

543-
$mce_css = $settings['content_css'];
544-
$editor_styles = get_editor_stylesheets();
545-
546-
if ( ! empty( $editor_styles ) ) {
547-
// Force urlencoding of commas.
548-
foreach ( $editor_styles as $key => $url ) {
549-
if ( strpos( $url, ',' ) !== false ) {
550-
$editor_styles[ $key ] = str_replace( ',', '%2C', $url );
543+
$mce_css = $settings['content_css'];
544+
545+
// The `editor-style.css` added by the theme is generally intended for the editor instance on the Edit Post screen.
546+
// Plugins that use wp_editor() on the front-end can decide whether to add the theme stylesheet
547+
// by using `get_editor_stylesheets()` and the `mce_css` or `tiny_mce_before_init` filters, see below.
548+
if ( is_admin() ) {
549+
$editor_styles = get_editor_stylesheets();
550+
551+
if ( ! empty( $editor_styles ) ) {
552+
// Force urlencoding of commas.
553+
foreach ( $editor_styles as $key => $url ) {
554+
if ( strpos( $url, ',' ) !== false ) {
555+
$editor_styles[ $key ] = str_replace( ',', '%2C', $url );
556+
}
551557
}
552-
}
553558

554-
$mce_css .= ',' . implode( ',', $editor_styles );
559+
$mce_css .= ',' . implode( ',', $editor_styles );
560+
}
555561
}
556562

557563
/**

src/wp-includes/theme.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,15 +1924,13 @@ function wp_update_custom_css_post( $css, $args = array() ) {
19241924
* Defaults to 'editor-style.css'
19251925
*/
19261926
function add_editor_style( $stylesheet = 'editor-style.css' ) {
1927-
add_theme_support( 'editor-style' );
1927+
global $editor_styles;
19281928

1929-
if ( ! is_admin() ) {
1930-
return;
1931-
}
1929+
add_theme_support( 'editor-style' );
19321930

1933-
global $editor_styles;
19341931
$editor_styles = (array) $editor_styles;
19351932
$stylesheet = (array) $stylesheet;
1933+
19361934
if ( is_rtl() ) {
19371935
$rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] );
19381936
$stylesheet[] = $rtl_stylesheet;

0 commit comments

Comments
 (0)