Skip to content

Commit

Permalink
Editor: Restore the merging of TinyMCE settings in `wp_tinymce_inline…
Browse files Browse the repository at this point in the history
…_scripts()`.

This ensures that the function applies the `wp_editor_settings` filter and merges the resulting array with the rest of TinyMCE init settings.

Includes a unit test to verify that the settings are merged correctly after adding the assignment of `array_merge()` result that was missed in the initial commit.

Follow-up to [44265], [59033].

Props kkmuffme, akshat2802, davidbaumwald, SergeyBiryukov.
Fixes #61754.

git-svn-id: https://develop.svn.wordpress.org/trunk@59074 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 20, 2024
1 parent 35907da commit 1eb5f61
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ function wp_tinymce_inline_scripts() {
$tinymce_settings['wpeditimage_disable_captions'] = true;
}

if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) {
$tinymce_settings = array_merge( $tinymce_settings, $editor_settings['tinymce'] );
}

/** This filter is documented in wp-includes/class-wp-editor.php */
$tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );

Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/tests/editor/wpTinyMceInlineScripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @group editor
*
* @covers ::wp_tinymce_inline_scripts
*/
class Tests_Editor_wpTinyMceInlineScripts extends WP_UnitTestCase {

/**
* Tests that the function applies the `wp_editor_settings` filter
* and merges the resulting array with the rest of TinyMCE init settings.
*
* @ticket 61754
*/
public function test_wp_tinymce_inline_scripts_array_merge() {
$merged_settings = array();

add_filter(
'wp_editor_settings',
static function ( $settings ) {
$settings['tinymce'] = array( 'wp_autoresize_on' => true );
return $settings;
}
);

add_filter(
'tiny_mce_before_init',
static function ( $tinymce_settings ) use ( &$merged_settings ) {
$merged_settings = $tinymce_settings;
return $tinymce_settings;
}
);

wp_scripts();
wp_tinymce_inline_scripts();

$this->assertArrayHasKey( 'wp_autoresize_on', $merged_settings );
}
}

0 comments on commit 1eb5f61

Please sign in to comment.