Skip to content

feat: configurable multi-format download split button on embeds#33

Merged
erseco merged 14 commits into
mainfrom
feat/multi-format-download
May 26, 2026
Merged

feat: configurable multi-format download split button on embeds#33
erseco merged 14 commits into
mainfrom
feat/multi-format-download

Conversation

@erseco
Copy link
Copy Markdown
Contributor

@erseco erseco commented May 26, 2026

Closes #32.

Summary

Adds a per-embed split-button next to embedded eXeLearning content that lets visitors download the resource in any of the formats produced by the editor's SharedExporters bundle, picked client-side. The .elpx source link continues to work as before; the new formats are produced by lazy-loading the static editor in a hidden iframe and invoking SharedExporters.quickExport via a new WP_REQUEST_EXPORT protocol message.

Format ID Output filename
HTML5 web `html5` `_web.zip`
SCORM 1.2 `scorm12` `_scorm.zip`
IMS CP `ims` `_ims.zip`
EPUB 3 `epub3` `.epub`
eXeLearning source `elpx` `.elpx`

SCORM 2004 and HTML5 single-page are intentionally excluded per the requirements.

What changed

  • Block UI (`assets/js/elp-upload.js`) — new `InspectorControls` panel "Download options" with a Show download button toggle and a checkbox per format. New block attributes: `showDownload` (bool) and `downloadFormats` (string[]). Defaults: all formats enabled.
  • Shortcode (`public/class-shortcodes.php`) — new `show_download` and `download_formats` (comma-separated) attributes that mirror the block.
  • Frontend rendering — both the block and the shortcode now emit the split-button via the new `ExeLearning_Download_Button_Renderer`. When only one format is enabled, the button collapses to a plain link; when none are enabled, the toolbar omits it.
  • Download orchestrator (`assets/js/wp-exe-download.js`) — handles clicks, lazy-creates a hidden iframe pointed at the new export bootstrap, sends `WP_REQUEST_EXPORT` postMessages, receives bytes, triggers the browser download. The iframe is reused for additional downloads and disposed after a 60s idle period.
  • Public export bootstrap (`includes/class-export-bootstrap.php`) — anonymous `template_redirect` handler that serves a stripped-down version of the static editor for export-only use. No save endpoint, no user data, no CSRF token; reuses the same dist/static/index.html template and the existing bridge.
  • Bridge (`assets/js/wp-exe-bridge.js`) — extended with a `WP_REQUEST_EXPORT` handler that invokes `SharedExporters.quickExport` for the requested format and replies with `WP_EXPORT_FILE` (bytes + filename + mimeType).
  • Format registry (`includes/class-download-formats.php`) — single source of truth for ids, labels, filename suffixes and MIME types.
  • Styles (`assets/css/exelearning.css`) — split-button styling with dropdown menu, status text, busy state.

Sibling module

A parallel PR lands the same feature in `exelearning/omeka-s-exelearning` (also references this issue).

Test plan

  • Insert an eXeLearning block in a post; sidebar shows "Download options" panel with all five formats checked.
  • Save and view the post; toolbar shows the split-button with HTML5 web as the primary action and the four other formats in the dropdown.
  • Click the primary action — receives a `_web.zip`.
  • Open the dropdown, click each non-elpx entry — receives a file with the documented suffix and a valid format.
  • Click the `.elpx` entry — downloads the raw attachment.
  • Disable "Show download button" — toolbar disappears.
  • Use the `[exelearning id="N" download_formats="elpx,epub3"]` shortcode — only those two appear in the toolbar.
  • Verify `exporters.bundle.js` is only requested after the first non-elpx click, not on page load.
  • Open the embed as a logged-out visitor — exports still work (anonymous bootstrap at `/?exe_export=1&attachment_id=N`).

Adds a per-embed split-button next to embedded eXeLearning content that
lets visitors download the resource in any of the formats produced by
the eXeLearning editor exporters bundle, picked client-side. The .elpx
source link continues to work as before; the new formats are produced
by lazy-loading the static editor in a hidden iframe and invoking
SharedExporters.quickExport via a new WP_REQUEST_EXPORT protocol
message.

Formats and filename suffixes:
  - HTML5 web ........  _web.zip
  - SCORM 1.2 ........  _scorm.zip
  - IMS CP ...........  _ims.zip
  - EPUB 3 ...........  .epub
  - eXeLearning ......  .elpx (raw attachment)

Public bootstrap (ExeLearning_Export_Bootstrap) serves an anonymous,
export-only editor page so the feature works for non-logged-in
visitors. The bridge is extended with a WP_REQUEST_EXPORT handler that
returns the exported bytes via postMessage.

Refs #32
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Test in WordPress Playground

Test the plugin with the code from this branch:

Preview in WordPress Playground

⚠️ The embedded eXeLearning editor is not included in this preview. You can install it from Settings > eXeLearning using the "Download & Install Editor" button. All other plugin features (ELP upload, shortcode, Gutenberg block, preview) work normally.

Comment thread includes/class-export-bootstrap.php Fixed
@erseco erseco self-assigned this May 26, 2026
Comment thread includes/class-download-button-renderer.php Dismissed
@erseco erseco merged commit dacb6fc into main May 26, 2026
4 checks passed
@erseco erseco deleted the feat/multi-format-download branch May 26, 2026 13:32
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.

feat: configurable per-embed multi-format download (SCORM/IMS/HTML5/EPUB) via client-side exporters bundle

2 participants