fix: serve embed behavior as an enqueued script instead of inline markup - #125
Merged
Merged
Conversation
Contributor
Test in WordPress PlaygroundTest the plugin with the code from this branch:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #125 +/- ##
============================================
+ Coverage 96.39% 96.43% +0.04%
+ Complexity 815 806 -9
============================================
Files 36 36
Lines 4213 4238 +25
============================================
+ Hits 4061 4087 +26
+ Misses 152 151 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Sep 26, 2026
erseco
force-pushed
the
feature/enqueue-embed-behavior
branch
from
September 26, 2026 10:17
619901a to
1f4ebf8
Compare
This was referenced Sep 26, 2026
erseco
force-pushed
the
feature/pot-file-references
branch
from
September 26, 2026 10:50
9184b21 to
bc32141
Compare
WordPress.org asked that plugins stop printing <script> and <style> blocks by hand. The frontend printed three: - the block and the shortcode each emitted an inline fullscreen/poster script per embed. One delegated script, assets/js/exelearning-embed.js, replaces both; it is registered with the block's other frontend assets and enqueued only when an embed renders. - ExeLearning_Viewer_Enhancements printed a <style> and a ResizeObserver <script> to turn a percentage height into pixels. CSS aspect-ratio gives the same box without script, so the class is removed. The editor and export pages are standalone HTML documents written without a theme header, so their tags are built with wp_get_inline_script_tag() and wp_get_script_tag() (WordPress 5.7+), keeping the export bridge deferred as before, and the editor page's CSS goes through wp_add_inline_style().
erseco
force-pushed
the
feature/enqueue-embed-behavior
branch
from
September 26, 2026 11:12
1f4ebf8 to
20700a0
Compare
Register the editor and export bridges with wp_register_script(), add their configuration with wp_add_inline_script( ..., 'before' ) and print only that handle with wp_print_scripts(), so the review's 'use wp_enqueue commands' applies literally, as it already did for the editor page's CSS. The export bridge stays deferred on every supported version: WordPress 6.3+ honours wp_script_add_data( ..., 'strategy', 'defer' ); for 6.1 and 6.2 a script_loader_tag filter, scoped to that handle and removed right after the print, adds the attribute. Checked on WordPress 6.1.14 and 6.3.12. Also register the embed scripts on init instead of wp_enqueue_scripts, so the shortcode can enqueue them in contexts where that hook never fires (the /embed/ template, previews), and restore the AGENTS.md note from #148 that an earlier rebase of this branch dropped.
…llback Enqueue the editor and export bridges and the editor page style before printing them, so the code reads as the review asked: register, enqueue, add inline, print. The WordPress < 6.3 defer fallback matched the exact tag serialization (id='…-js'>). It now adds defer to the first <script> tag with a src in the handle's output, which skips the inline config printed in the same string, and leaves a tag that already has defer alone. A test simulates pre-6.3 core to cover it; checked again on WordPress 6.1.14 and 6.3.12. Also cover the remaining branches of exelearning-embed.js: the legacy Edge fullscreen request, a control outside any embed, and a non-element target.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No translation changes: no strings change here, and since #148 code-only changes no longer touch the catalogs.
WordPress.org asked that plugins stop printing
<script>and<style>blocks by hand and use the enqueue APIs instead. After this PR, plugin PHP prints none.Frontend
<script>per embed. One delegated script,assets/js/exelearning-embed.js, replaces both.exelearning-embed-loaderinExeLearning_Elp_Upload_Block::register_frontend_scripts(), hooked oninit.ExeLearning_Embed_Assetswrapper was dropped.ExeLearning_Viewer_Enhancements: printed a<style>and a ResizeObserver<script>to turn a percentage height (for exampleheight="75%") into pixels. CSSaspect-ratioproduces the same box without script, and without the 150px collapse before the script ran. The class and its tests are removed, and the E2E height test is rewritten foraspect-ratio.Standalone editor and export pages
These are full HTML documents written without a theme header, so there is no
wp_headto print a queue into. They still use the queue, but print only their own handles:wp_register_script()and enqueued withwp_enqueue_script(). Its configuration is added withwp_add_inline_script( …, 'before' ), which WordPress always prints before thesrctag. Thenwp_print_scripts( array( $handle ) )prints that handle alone into an output buffer, with no theme or other plugin scripts.deferon the export bridge, kept on every supported version:wp_script_add_data( $handle, 'strategy', 'defer' ).script_loader_tagfilter adds the attribute. It is scoped to that handle and removed right after the print, and it only touches the first<script>tag with asrc(the inline config arrives in the same string). A test simulates pre-6.3 core to cover it.array( 'strategy' => 'defer' )towp_register_script()is avoided on purpose: on 6.1/6.2 it is read as$in_footer = true.wp_register_style( false )+wp_enqueue_style()+wp_add_inline_style()) and printed withwp_print_styles( handle ).The embed scripts are registered on
init, so the shortcode can enqueue them even wherewp_enqueue_scriptsnever fires (the/embed/template, previews).Verification
deferred and the editor's is not;init.npm run test:js: 258 passed, including every branch ofexelearning-embed.js.…-js-beforeconfig, then<script defer src=… id='exelearning-export-bridge-js'>;defer data-wp-strategy='defer'.make test-e2eforshortcode-viewerandviewer-enhancements: 38 passed.NonEnqueuedScriptexclusions left.