Opened 10 years ago
Closed 6 years ago
#34882 closed enhancement (fixed)
make registered editor stylesheets available to frontend
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | TinyMCE | Keywords: | |
Focuses: | Cc: |
Description
Currently add_editor_style() does not register a style as of theme.php:~1318
function add_editor_style( $stylesheet = 'editor-style.css' ) { add_theme_support( 'editor-style' ); if ( ! is_admin() ) return; ...
For custom frontend usage of wp_editor, there is currently no way to access any custom stylesheets because they are never registered.
The admin check could be moved to class-wp-editor.php:~564 like
if (is_admin() ) { $editor_styles = get_editor_stylesheets(); if ( ! empty( $editor_styles ) ) { foreach ( $editor_styles as $style ) { $mce_css[] = $style; } } }
That way, one could use 'mce_css' filter to manually add any custom stylesheets back to the array of stylesheets.
Attachments (1)
Change History (12)
#1
@
10 years ago
- Milestone Awaiting Review deleted
- Resolution set to maybelater
- Status changed from new to closed
#3
@
9 years ago
Adding an editor stylesheet(s) is responsibility of the theme, right?
In that case a plugin using the TinyMCE editor on frontend doesn't know about what editor stylesheets the theme includes. So, using mce_css
filter in plugin doesn't make sense really.
Likewise, if the theme wants its editor stylesheets to be frontend available, it should hook to mce_css
right from the start. Then what point there is to use add_editor_style()
?
I've proposed the way which filters the ! is_admin()
conditional inside add_editor_style()
, so a theme can use add_editor_style()
as usually, while a plugin which uses TinyMCE editor on frontend can hook onto the conditional and change it when needed so it allows theme editor stylesheets in frontend editor.
What do you think about that?
#4
@
9 years ago
- Keywords has-patch added
Hey, I've just proposed a patch that could help with this issue too.
#6
@
9 years ago
@webmandesign, I'm not sure if adding another filter there is the best solution. The "patch" proposed by @ungestaltbar in the ticket description looks pretty good too. Seems we should be letting themes register editor stylesheet on the front-end.
The next step would be to find out why is_admin()
was added there. Is it a simple optimization (less code to run on every front-end page load) or there was another reason too.
#7
@
9 years ago
- Focuses ui administration removed
- Keywords has-patch removed
- Milestone set to Future Release
- Resolution maybelater deleted
- Status changed from closed to reopened
#8
@
9 years ago
Hi,
The reason why I used a filter is due to the fact that I am not sure why there is the is_admin()
check. Might be simple optimization, might be something else. And as I didn't want to break anything, I've used the most flexible solution to this problem without actually changing the original functionality.
Of course, if is_admin()
check is not needed there, then I would remove it completely. But I don't know the history of it and don't know how to find out, sorry.
But, please, keep in mind that the solution proposed in this ticket would mean a theme author needs to register the editor stylesheets twice. Once in add_editor_style()
and second time with mce_css
filter. This is a bit too tedious and brings a question why should we use add_editor_style()
first place. I've described this in my previous comment.
Regards,
Oliver
#9
@
6 years ago
- Milestone set to 5.3
Fixing this is not as easy as it looks :)
The add_editor_style()
and editor-style.css
are specifically for the editor instance on the old Edit Post screen. If we suddenly add these styles to front-end instances of the editor (by removing the is_admin() conditional), chances are something will break or not match well.
On the other hand WP shouldn't prevent plugins to add these editor specific styles to front-end instances, even if not specifically tested by the theme. Thinking the solution proposed in the ticket description is preferable. It allows themes to always register editor-style.css
, and plugins to decide where to add it.
Patch coming up.
The
mce_css
filter can be used to add any stylesheets at any time. It is more powerful thanadd_editor_style()
as it doesn't limit the location to the current theme.Closing as maybelater as
mce_css
can be used for this.