Skip to content

Conversation

@typomaniac77
Copy link

@typomaniac77 typomaniac77 commented Mar 4, 2025

Closes #974

@crftwrk crftwrk added this to v6.2.0 Mar 4, 2025
@crftwrk crftwrk moved this to In Progress in v6.2.0 Mar 4, 2025
@crftwrk crftwrk self-requested a review March 4, 2025 11:15
@crftwrk crftwrk marked this pull request as draft March 5, 2025 08:52
@crftwrk
Copy link
Member

crftwrk commented Mar 5, 2025

It seems that this needs more attention. #976 does not enqueue editor-style if Block editor is in use, so I closed it and let's go further here.

Have following improved idea which enqueues editor-styles only if Block editor is in use. It works at first glance fine with Block, Classic and in general if TinyMCE is active:

/**
 * Register editor styles only if the block editor is active.
 */
function bootscore_add_editor_styles() {
  add_action('current_screen', function($screen) {
    if (function_exists('use_block_editor_for_post_type') && use_block_editor_for_post_type($screen->post_type)) {
      add_theme_support('editor-styles');
      add_editor_style('assets/css/main.css');
    }
  });
}
add_action('after_setup_theme', 'bootscore_add_editor_styles');

Let me know what you think!

@typomaniac77
Copy link
Author

great! That works!

@crftwrk
Copy link
Member

crftwrk commented Mar 6, 2025

Unfortunately, I discovered one more issue. If editor-style is enqueued like in my comment above, styles are not added to the pattern library Backend > Appearance > Patterns > Bootscore. Means we have to refactor the entire scripts:

/**
* Register editor styles.
*/
function bootscore_add_editor_styles() {
// Add support for editor styles and main.css for the editor
add_theme_support('editor-styles');
add_editor_style('assets/css/main.css');
}
add_action('after_setup_theme', 'bootscore_add_editor_styles');
/**
* Enqueue styles for block editor and Pattern Library.
*/
function bootscore_enqueue_editor_and_pattern_library_styles($hook_suffix) {
$screen = get_current_screen();
// Enqueue editor.css only in the block editor
if ($screen && $screen->is_block_editor) {
wp_enqueue_style('editor-style', get_stylesheet_directory_uri() . '/assets/css/editor.css');
}
// Enqueue main.css only in the Pattern Library
if ('appearance_page_edit-wp-patterns' === $hook_suffix) {
wp_enqueue_style('bootscore-pattern-library-styles', get_stylesheet_directory_uri() . '/assets/css/main.css');
}
}
add_action('admin_enqueue_scripts', 'bootscore_enqueue_editor_and_pattern_library_styles');

@crftwrk
Copy link
Member

crftwrk commented Mar 10, 2025

@typomaniac77 Let's try another approach.

Go to:

$content_style = 'body.mce-content-body { margin: 9px 10px; font-family: inherit; }';

and add height: auto;:

  $content_style = 'body.mce-content-body { margin: 9px 10px; font-family: inherit; height: auto;}';

This works fine in my case for block and classic editor. I tried to do this changes by myself in your branch but I have no access to it.

@typomaniac77 @faridulhassan This have to be deeply tested in both, block and classic editor on your side as well. If you agree with this changes, we can fix this bug quickly.

@faridulhassan
Copy link

@crftwrk
Screenshot 2025-03-11 at 3 20 12 PM
,
Though the tinymce height is fixed in this way, but child theme's main.css file is loading into dashboard editing page (Screenshot attached).

Your following approach worked fine for me. It fixes the auto height issue and doesn't load main.css in dashboard page.

function bootscore_add_editor_styles() { add_action('current_screen', function($screen) { if (function_exists('use_block_editor_for_post_type') && use_block_editor_for_post_type($screen->post_type)) { add_theme_support('editor-styles'); add_editor_style('assets/css/main.css'); } }); } add_action('after_setup_theme', 'bootscore_add_editor_styles');

@crftwrk
Copy link
Member

crftwrk commented Mar 11, 2025

@faridulhassan

Though the tinymce height is fixed in this way

Great, are you able to create quickly a new pull request? Then we can merge this directly and release a new patch soon.

but child theme's main.css file is loading into dashboard editing page

Yes, that's how WordPress handles it and it's intended. You can check this by installing a default WP theme https://wordpress.org/themes/twentytwentyone/ and check the Classic Editor (Styles) in the backend.

But we can wrap the editor-styles enqueue in a filter in a second pull request to disable editor-styles with a single line in child's functions.php. For example like this:

/**
 * Disable editor-style
 */
add_filter('bootscore/load/editor_styles', '__return_false');

Do you agree?

@crftwrk
Copy link
Member

crftwrk commented Mar 12, 2025

@faridulhassan The more I think about it, I believe this is a bug (or it is intended to move users to the GB editor) came with WordPress 6.7.2. It does not happen on earlier WP versions and default themes editor-style is enqueued to classic editor as well.

There is no way to disable editor-styles in classic editor, we can only stop the growing by adding the height CSS to TinyMCE.

Edit: This will be fixed in WP 6.8

@crftwrk
Copy link
Member

crftwrk commented Mar 13, 2025

#983

@crftwrk crftwrk closed this Mar 13, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in v6.2.0 Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

TinyMCE in Backend keeps »growing« vertically in combination with wpbakery

3 participants