Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#36636 closed enhancement (wontfix)

allow add_editor_style() to include inline style

Reported by: selnomeria's profile selnomeria Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Editor Keywords:
Focuses: Cc:

Description (last modified by swissspidy)

add_editor_style() needs to return an url of style... but it is not always convenient for quick testing.
please, give us ability, to code inside that function, like this:

add_editor_style( "<style> .somehting{.....}</style>" );

thanks.

Change History (7)

#1 @swissspidy
9 years ago

  • Component changed from General to Editor
  • Description modified (diff)
  • Summary changed from allow ADD_EDITOR_STYLE() to include inline style to allow add_editor_style() to include inline style
  • Type changed from defect (bug) to enhancement
  • Version set to 3.0

#2 @swissspidy
9 years ago

add_editor_style() is meant for theme developers to make the editor style look more like the front-end of the site ("What you see is what you get").

This is usually done by either using a specific stylesheet in the theme or creating an editor-style.css file which uses @import to load the necessary styles.

How would allowing inline styles help here? You can also debug your CSS when it's in a separate file.

#3 @jcastaneda
9 years ago

If you really are looking to add inline styles there is also the function wp_add_inline_style():
https://developer.wordpress.org/reference/functions/wp_add_inline_style/

#4 @azaozz
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Agree with @swissspidy. Dynamically adding CSS to the editor iframe is "out of scope" for core. BTW even add_editor_style() is a helper/convenience function. The "real" way of adding more stylesheets to the editor is by using the mce_css filter (yes, the name is not that intuitive).

If you want to add CSS directly to the editor, have a look at its settings: https://www.tinymce.com/docs/configure/content-appearance/#content_style. However this is not recommended for a plugin that will run in production on different sites. Can affect it pretty drastically.

#5 follow-up: @selnomeria
9 years ago

a while ago, i posted in FB support that "almost every time I come accross a problem or find out a good suggesion, it doesnt matter if i tell that to support, because it wont ever be taken into account, they will always say opposite".
this is evergreen truth for me, like in this situation. (because as i say, that it is problem for me(like one of developers), so it could be problematic for many others too... when working in notepad++ ftp connections, it is not easy to create a new file "editor_style.css" and upload it to site, and then blablabla... so it was a very quick and helpful way, to have a function, which will directly inject something style into MCE window... lets people use "add_editor_style", but what if you will take into account an ask of a particular person, and make a function, which will do that. it will be HELP for me, for many of like me...)

#6 in reply to: ↑ 5 ; follow-up: @swissspidy
9 years ago

Replying to selnomeria:

a while ago, i posted in FB support that "almost every time I come accross a problem or find out a good suggesion, it doesnt matter if i tell that to support, because it wont ever be taken into account, they will always say opposite".
this is evergreen truth for me, like in this situation. (because as i say, that it is problem for me(like one of developers), so it could be problematic for many others too... when working in notepad++ ftp connections, it is not easy to create a new file "editor_style.css" and upload it to site, and then blablabla... so it was a very quick and helpful way, to have a function, which will directly inject something style into MCE window... lets people use "add_editor_style", but what if you will take into account an ask of a particular person, and make a function, which will do that. it will be HELP for me, for many of like me...)

Apart from this not being an ideal workflow, nobody stops you from creating such a function yourself. TinyMCE supports it, but it's just not something we'd implement in core for the reasons mentioned earlier.

For example, you could use something like that to achieve what you want:

<?php

/**
 * Adds inline style to TinyMCE.
 *
 * Please never use this in production.
 *
 * @param array $settings TinyMCE settings
 * @return array
 */
function wptrac_36636_editor_inline_style( $settings ) {
        $settings['content_style'] = '* {outline: 1px solid red;}';

        return $settings;
}

add_filter( 'tiny_mce_before_init', 'wptrac_36636_editor_inline_style' );

#7 in reply to: ↑ 6 @selnomeria
9 years ago

Replying to swissspidy:

Apart from ................

swissspidy!!!!!!!!!!!!!!! WOW, THANKS! that is I was searching for!

Last edited 9 years ago by selnomeria (previous) (diff)
Note: See TracTickets for help on using tickets.