diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js index 269f7d79774a7..da1f0b79f9a10 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js @@ -608,7 +608,8 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); editor.on( 'preInit', function() { - var validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' + + var iframeRule, + validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' + 'title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],' + // Global attributes. 'i,' + // Don't replace with and with and don't remove them when empty. 'b,' + @@ -616,6 +617,23 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { editor.schema.addValidElements( validElementsSetting ); + /* + * Keep the iframe attributes that current embed codes (YouTube, Vimeo, Google Maps) + * use, which TinyMCE's HTML5 schema doesn't know and would strip on every save. + * The existing rule is extended rather than replaced, so iframe attributes added + * through `extended_valid_elements` are kept. + */ + iframeRule = editor.schema.getElementRule( 'iframe' ); + + if ( iframeRule ) { + each( [ 'allow', 'referrerpolicy', 'loading' ], function( attributeName ) { + if ( ! iframeRule.attributes[ attributeName ] ) { + iframeRule.attributes[ attributeName ] = {}; + iframeRule.attributesOrder.push( attributeName ); + } + } ); + } + if ( tinymce.Env.iOS ) { editor.settings.height = 300; } diff --git a/tests/qunit/index.html b/tests/qunit/index.html index f9033a776151c..0d96946c3d36f 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -2299,6 +2299,7 @@

Preview

+ diff --git a/tests/qunit/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/tests/qunit/wp-includes/js/tinymce/plugins/wordpress/plugin.js new file mode 100644 index 0000000000000..68065ccf011e5 --- /dev/null +++ b/tests/qunit/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -0,0 +1,118 @@ +( function( $, QUnit, tinymce ) { + var editor, + count = 0; + + if ( tinymce.Env.ie && tinymce.Env.ie < 11 ) { + return; + } + + /** + * Initializes an editor with the wordpress plugin on a new textarea. + * + * @param {string} id The textarea ID. + * @param {Object} settings Additional editor settings. + * @param {Function} callback Called with the editor once it is initialized. + */ + function initEditor( id, settings, callback ) { + $( document.body ).append( '