AdvancedCustomFields / AdvancedCustomFields/acf

filter wysiwyg_tinymce_settings breaking

Open
#906 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
The ACF Block content doesn't update when i add custom WYSIWYG buttons. There's also no console errors.

Ive tried this the WYSIWYG editor on delayed initialization and default.

When I add the code below to trigger on the front-end, the 'Text' tab code view shows the correct HTML updates, but the 'Visual' tab and the WP Block HTML ( rendered and code editor view ) are not.

Caveat** If i tab over to the 'Text' view and manually change the content or even just a hard return, the editor and WP Block update and render properly.

To Reproduce
Steps to reproduce the behavior:

  1. Add this js to the front-end during admin 'post' editing mode
  2. Wait for Gutenberg to load/render
  3. Select a block w/ the WYSIWYG editor in it.
  4. Enter any text, select a single word, click the 'Bold' button, notice the WYSIWYG editor bolds the text, but not the WP Block render view
  5. Next, click on same Block with a WYSIWYG editor in it, and click on any of the custom buttons, see the content change in the WYSIWYG editor, but not the WP Block render view although it should just like the default buttons like 'bold' would
  6. CAVEAT** ( See above in description ) and manual hard-return in the 'text' tab renders the WYSIWYG content correctly.

Expected behavior
Expect that clicking on any of the custom buttons in the ACF fields in page or block will update the WP Gutenberg Block render template live like normal.

Screenshots or Video
...

Code

acf.add_filter('wysiwyg_tinymce_settings', ( mceInit, id, field ) => {

		// // mceInit.height = 50;
		// // mceInit.apply_source_formatting = true;
      // // mceInit.verify_html = false;
		mceInit.extended_valid_elements = "span[class|name|id]",
		mceInit.toolbar1 = `${ mceInit.toolbar1 }forecolor,custom-br-shortcode,custom-headline,custom-color-solid`;
		// mceInit.toolbar2 = '';
		mceInit.setup = (editor) => 
		{
			
			// editor.on('change', function(e) {
			// 	console.log( 'Editor change triggered...' );
			// 	document.getElementById( `#${ id }`).dispatchEvent( new Event( 'change') );
			// });
			
			editor.addButton('custom-br-shortcode', {
				type: 'listbox',
				text: 'Break',
				values: [
					{ text: 'BR: None', value: '' },
					{ text: 'BR: Mobile', value: '[br-m]' },
					{ text: 'BR: Mobile to Tablet', value: '[br-m-t]' },
					{ text: 'BR: Mobile to Desktop', value: '[br-m-d]' },
					{ text: 'BR: Tablet', value: '[br-t]' },
					{ text: 'BR: Tablet to Desktop', value: '[br-t-d]' },
					{ text: 'BR: Desktop', value: '[br-d]' },
				 ],
				onselect: function ( _event ) {
					editor.insertContent( this.value() );
				 },
			});

			editor.addButton('custom-headline', {
				type: 'listbox',
				text: 'Headline',
				values: [
					{ text: 'H1', value: 'h1' },
					{ text: 'H2', value: 'h2' },
				 ],
				onselect: function ( _event ) {

					const content = editor.getContent();
					const contentSelect = editor.selection.getContent();
					const contentUpdate = content.replace( editor.selection.getContent(), `<${ this.value() }>${ editor.selection.getContent() }</${ this.value() }>\n` );
					editor.setContent( contentUpdate );
				 },
			});

			editor.addButton('custom-color-solid', {
				type: 'listbox',
				text: 'Color',
				values: [
					{ text: 'Default', value: '' },
					{ text: 'Green, Forrest', value: 'clr-green-forrest' },
					{ text: 'Green, Lime', value: 'clr-green-lime' },
				 ],
				onselect: function ( _event ) 
				{
					const content = `<span class='${ this.value() }'>${ editor.selection.getContent() }</span>`;
					editor.selection.setContent( content );
				 },
			});
		}

		return mceInit;

	});

Version Information:

  • WordPress Version 6.4.3
  • PHP Version 8.1.23
  • ACF Version ACF PRO 6.2.9
  • Browser: All

Additional context

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the wysiwyg_tinymce_settings filter and its TinyMCE setup while reproducing this in an ACF block under Gutenberg. Compare the default Bold control with custom buttons using editor.insertContent, editor.setContent, and editor.selection.setContent. Done means custom-button edits update the Gutenberg block render and HTML views consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php, wordpress
Domain
backend, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.