From 1fa46e49a81531a2bf2d59a122ede982ae9688e6 Mon Sep 17 00:00:00 2001 From: ideadude Date: Mon, 3 Dec 2018 18:19:22 -0500 Subject: [PATCH 1/8] When a post is saved, check for tinymce and save any editors. --- packages/edit-post/src/store/effects.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index 699b08f0636ed2..79b09f61d447fd 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -72,6 +72,13 @@ const effects = { } ); }, REQUEST_META_BOX_UPDATES( action, store ) { + // Saves the wp_editor fields + if ( window.tinymce ) { + for ( var i = 0; i < window.tinymce.editors.length; i++ ) { + window.tinymce.editors[i].save(); + } + } + const state = store.getState(); // Additional data needed for backwards compatibility. From 7654273a1adc3910dd2827fa5f6f132434079606 Mon Sep 17 00:00:00 2001 From: ideadude Date: Tue, 4 Dec 2018 08:46:15 -0500 Subject: [PATCH 2/8] Importing tinymce and using tinyMCE vs the object stored in window.tinymce. --- package-lock.json | 3 ++- packages/edit-post/package.json | 3 ++- packages/edit-post/src/store/effects.js | 7 +++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index df6980879a3426..ab7b2da5ed17ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2528,7 +2528,8 @@ "@wordpress/viewport": "file:packages/viewport", "classnames": "^2.2.5", "lodash": "^4.17.10", - "refx": "^3.0.0" + "refx": "^3.0.0", + "tinymce": "^4.7.2" } }, "@wordpress/editor": { diff --git a/packages/edit-post/package.json b/packages/edit-post/package.json index 6c98e2826302c5..46b544189d4a55 100644 --- a/packages/edit-post/package.json +++ b/packages/edit-post/package.json @@ -40,7 +40,8 @@ "@wordpress/viewport": "file:../viewport", "classnames": "^2.2.5", "lodash": "^4.17.10", - "refx": "^3.0.0" + "refx": "^3.0.0", + "tinymce": "^4.7.2" }, "devDependencies": { "deep-freeze": "^0.0.1", diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index 79b09f61d447fd..ec6974c4bf9ff4 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -2,6 +2,7 @@ * External dependencies */ import { reduce } from 'lodash'; +import tinymce from 'tinymce'; /** * WordPress dependencies @@ -73,10 +74,8 @@ const effects = { }, REQUEST_META_BOX_UPDATES( action, store ) { // Saves the wp_editor fields - if ( window.tinymce ) { - for ( var i = 0; i < window.tinymce.editors.length; i++ ) { - window.tinymce.editors[i].save(); - } + for ( var i = 0; i < tinyMCE.editors.length; i++ ) { + tinyMCE.editors[i].save(); } const state = store.getState(); From 8a1a38b8189f56ec109f4c6ecc4fdf4dbfd987a8 Mon Sep 17 00:00:00 2001 From: ideadude Date: Tue, 4 Dec 2018 11:42:49 -0500 Subject: [PATCH 3/8] Updated version number and changelog. --- packages/edit-post/CHANGELOG.md | 5 +++++ packages/edit-post/package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/edit-post/CHANGELOG.md b/packages/edit-post/CHANGELOG.md index 3fdf099954c982..e4b0c1ad32c680 100644 --- a/packages/edit-post/CHANGELOG.md +++ b/packages/edit-post/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.1.5 (Unreleased) + +### Bug Fixes + - Fix saving WYSIWYG Meta Boxes + ## 3.1.4 (2018-11-30) ## 3.1.3 (2018-11-30) diff --git a/packages/edit-post/package.json b/packages/edit-post/package.json index 46b544189d4a55..99406ed513cd0b 100644 --- a/packages/edit-post/package.json +++ b/packages/edit-post/package.json @@ -1,6 +1,6 @@ { "name": "@wordpress/edit-post", - "version": "3.1.4", + "version": "3.1.5", "description": "Edit Post module for WordPress.", "author": "The WordPress Contributors", "license": "GPL-2.0-or-later", From 55e799d7af2deca59b66362de2d15cce474f3565 Mon Sep 17 00:00:00 2001 From: ideadude Date: Tue, 4 Dec 2018 12:09:44 -0500 Subject: [PATCH 4/8] no longer importing tinymce since we use the tinyMCE global. tinyMCE.triggerSave works now. checking if tinyMCE exists before making the call just in case. --- package-lock.json | 3 +-- packages/edit-post/package.json | 3 +-- packages/edit-post/src/store/effects.js | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index ab7b2da5ed17ac..df6980879a3426 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2528,8 +2528,7 @@ "@wordpress/viewport": "file:packages/viewport", "classnames": "^2.2.5", "lodash": "^4.17.10", - "refx": "^3.0.0", - "tinymce": "^4.7.2" + "refx": "^3.0.0" } }, "@wordpress/editor": { diff --git a/packages/edit-post/package.json b/packages/edit-post/package.json index 99406ed513cd0b..519aec9545916b 100644 --- a/packages/edit-post/package.json +++ b/packages/edit-post/package.json @@ -40,8 +40,7 @@ "@wordpress/viewport": "file:../viewport", "classnames": "^2.2.5", "lodash": "^4.17.10", - "refx": "^3.0.0", - "tinymce": "^4.7.2" + "refx": "^3.0.0" }, "devDependencies": { "deep-freeze": "^0.0.1", diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index ec6974c4bf9ff4..e4426c5cb877be 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -2,7 +2,6 @@ * External dependencies */ import { reduce } from 'lodash'; -import tinymce from 'tinymce'; /** * WordPress dependencies @@ -74,10 +73,10 @@ const effects = { }, REQUEST_META_BOX_UPDATES( action, store ) { // Saves the wp_editor fields - for ( var i = 0; i < tinyMCE.editors.length; i++ ) { - tinyMCE.editors[i].save(); + if( tinyMCE ) { + tinyMCE.triggerSave(); } - + const state = store.getState(); // Additional data needed for backwards compatibility. From fb38486784883f9e3bcf7239f42d3dd381cda0f0 Mon Sep 17 00:00:00 2001 From: ideadude Date: Wed, 5 Dec 2018 19:52:12 -0500 Subject: [PATCH 5/8] Using typeof to check for tinyMCE and fixed issues brought up in travis run. --- packages/edit-post/src/store/effects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index e4426c5cb877be..47ea98796ab0d7 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -73,10 +73,10 @@ const effects = { }, REQUEST_META_BOX_UPDATES( action, store ) { // Saves the wp_editor fields - if( tinyMCE ) { + if ( typeof( tinyMCE ) !== 'undefined' ) { tinyMCE.triggerSave(); } - + const state = store.getState(); // Additional data needed for backwards compatibility. From 4ce7e7445a7fdf2b1307108bf6c3eca2c6c3009b Mon Sep 17 00:00:00 2001 From: ideadude Date: Wed, 5 Dec 2018 20:08:12 -0500 Subject: [PATCH 6/8] using window.tinyMCE again to avoid warning RE undefined var --- packages/edit-post/src/store/effects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index 47ea98796ab0d7..589af42c34e49d 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -73,8 +73,8 @@ const effects = { }, REQUEST_META_BOX_UPDATES( action, store ) { // Saves the wp_editor fields - if ( typeof( tinyMCE ) !== 'undefined' ) { - tinyMCE.triggerSave(); + if ( typeof( window.tinyMCE ) !== 'undefined' ) { + window.tinyMCE.triggerSave(); } const state = store.getState(); From 4a2af66eb39e5add21b04e4d1ec67096c89b5204 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Sun, 9 Dec 2018 13:37:58 -0600 Subject: [PATCH 7/8] Restore the package.json version. --- packages/edit-post/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/package.json b/packages/edit-post/package.json index 519aec9545916b..6c98e2826302c5 100644 --- a/packages/edit-post/package.json +++ b/packages/edit-post/package.json @@ -1,6 +1,6 @@ { "name": "@wordpress/edit-post", - "version": "3.1.5", + "version": "3.1.4", "description": "Edit Post module for WordPress.", "author": "The WordPress Contributors", "license": "GPL-2.0-or-later", From 04ca775ce054e09176e3fbbd506d173b3bf04466 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Sun, 9 Dec 2018 14:48:06 -0600 Subject: [PATCH 8/8] Add e2e tests for the custom wp_editor metaboxes --- packages/edit-post/src/store/effects.js | 2 +- .../wp-editor-meta-box.test.js.snap | 3 ++ test/e2e/specs/wp-editor-meta-box.test.js | 38 +++++++++++++++++++ test/e2e/test-plugins/wp-editor-metabox.php | 27 +++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/e2e/specs/__snapshots__/wp-editor-meta-box.test.js.snap create mode 100644 test/e2e/specs/wp-editor-meta-box.test.js create mode 100644 test/e2e/test-plugins/wp-editor-metabox.php diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index 589af42c34e49d..70ebd8cbb53051 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -73,7 +73,7 @@ const effects = { }, REQUEST_META_BOX_UPDATES( action, store ) { // Saves the wp_editor fields - if ( typeof( window.tinyMCE ) !== 'undefined' ) { + if ( window.tinyMCE ) { window.tinyMCE.triggerSave(); } diff --git a/test/e2e/specs/__snapshots__/wp-editor-meta-box.test.js.snap b/test/e2e/specs/__snapshots__/wp-editor-meta-box.test.js.snap new file mode 100644 index 00000000000000..485862873b648d --- /dev/null +++ b/test/e2e/specs/__snapshots__/wp-editor-meta-box.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`WP Editor Meta Boxes Should save the changes 1`] = `"

Typing in a metabox

"`; diff --git a/test/e2e/specs/wp-editor-meta-box.test.js b/test/e2e/specs/wp-editor-meta-box.test.js new file mode 100644 index 00000000000000..496057bb55c1cf --- /dev/null +++ b/test/e2e/specs/wp-editor-meta-box.test.js @@ -0,0 +1,38 @@ +/** + * Internal dependencies + */ +import { newPost, publishPost } from '../support/utils'; +import { activatePlugin, deactivatePlugin } from '../support/plugins'; + +describe( 'WP Editor Meta Boxes', () => { + beforeAll( async () => { + await activatePlugin( 'gutenberg-test-plugin-wp-editor-meta-box' ); + await newPost(); + } ); + + afterAll( async () => { + await deactivatePlugin( 'gutenberg-test-plugin-wp-editor-meta-box' ); + } ); + + it( 'Should save the changes', async () => { + // Add title to enable valid non-empty post save. + await page.type( '.editor-post-title__input', 'Hello Meta' ); + + // Type something + await page.click( '#test_tinymce_id-html' ); + await page.type( '#test_tinymce_id', 'Typing in a metabox' ); + await page.click( '#test_tinymce_id-tmce' ); + + await publishPost(); + + await page.reload(); + + await page.click( '#test_tinymce_id-html' ); + const content = await page.$eval( + '#test_tinymce_id', + ( textarea ) => textarea.value + ); + + expect( content ).toMatchSnapshot(); + } ); +} ); diff --git a/test/e2e/test-plugins/wp-editor-metabox.php b/test/e2e/test-plugins/wp-editor-metabox.php new file mode 100644 index 00000000000000..088fd2ee6e87a2 --- /dev/null +++ b/test/e2e/test-plugins/wp-editor-metabox.php @@ -0,0 +1,27 @@ +ID, 'test_tinymce', true ); + wp_editor( $field_value, 'test_tinymce_id', array( + 'wpautop' => true, + 'media_buttons' => false, + 'textarea_name' => 'test_tinymce', + 'textarea_rows' => 10, + 'teeny' => true + ) ); + }, null, 'advanced', 'high' ); +}); +add_action( 'save_post', function( $post_id ){ + if ( ! isset( $_POST['test_tinymce'] ) ) { + return; + } + update_post_meta( $post_id, 'test_tinymce', $_POST['test_tinymce'] ); +});