From 51c5b802ee429fd6152c4038ecba57d79b0517c5 Mon Sep 17 00:00:00 2001 From: Benito Alba Molina Date: Sun, 15 Nov 2026 19:40:54 +0100 Subject: [PATCH] TinyMCE: Keep the `allow`, `referrerpolicy`, and `loading` iframe attributes. TinyMCE's HTML5 schema does not include these attributes, so the Classic Editor removed them from iframe embeds on every save. Current YouTube, Vimeo, and Google Maps embed codes use them, and without `referrerpolicy` domain-restricted Vimeo videos fail to play. Add them to the existing iframe rule in the `wordpress` plugin, extending the rule rather than replacing it so that iframe attributes added through `extended_valid_elements` are kept. See #66320. --- .../tinymce/plugins/wordpress/plugin.js | 20 ++- tests/qunit/index.html | 1 + .../js/tinymce/plugins/wordpress/plugin.js | 118 ++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 tests/qunit/wp-includes/js/tinymce/plugins/wordpress/plugin.js 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( '