Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyMCE inside a metabox creates console errors in GB #6305

Closed
kmgalanakis opened this issue Apr 20, 2018 · 4 comments
Closed

TinyMCE inside a metabox creates console errors in GB #6305

kmgalanakis opened this issue Apr 20, 2018 · 4 comments
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Meta Boxes A draggable box shown on the post editing screen [Type] Bug An existing feature does not function as intended
Milestone

Comments

@kmgalanakis
Copy link

kmgalanakis commented Apr 20, 2018

I use this sample code to create a metabox in the editor

add_action( 'add_meta_boxes',  function() {
	add_meta_box(
		'my_custom_tinymce_metabox',
		'My metabox title',
		'my_metabox_callback_function'
	);
});

function my_metabox_callback_function( $post ) {
	wp_editor(
		htmlspecialchars_decode( get_post_meta( $post->ID, 'metabox_tinymce_meta_key', true ) ),
		'metabox_tinymce_id',
		$settings = array(
			'textarea_name' => 'metabox_tinymce_name',
		)
	);
}

add_action( 'save_post',
	function( $post_id ) {
		if ( ! empty( $_POST['metabox_tinymce_name'] ) ) {
			$data = htmlspecialchars( $_POST['metabox_tinymce_name'] );
			update_post_meta( $post_id, 'metabox_tinymce_meta_key', $data );
		}
	}
);

The code works fine in the classic editor but in Gutenberg it creates a few console errors

Uncaught SyntaxError: Unexpected token <
tinymce.min.js?ver=4607-20180123:13 Uncaught TypeError: b is not a constructor
    at n (tinymce.min.js?ver=4607-20180123:13)
    at Object.r [as init] (tinymce.min.js?ver=4607-20180123:13)
    at q.<anonymous> (tinymce.min.js?ver=4607-20180123:13)
    at Array.<anonymous> (tinymce.min.js?ver=4607-20180123:3)
    at b (tinymce.min.js?ver=4607-20180123:1)
    at r (tinymce.min.js?ver=4607-20180123:3)
    at tinymce.min.js?ver=4607-20180123:3
    at HTMLScriptElement.f (tinymce.min.js?ver=4607-20180123:3)

Am I doing something wrong?

I see this comment #5181 (comment) but how could I use the same version as the version used in GB also in my metabox?

@youknowriad
Copy link
Contributor

Pretty sure this is a duplicate, but I'll have hard time retrieving the original issue ;)

Once we merge it will be fixed, this is caused by conflicting TinyMCE versions (see #3840 )

@kmgalanakis
Copy link
Author

It's always really hard for me to search for tickets everytime I need to open a new one, so I totally get you :)

If there is another ticket for this, feel free to close this as duplicate.

Thanks

@Soean Soean added [Component] TinyMCE [Feature] Meta Boxes A draggable box shown on the post editing screen labels Apr 20, 2018
@danielbachhuber danielbachhuber added the Backwards Compatibility Issues or PRs that impact backwards compatability label May 10, 2018
@danielbachhuber danielbachhuber added this to the Merge Proposal: Editor milestone May 10, 2018
@danielbachhuber
Copy link
Member

I've run into this same issue too.

@danielbachhuber danielbachhuber added the [Type] Bug An existing feature does not function as intended label May 10, 2018
@youknowriad
Copy link
Contributor

closed by #6848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Meta Boxes A draggable box shown on the post editing screen [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants