Skip to content

fix: serve embed behavior as an enqueued script instead of inline markup - #125

Open
erseco wants to merge 3 commits into
mainfrom
feature/enqueue-embed-behavior
Open

erseco wants to merge 3 commits into
mainfrom
feature/enqueue-embed-behavior

Conversation

@erseco

@erseco erseco commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Shortcode and block embeds previously printed behavior scripts per instance, and percentage heights required an inline style and ResizeObserver. The standalone editor and export bootstrap also inserted integration scripts directly.

Both embed renderers now enqueue one delegated behavior script. CSS aspect-ratio handles percentage heights. Controls are scoped to the nearest shortcode/block container, so an embed with a missing frame cannot fullscreen its neighbor.

The editor and export documents now enqueue their WordPress bridge and attach bootstrap code with wp_add_inline_script(). The editor stylesheet uses wp_add_inline_style(). Explicit handles are printed into the standalone HTML with wp_print_scripts()/wp_print_styles(), without printing the theme's asset queue. This retains WordPress 6.1 compatibility and leaves the upstream editor's own dependency loading unchanged. The bridge initializes on DOMContentLoaded; the export script no longer needs a manually emitted defer attribute.

Validation after the review corrections:

  • 931 PHP tests / 2,063 assertions passed; the known residual screenshot fixture was moved aside in the test container before the clean run.
  • 252 JavaScript tests passed, including a regression reproduced before fixing cross-embed fullscreen targeting.
  • All 38 repository E2E tests passed, including Chromium and Firefox viewer coverage.
  • PHPCS and Plugin Check passed. Plugin Check uses the repository target, which ignores warnings and excludes file_type/image_functions; it is not a certification of the bundled editor.
  • PHPMD completed with no rule violations; the downloaded tool emits deprecation notices under the local PHP version.

The separate WordPress.org findings concerning bundled libraries and remote resources still require review of the final editor build and release ZIP.

Every shortcode and block preview printed its own <script> block, and a
percentage height added an inline <style> plus a ResizeObserver on top. That is
what WordPress.org rejects, and it also shipped the same handful of lines once
per embed on the page.

The behavior now lives in assets/js/exelearning-embed.js, enqueued once through
wp_enqueue_script() and delegated from the document, so it serves every embed on
the page -- including one inserted later -- and the markup carries no script at
all. The embed a click belongs to is found by walking up to the nearest ancestor
holding an .exelearning-iframe, which keeps several embeds on one page
independent without per-instance ids.

Percentage heights are pure CSS now: height="75%" renders as
`aspect-ratio: 100 / 75`, which says exactly what the attribute means ("75% as
tall as the embed is wide") and is resolved by the browser on every resize.
ExeLearning_Viewer_Enhancements existed only to script that and is deleted.
@github-actions

Copy link
Copy Markdown
Contributor

Test in WordPress Playground

Test the plugin with the code from this branch:

Preview in WordPress Playground

ℹ️ The eXeLearning editor is fetched from the shared release and unpacked into the plugin when the playground boots, so the first load may take a few extra seconds. ELP upload, shortcode, Gutenberg block and preview work normally.

@codecov-commenter

codecov-commenter commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.83%. Comparing base (97fe8af) to head (962086e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
assets/js/exelearning-embed.js 87.87% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #125      +/-   ##
============================================
- Coverage     96.87%   96.83%   -0.04%     
+ Complexity      864      851      -13     
============================================
  Files            39       40       +1     
  Lines          4323     4333      +10     
============================================
+ Hits           4188     4196       +8     
- Misses          135      137       +2     
Flag Coverage Δ
javascript 95.46% <87.87%> (-0.24%) ⬇️
php 97.29% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
admin/views/editor-bootstrap.php 92.40% <100.00%> (+0.85%) ⬆️
exelearning.php 0.00% <ø> (ø)
includes/class-elp-upload-block.php 100.00% <100.00%> (ø)
includes/class-embed-assets.php 100.00% <100.00%> (ø)
includes/class-export-bootstrap.php 90.47% <100.00%> (+0.47%) ⬆️
public/class-shortcodes.php 100.00% <100.00%> (ø)
assets/js/exelearning-embed.js 87.87% <87.87%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants