Core Complete 0.47.0
How a workbook is stored, what a workbook file contains, and the filters that let code check, extend or add workbooks. For building one on screen, see Make your own workbook.
How a workbook you build is stored
- Each workbook is a post of type
lmsb_workbook. Its content is the workbook itself, as JSON in format 1 (below), so WordPress keeps a revision of every save. - On its first publish it gets a slug,
wb-followed by the post ID, which never changes. Lessons point at a workbook by that slug. - Every question key and choice value is generated by the plugin, and stays the same once published. The author never sees them.
- Only published workbooks reach lessons. Drafts, pending, private and binned ones can’t be shown or evaluated.
Format 1
This is the shape, copied from the comment above the code that reads it:
{ "v":1, "title", "kicker", "intro", "daily_limit":1–10,
"sections":[
{"kind":"questions","heading","questions":[
{"key":"f-xxxxxx","text","example","paragraph":bool,"required":bool,"min_length":int} ]},
{"kind":"selfcheck","heading","line","items":[
{"key","text","control":"choice","choices":[{"value":"o-xxxxxx","label"}…]}
| {"key","text","control":"slider","from","to","step","percent":bool} ]} ],
"feedback":{ "on":bool, "purpose", "points":[{"name","good","weak"}…],
"tone":"direct|encouraging|plain", "rating":bool,
"length":"shorter|standard|longer", "folio":bool } }The feedback part is used only when the AI add-on is active. Without it, a workbook saves answers and shows no Evaluate button; the feedback settings stay in the workbook and come back when the add-on is switched on again.
The workbook file
Export downloads workbook-<title>.json. The file wraps the workbook in a small envelope:
{ "lmsb_workbook": 1, "exported": "…", "title": "…", "workbook": { … format 1 … } }It carries no slug, no compiled settings, no feedback instructions and nothing about your site. Question keys and choice values travel with it, so a workbook imported back compiles to exactly the same settings.
Import takes a file of up to 1 MB (1,048,576 bytes). Three kinds of file are refused, each with its own message:
| the file | the message |
|---|---|
| can’t be read | “This file couldn’t be read. It may be damaged, or only part of it was saved.” |
| comes from a newer version | “This file was made by a newer version of LMS Blueprint.” |
| isn’t a workbook file | “This isn’t a workbook file.” |
Anything else becomes a new draft, never a published workbook, and is checked by the same checks as a publish, so the edit screen shows what a publish would refuse.
Filters
The full call sites and arguments are on the hooks reference.
Check a workbook before it publishes: lmsb_workbook_validate
Receives the list of checks so far and the workbook. Each entry has a code, a path (the row it is about), a level (refuse or warn) and a message. Core runs checks V1–V8, V13, V15 and V16; the AI add-on adds V9–V12 and V14 through this filter. Only refusals stop a publish; warnings publish.
Add to what a workbook compiles to: lmsb_workbook_compile
Receives the Core settings, the author’s workbook and the post ID. The AI add-on adds system, max_tokens, graded, context and evaluate here when the workbook’s feedback is on and valid.
Let a built-in workbook be copied: lmsb_workbook_builtin_source
“Duplicate to edit” on a built-in workbook needs to know what its feedback looks for, in the authoring screen’s terms. The filter receives that (purpose and criteria, or nothing), the slug and the registered settings. A built-in with feedback but no answer here can’t be copied.
Add workbooks in code: cb_workbook_configs
Every workbook a lesson can show is in one list, slug to settings, passed through cb_workbook_configs. A plugin adds a workbook by adding an entry. The settings it accepts are described in the comment at the top of modules/lms/includes/class-am-lesson-workbook.php.
- Workbooks built on the Workbooks screen join the list at priority 20, and never replace a slug that is already there, so an entry added earlier wins.
- There is no default workbook: a lesson block with no slug, or a slug nothing adds, shows a plain notice.
The workbook editor also has its own hooks for extra panels and preview tools (lmsb_workbook_editor_panels, lmsb_workbook_preview_tools, lmsb_workbook_preview_after); see the hooks reference.