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

When a post is saved, check for tinymce and save any editors. #12568

Merged
merged 8 commits into from
Dec 9, 2018
5 changes: 5 additions & 0 deletions packages/edit-post/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-post/src/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const effects = {
} );
},
REQUEST_META_BOX_UPDATES( action, store ) {
// Saves the wp_editor fields
if ( window.tinyMCE ) {
window.tinyMCE.triggerSave();
}

const state = store.getState();

// Additional data needed for backwards compatibility.
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/specs/__snapshots__/wp-editor-meta-box.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`WP Editor Meta Boxes Should save the changes 1`] = `"<p>Typing in a metabox</p>"`;
38 changes: 38 additions & 0 deletions test/e2e/specs/wp-editor-meta-box.test.js
Original file line number Diff line number Diff line change
@@ -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();
} );
} );
27 changes: 27 additions & 0 deletions test/e2e/test-plugins/wp-editor-metabox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Plugin Name: Gutenberg Test Plugin, WP Editor Meta Box
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-wp-editor-metabox
*/

add_action( 'add_meta_boxes', function(){
add_meta_box( 'test_tinymce', 'Test TinyMCE', function( $post ){
$field_value = get_post_meta( $post->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'] );
});