Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
When a post is saved, check for tinymce and save any editors. #12568
This is an alternative fix to this PR: #12363
The other pull request imported tinymce and ran
This patch instead checks for window.tinymce and if found loops through the editors individually and calls the save() method of the editors. This will copy the tinymce editor content into the related textarea so the updated content is saved. Importantly, if the editor is on the text tab, the save method will NOT copy the tinymce content and instead leave the textarea as is. In other words, with this PR things are working as expected: the content from whichever tab (visual or text) that is visible will be saved.
Another note: this PR doesn't import the tinymce library or include the other updates the referenced PR had. This isn't needed, since we just use the window.tinymce object as is if it's found.
How has this been tested?
This was tested on WP 4.9.9-alpha-43656 and Chrome Version 70.0.3538.110 (Official Build) (64-bit). I tested on Firefox v63.
I tested this in a number of ways. I tested on new pages and posts. I tested updated the visual or text tabs. I tested with multiple editors from multiple plugins. I tested with the classic editor installed. I tested when saving a draft or publishing or clicking update.
All my tests passed.
Types of changes
(Note: There were other warnings in the file I changed that I ignored.)
Can we bring the package.json and changelog tweaks from https://github.com/WordPress/gutenberg/pull/12363/files too?
Updated the version in package.json and changelog.md. Let me know if I did this incorrectly. I'm confused by the empty sections for certain versions in the changelog.md. Is there a write up on how these components are versioned?
3 options left for the actual code here:
Adding a 4th that the current PR is using. Don't import tinymce, use tinyMCE.triggerSave()
A variation of this would be to use window.tinyMCE.triggerSave() to make sure we are talking about the "global" tinyMCE.