- Fix parsing of the init array in script-loader.
- Do not JSON encode the options object when outputting it from PHP.
- Remove JSON decoding of TinyMCE's `style_formats` option.

Props azaozz.
Merges [43867] to trunk.
Fixes #45221.

git-svn-id: https://develop.svn.wordpress.org/trunk@44236 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2018-12-16 20:23:57 +00:00
parent 3bcf9f7e46
commit 55f4475f9f
1 changed files with 108 additions and 103 deletions

View File

@ -461,17 +461,8 @@ function wp_default_packages_inline_scripts( &$scripts ) {
'after' 'after'
); );
/* This filter is documented in wp-includes/class-wp-editor.php */ // TinyMCE init.
$tinymce_settings = apply_filters( $tinymce_plugins = array(
'tiny_mce_before_init',
array(
'plugins' => implode(
',',
array_unique(
/* This filter is documented in wp-includes/class-wp-editor.php */
apply_filters(
'tiny_mce_plugins',
array(
'charmap', 'charmap',
'colorpicker', 'colorpicker',
'hr', 'hr',
@ -490,17 +481,13 @@ function wp_default_packages_inline_scripts( &$scripts ) {
'wpdialogs', 'wpdialogs',
'wptextpattern', 'wptextpattern',
'wpview', 'wpview',
) );
)
)
),
'toolbar1' => implode(
',',
array_merge(
/* This filter is documented in wp-includes/class-wp-editor.php */ /* This filter is documented in wp-includes/class-wp-editor.php */
apply_filters( $tinymce_plugins = apply_filters( 'tiny_mce_plugins', $tinymce_plugins, 'classic-block' );
'mce_buttons', $tinymce_plugins = array_unique( $tinymce_plugins );
array(
$toolbar1 = array(
'formatselect', 'formatselect',
'bold', 'bold',
'italic', 'italic',
@ -515,18 +502,13 @@ function wp_default_packages_inline_scripts( &$scripts ) {
'wp_more', 'wp_more',
'spellchecker', 'spellchecker',
'wp_add_media', 'wp_add_media',
), 'kitchensink',
'editor' );
),
array( 'kitchensink' )
)
),
'toolbar2' => implode(
',',
/* This filter is documented in wp-includes/class-wp-editor.php */ /* This filter is documented in wp-includes/class-wp-editor.php */
apply_filters( $toolbar1 = apply_filters( 'mce_buttons', $toolbar1, 'classic-block' );
'mce_buttons_2',
array( $toolbar2 = array(
'strikethrough', 'strikethrough',
'hr', 'hr',
'forecolor', 'forecolor',
@ -538,36 +520,59 @@ function wp_default_packages_inline_scripts( &$scripts ) {
'undo', 'undo',
'redo', 'redo',
'wp_help', 'wp_help',
),
'editor'
)
),
/* This filter is documented in wp-includes/class-wp-editor.php */
'toolbar3' => implode( ',', apply_filters( 'mce_buttons_3', array(), 'editor' ) ),
/* This filter is documented in wp-includes/class-wp-editor.php */
'toolbar4' => implode( ',', apply_filters( 'mce_buttons_4', array(), 'editor' ) ),
/* This filter is documented in wp-includes/class-wp-editor.php */
'external_plugins' => apply_filters( 'mce_external_plugins', array() ),
),
'editor'
); );
if ( isset( $tinymce_settings['style_formats'] ) && is_string( $tinymce_settings['style_formats'] ) ) { /* This filter is documented in wp-includes/class-wp-editor.php */
// Decode the options as we used to recommende json_encoding the TinyMCE settings. $toolbar2 = apply_filters( 'mce_buttons_2', $toolbar2, 'classic-block' );
$tinymce_settings['style_formats'] = json_decode( $tinymce_settings['style_formats'] ); /* This filter is documented in wp-includes/class-wp-editor.php */
$toolbar3 = apply_filters( 'mce_buttons_3', array(), 'classic-block' );
/* This filter is documented in wp-includes/class-wp-editor.php */
$toolbar4 = apply_filters( 'mce_buttons_4', array(), 'classic-block' );
/* This filter is documented in wp-includes/class-wp-editor.php */
$external_plugins = apply_filters( 'mce_external_plugins', array(), 'classic-block' );
$tinymce_settings = array(
'plugins' => implode( ',', $tinymce_plugins ),
'toolbar1' => implode( ',', $toolbar1 ),
'toolbar2' => implode( ',', $toolbar2 ),
'toolbar3' => implode( ',', $toolbar3 ),
'toolbar4' => implode( ',', $toolbar4 ),
'external_plugins' => wp_json_encode( $external_plugins ),
'classic_block_editor' => true,
);
/* This filter is documented in wp-includes/class-wp-editor.php */
$tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );
// Do "by hand" translation from PHP array to js object.
// Prevents breakage in some custom settings.
$init_obj = '';
foreach ( $tinymce_settings as $key => $value ) {
if ( is_bool( $value ) ) {
$val = $value ? 'true' : 'false';
$init_obj .= $key . ':' . $val . ',';
continue;
} elseif ( ! empty( $value ) && is_string( $value ) && (
( '{' == $value{0} && '}' == $value{strlen( $value ) - 1} ) ||
( '[' == $value{0} && ']' == $value{strlen( $value ) - 1} ) ||
preg_match( '/^\(?function ?\(/', $value ) ) ) {
$init_obj .= $key . ':' . $value . ',';
continue;
}
$init_obj .= $key . ':"' . $value . '",';
} }
$scripts->localize( $init_obj = '{' . trim( $init_obj, ' ,' ) . '}';
'wp-block-library',
'wpEditorL10n', $script = 'window.wpEditorL10n = {
array( tinymce: {
'tinymce' => array( baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ',
'baseURL' => includes_url( 'js/tinymce' ), suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ',
'suffix' => SCRIPT_DEBUG ? '' : '.min', settings: ' . $init_obj . ',
'settings' => $tinymce_settings, }
), }';
)
); $scripts->add_inline_script( 'wp-block-library', $script, 'before' );
} }
/** /**