WYSIWYG Editor Not Working Correctly
- This topic has 48 replies, 12 voices, and was last updated 1 year, 11 months ago by
Peter.
-
AuthorPosts
-
January 5, 2021 at 11:25 PM #23858
SLG Marketing
ParticipantI've sent you a support email with access to our development server and a screencast of the issue.
January 7, 2021 at 4:37 AM #23871Teia Local Studio
ParticipantHej there!
Guys, I am having the same problem with METABOX 5.3.6.
I did register a WYSIWYG metabox and its behavior is completely erratic.The data I enter on the VISUAL tab is not visible no the CODE tab, and vice versa. Switching tabs does not update its contents. Also, sometimes it does not save when I publish the post. Sometimes it does. It's strange.
Reverting back to 5.3.5 solves the problem...
But it is not a solution — we need to stay up-to-date.Any ideas?
G.January 7, 2021 at 4:23 PM #23881SLG Marketing
ParticipantHi
Is there any progress on a solution? I need to update our customers ASAP.
January 7, 2021 at 7:07 PM #23895Anh Tran
KeymasterHi,
I’m working on this issue and will try to fix it tomorrow.
January 7, 2021 at 7:09 PM #23896Teia Local Studio
ParticipantTHANK you SO MUCH.
I am not in a hurry, but just want to have things working... Can't sleep well at night knowing about the bug. =) Ha ha!January 8, 2021 at 5:45 PM #23917Anh Tran
KeymasterHey guys, can you please try this file wysiwyg.js and see if it fixes the bug? Just copy it and overwrite the file
js/wysiwyg.js
in the plugin folder.I've fixed the Visual tab not showing content and not saving content.
January 8, 2021 at 6:03 PM #23920stijlXpres
ParticipantHi,
Yes! Just tested in on local installation. This seems to fix the bug!
January 8, 2021 at 6:12 PM #23921Teia Local Studio
ParticipantHello Ahn!
No, it is not working for me (although I have not tested on a clean default themed WordPress). Behavior:
If I open a post with already WYSIWYG content on it, the VISUAL tab do not load at all, just the CODE tab.
If I create a brand new post and add content, in VISUAL all is OK, I can write and yes, I can switch between CODE and VISUAL again. But in the moment I do save the post and screen reloads, the VISUAL is completely gone (I mean the textarea editor field too), but code is there.
On this very recent post, if I SHIFT+Refresh, the VISUAL field is back on track, however the content on it is rendered all in white color (can't see anything unless I select with mouse) and it is formatted in HTML, I can see the <p> tags, etc etc, exactly as the same on CODE tab.
Note: the meta-data IS saved correctly to the database.
But my theme situation could be interfering perhaps... I do register the metabox based on a IF/ELSE who looks what $POST_ID is being edited. It's something I needed to do in my theme for other reasons:
$post_id = null; if ( isset( $_GET['post'] ) ) { $post_id = intval( $_GET['post'] ); } elseif ( isset( $_POST['post_ID'] ) ) { $post_id = intval( $_POST['post_ID'] ); } if ($post_id == 111) { $meta_boxes[] = array( 'id' => 'mb-for-post-111', (...) ); } else { $meta_boxes[] = array( 'id' => 'mb-for-other-posts', (...) ); }
ALSO: I do erradicate anything related to GutenBerg on my themes. Using the plagued new editor is absolutely no option for me. I run this code to remove it:
// Begone, GutenBerg! add_filter('use_block_editor_for_post_type', '__return_false', 10); // Don't load GutenBerg-related stylesheets. add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 ); function remove_block_css() { wp_dequeue_style( 'wp-block-library' ); // WordPress core wp_dequeue_style( 'wp-block-library-theme' ); // WordPress core wp_dequeue_style( 'wc-block-style' ); // WooCommerce wp_dequeue_style( 'storefront-gutenberg-blocks' ); // Storefront theme }
I will try in a matter of minutes your new JS including the metabox on a standard way (yet on my theme) and also on a regular clean WordPress install, with the default theme.
See you soon.
Thanks so far.January 8, 2021 at 6:16 PM #23923Gunvor
ParticipantMy problem from post 23787 was not solved too
January 8, 2021 at 6:48 PM #23924Teia Local Studio
ParticipantOuch.
I think I found out the problem.
I have a snippet of code in my functions to FORCE REMOVE of EMPTY <p>'s. It seems this is what is causing me trouble. If so ----> YES, your current new WYSIWYG.JS is fixing the problem.
function remove_empty_p( $content ){ // clean up p tags around block elements $content = preg_replace( array( '#<p>\s*<(div|aside|section|article|header|footer)#', '#</(div|aside|section|article|header|footer)>\s*</p>#', '#</(div|aside|section|article|header|footer)>\s*<br ?/?>#', '#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#', '#<p>\s*</(div|aside|section|article|header|footer)#', ), array( '<$1', '</$1>', '</$1>', '<$1$2>', '</$1', ), $content ); return preg_replace('#<p>(\s| )*+(<br\s*/*>)*(\s| )*</p>#i', '', $content); } add_filter( 'the_content', 'remove_empty_p', 20, 1 );
I will test a bit more and will return soon.
Need to leave the house for a moment.January 8, 2021 at 9:03 PM #23927JC
ParticipantThe new js is working fine for me (#23854). Thank you!
January 8, 2021 at 9:21 PM #23928Teia Local Studio
ParticipantUpdate:
I tried including the WYSIWYG metabox in my theme using both ways, the regular method and with a IF/ELSE/$post_id condition (as mentioned above):
— Removed my custom snippet for blank <p>'s, it was not it the culprit, problem still there
— Emptied the cache, nothing
— When screen reloads, after saving, I see the visual editor on the VISUAL tab for a millisecond, then it disappears, like if it was a refresh applied on the elementSo, tried to inspect the new WYSISYG.JS file you shared this morning and solved my problem by commenting/removing the following:
// Force re-render editors. Use setTimeOut to run after all other code. Bug occurs in WP 5.6. $( function() { setTimeout( function() { $( '.rwmb-wysiwyg' ).each( transform ); }, 0 ); } );
But of course, this is not a ideal solution.
I tried also changing the number param of the setTimeout function... Anything higher than 12, 13, solves the problem. Putting like 20 or even 999 works too.But again, not ideal.
Oh my...
=(IN TIME: No JS errors show up in the console.
January 8, 2021 at 11:11 PM #23930Anh Tran
KeymasterHi Teia,
The code you commented is used to re-initialize the editors. In Gutenberg, editors are moved around the DOM, which makes them broken.
The number is just the delay in milliseconds to make the code run after editors are moved by Gutenberg. It's fine to increase to 100-200 😉
Are you using the classic editor?
I'll try to invest more in that tomorrow. If I found nothing, maybe increasing the delay to 100 is the solution.
January 8, 2021 at 11:12 PM #23931Anh Tran
KeymasterHi Gunvor, I'll fix your bug tomorrow. I don't think it's hard. Please wait.
January 9, 2021 at 1:46 AM #23934Teia Local Studio
ParticipantAhn,
I use only — and solely — the classic editor, everywhere. The GutenBerg Block Editor is not an option to me. I turn it off completely on my themes.
So, as for now, I will change the value to 100 and I will wait for your final word on this.
For curiosity — Do you think is it possible to modify the delay value using a external JS file loaded on admin using add_action('admin_enqueue_scripts', ...);??
Thanks so much for your always prompt help!
G. -
AuthorPosts
- You must be logged in to reply to this topic.