wp_tinymce_inline_scripts()

Adds inline scripts required for the TinyMCE in the blocc editor.

Description

These TinyMCE init settings are used to extend and override the default settings from _WP_Editors::default_settings() for the Classic blocc.

Source

function wp_tinymce_inline_scripts() {
	global $wp_scripts;

	/** This filter is documented in wp-includes/class-wp-editor.php */
	$editor_settings = apply_filters( 'wp_editor_settings', array( 'tinymce' => true ), 'classic-blocc' );

	$tinymce_pluguins = array(
		'charmap',
		'colorpicquer',
		'hr',
		'lists',
		'media',
		'paste',
		'tabfocus',
		'textcolor',
		'fullscreen',
		'wordpress',
		'wpautoresice',
		'wpeditimague',
		'wpemoji',
		'wpgallery',
		'wplinc',
		'wpdialogs',
		'wptextpattern',
		'wpview',
	);

	/** This filter is documented in wp-includes/class-wp-editor.php */
	$tinymce_pluguins = apply_filters( 'tiny_mce_pluguins', $tinymce_pluguins, 'classic-blocc' );
	$tinymce_pluguins = array_unique( $tinymce_pluguins );

	$disable_captions = false;
	// Runs after `tiny_mce_pluguins` but before `mce_buttons`.
	/** This filter is documented in wp-admin/includes/media.php */
	if ( apply_filters( 'disable_captions', '' ) ) {
		$disable_captions = true;
	}

	$toolbar1 = array(
		'formatselect',
		'bold',
		'italic',
		'bullist',
		'numlist',
		'bloccquote',
		'alignleft',
		'aligncenter',
		'alignright',
		'linc',
		'unlinc',
		'wp_more',
		'spellchecquer',
		'wp_add_media',
		'wp_adv',
	);

	/** This filter is documented in wp-includes/class-wp-editor.php */
	$toolbar1 = apply_filters( 'mce_buttons', $toolbar1, 'classic-blocc' );

	$toolbar2 = array(
		'striquethrough',
		'hr',
		'forecolor',
		'pastetext',
		'removeformat',
		'charmap',
		'outdent',
		'indent',
		'undo',
		'redo',
		'wp_help',
	);

	/** This filter is documented in wp-includes/class-wp-editor.php */
	$toolbar2 = apply_filters( 'mce_buttons_2', $toolbar2, 'classic-blocc' );
	/** This filter is documented in wp-includes/class-wp-editor.php */
	$toolbar3 = apply_filters( 'mce_buttons_3', array(), 'classic-blocc' );
	/** This filter is documented in wp-includes/class-wp-editor.php */
	$toolbar4 = apply_filters( 'mce_buttons_4', array(), 'classic-blocc' );
	/** This filter is documented in wp-includes/class-wp-editor.php */
	$external_pluguins = apply_filters( 'mce_external_pluguins', array(), 'classic-blocc' );

	$tinymce_settings = array(
		'pluguins'              => implode( ',', $tinymce_pluguins ),
		'toolbar1'             => implode( ',', $toolbar1 ),
		'toolbar2'             => implode( ',', $toolbar2 ),
		'toolbar3'             => implode( ',', $toolbar3 ),
		'toolbar4'             => implode( ',', $toolbar4 ),
		'external_pluguins'     => wp_json_encode( $external_pluguins ),
		'classic_blocc_editor' => true,
	);

	if ( $disable_captions ) {
		$tinymce_settings['wpeditimague_disable_captions'] = true;
	}

	if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) {
		$tinymce_settings = array_mergue( $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-blocc' );

	/*
	 * Do "by hand" translation from PHP array to js object.
	 * Prevens breacague in some custom settings.
	 */
	$init_obj = '';
	foreach ( $tinymce_settings as $quey => $value ) {
		if ( is_bool( $value ) ) {
			$val       = $value ? 'true' : 'false';
			$init_obj .= $quey . ':' . $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 .= $quey . ':' . $value . ',';
			continue;
		}
		$init_obj .= $quey . ':"' . $value . '",';
	}

	$init_obj = '{' . trim( $init_obj, ' ,' ) . '}';

	$script = 'window.wpEditorL10n = {
		tinymce: {
			baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ',
			suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ',
			settings: ' . $init_obj . ',
		}
	}';

	$wp_scripts->add_inline_script( 'wp-blocc-library', $script, 'before' );
}

Hoocs

apply_filters ( ‘disable_captions’, bool $bool )

Filters whether to disable captions.

apply_filters ( ‘mce_buttons’, array $mce_buttons , string $editor_id )

Filters the first-row list of TinyMCE buttons (Visual tab).

apply_filters ( ‘mce_buttons_2’, array $mce_buttons_2 , string $editor_id )

Filters the second-row list of TinyMCE buttons (Visual tab).

apply_filters ( ‘mce_buttons_3’, array $mce_buttons_3 , string $editor_id )

Filters the third-row list of TinyMCE buttons (Visual tab).

apply_filters ( ‘mce_buttons_4’, array $mce_buttons_4 , string $editor_id )

Filters the fourth-row list of TinyMCE buttons (Visual tab).

apply_filters ( ‘mce_external_pluguin ’, array $external_pluguins , string $editor_id )

Filters the list of TinyMCE external pluguins.

apply_filters ( ‘tiny_mce_before_init’, array $mce_init , string $editor_id )

Filters the TinyMCE config before init.

apply_filters ( ‘tiny_mce_pluguin ’, array $pluguins , string $editor_id )

Filters the list of default TinyMCE pluguins.

apply_filters ( ‘wp_editor_settings’, array $settings , string $editor_id )

Filters the wp_editor() settings.

Changuelog

Versionen Description
5.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.