WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#19437 closed enhancement (fixed)

Pass post type as a class to TinyMCE init

Reported by: markjaquith Owned by: azaozz
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: TinyMCE Keywords:
Focuses: Cc:

Description

If we pass the post type as a class to TinyMCE, editor-styles.css can target rules to specific post types which may be displayed differently.

<?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabindex' => 1, 'tinymce' => array( 'body_class' => 'post-type-' . $post_type ) ) ); ?>

Attachments (1)

19437.child-editor-style.patch (1.2 KB) - added by SergeyBiryukov 2 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 nacin2 years ago

+100. Ran into this earlier today.

comment:2 azaozz2 years ago

  • Component changed from General to Editor
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to enhancement

Been looking into something similar recently too. However to set anything into TinyMCE's iframe it has to go through JS (as it's 100% JS generated). So we need a JS "helper" function to modify classes (and IDs?) in the iframe document.

Also it seems we need to make editor-style.css more structured/predictable. There are styles/selectors that shouldn't go in there and all selectors should be exactly the same as in the theme's style.css.

Version 0, edited 2 years ago by azaozz (next)

comment:3 johnjamesjacoby2 years ago

Just dropping a note while it's on my mind, this will become increasingly more important as plugins (like bbPress/BuddyPress) start including wp_editor() in places outside of the traditional post editor; within the theme, for example.

comment:4 gluten2 years ago

It would also be useful to have a class added with the wp_editor() $editor_id to allow for unique styling of TinyMCE editors.

comment:5 SergeyBiryukov2 years ago

  • Keywords needs-patch added

comment:6 azaozz2 years ago

  • Component changed from Editor to TinyMCE
  • Keywords needs-patch removed
  • Milestone changed from Future Release to 3.4

3.4 as part of the editor enhancements.

comment:7 azaozz2 years ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In [19912]:

Add the editor ID and the post type (when available) as classes to the TinyMCE's body, fixes #19437

comment:8 follow-up: jamescollins2 years ago

For security, do we need to esc_attr() the $body_class variable?

That's what we do at the end of the get_body_class() function (http://core.trac.wordpress.org/browser/trunk/wp-includes/post-template.php#L545).

comment:9 nacin2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:11 in reply to: ↑ 8 azaozz2 years ago

Replying to jamescollins:

For security, do we need to esc_attr() the $body_class variable?

Don't see a point in escaping the editor ID or the post_type strings.

That's what we do at the end of the get_body_class() function (http://core.trac.wordpress.org/browser/trunk/wp-includes/post-template.php#L545).

Right, seems that's not needed there either, the HTML class attribute allows all UTF-8 chars with very few exceptions.

comment:12 azaozz2 years ago

In [20054]:

Improve adding more css classes to the editor body, add "rtl", "ie7", "ie8", "ie9" so they can be targeted in editor-style.css, see #19437

comment:13 azaozz2 years ago

In [20059]:

Don't pass non-existing rtl stylesheet to TinyMCE, update phpdoc for add_editor_style(), see #19437

comment:14 follow-up: SergeyBiryukov2 years ago

[20059] brings back #18457. 19437.child-editor-style.patch is an attempt to fix that.

comment:15 in reply to: ↑ 14 azaozz2 years ago

Replying to SergeyBiryukov:

Wouldn't that add the child theme's stylesheet before the parent theme's? At first look in the patch the parent theme loop is after the child theme loop:

Edit: nevermind, that's otherwise round. It's the differences between get_stylesheet_directory() and get_template_directory().

Last edited 2 years ago by azaozz (previous) (diff)

comment:16 azaozz2 years ago

In [20342]:

Fix adding of parent theme's editor-style before child theme's, props SergeyBiryukov, see #19437

comment:17 azaozz2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Seems to work properly

Note: See TracTickets for help on using tickets.