page-model.php
Parses page HTML into an automation outline with revision-scoped section, item, and field paths. It applies structured edits through the same tree and saves drafts using shared validation.
Responsibility#
Parses page HTML into an automation outline with revision-scoped section, item, and field paths. It applies structured edits through the same tree and saves drafts using shared validation.
This is an implementation reference for the released 0.9.13 module. Internal PHP helpers are not a compatibility promise for third-party callers. Prefer the documented REST, Abilities, theme, and filter contracts.
Related modules#
ai-checks, linked-components, render, rest, sanitize, template-code, theme, tones.
Module constants#
const CANTATA_EDIT_AI_TEXT_TAGS = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'summary', 'figcaption', 'blockquote', 'dt', 'dd', 'td', 'th', 'button' ];
These values describe this release. Defined configuration constants and generated identifiers can have different ownership; do not edit stored values directly without following the corresponding workflow.
Function and method reference#
cantata_edit_ai_source#
function cantata_edit_ai_source( WP_Post $post, string $version = 'draft' ): array
The HTML an outline is made from: the editor's draft if there is one (unless the live page is asked for), else what's live.
Implementation connections: cantata_edit_linked_render.
Source location: includes/page-model.php:18.
cantata_edit_ai_parse#
function cantata_edit_ai_parse( string $html ): ?object
The content parsed into a document, returning the element that holds it. PHP 8.4's HTML5 parser when there is one,
else libxml's (which warns about
Source location: includes/page-model.php:32.
cantata_edit_ai_tag#
function cantata_edit_ai_tag( object $el ): string
An element's tag, lowercased (libxml and the HTML5 parser disagree on case).
Source location: includes/page-model.php:54.
cantata_edit_ai_children#
function cantata_edit_ai_children( object $el ): array
The element children of a node.
Source location: includes/page-model.php:59.
cantata_edit_ai_classes#
function cantata_edit_ai_classes( object $el ): array
An element's classes.
Source location: includes/page-model.php:70.
cantata_edit_ai_words#
function cantata_edit_ai_words( object $el ): string
The words in an element, as the editor's words() gives them: whitespace collapsed, trimmed.
Source location: includes/page-model.php:75.
cantata_edit_ai_has#
function cantata_edit_ai_has( object $el, array $tags ): bool
True when an element or anything inside it matches one of these tags.
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_tag.
Source location: includes/page-model.php:80.
cantata_edit_ai_inner#
function cantata_edit_ai_inner( object $el ): string
The markup inside an element.
Source location: includes/page-model.php:90.
cantata_edit_ai_item#
function cantata_edit_ai_item( object $el ): ?array
The repeated thing an element is, as the editor's itemOf() finds it: [ 'noun' => … ], or null. Known lists first,
a questions list's
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_classes, cantata_edit_ai_has, cantata_edit_ai_tag.
Source location: includes/page-model.php:111.
cantata_edit_ai_walk#
function cantata_edit_ai_walk( object $el, string $prefix, array &$into, ?array &$items, string $format ): void
Walk one section (or item), adding its fields and items. $into is the field list being filled; $items is the section's item list (null inside an item: items don't nest in the outline).
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_has, cantata_edit_ai_inner, cantata_edit_ai_item, cantata_edit_ai_tag, cantata_edit_ai_words.
Source location: includes/page-model.php:167.
cantata_edit_ai_component_of#
function cantata_edit_ai_component_of( object $sec ): ?array
The theme's component a section was built from: matched by its first class, as the editor's componentOf() does.
Implementation connections: cantata_edit_ai_classes, cantata_edit_ai_tag, cantata_edit_components.
Source location: includes/page-model.php:216.
cantata_edit_ai_styles_available#
function cantata_edit_ai_styles_available( ?array $comp ): array
The layouts and tones a section may take: its component's own lists, else the theme's general tones.
Implementation connections: cantata_edit_tones.
Source location: includes/page-model.php:233.
cantata_edit_ai_outline#
function cantata_edit_ai_outline( WP_Post $post, string $version = 'draft', string $format = 'outline' ): array
A page as an outline (the plan's get-page shape). $format: outline (default), html (each section's markup and each text field's inner markup too) or text (one compact line per section, to save an AI's tokens).
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_classes, cantata_edit_ai_component_of, cantata_edit_ai_inner, cantata_edit_ai_parse, cantata_edit_ai_source, cantata_edit_ai_styles_available, cantata_edit_ai_tag, cantata_edit_ai_walk, cantata_edit_has_draft, cantata_edit_page_rev.
Source location: includes/page-model.php:245.
cantata_edit_ai_fresh_ids#
function cantata_edit_ai_fresh_ids( object $clone ): void
Copy-local HTML identities and references must not point back into the original item.
Source location: includes/page-model.php:318.
cantata_edit_ai_pages#
function cantata_edit_ai_pages( array $in ): array
Pages for list-pages: built with Kindly Edit or not, newest first.
Implementation connections: cantata_edit_has_draft.
Source location: includes/page-model.php:348.
cantata_edit_ai_sections_available#
function cantata_edit_ai_sections_available( array $in ): array
The theme's designed sections for list-sections-available: the picker's list, without the HTML.
Implementation connections: cantata_edit_components.
Source location: includes/page-model.php:399.
cantata_edit_ai_set_inner#
function cantata_edit_ai_set_inner( object $el, string $value, bool $markup = false ): void
Replace an element's children with safe inline markup (or escaped plain words).
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_parse.
Source location: includes/page-model.php:428.
cantata_edit_ai_path_map#
function cantata_edit_ai_path_map( object $root ): array
The path map used by writes: section, item and field ids point at the same elements returned by get-page.
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_has, cantata_edit_ai_item, cantata_edit_ai_tag.
Source location: includes/page-model.php:454.
cantata_edit_ai_root_html#
function cantata_edit_ai_root_html( object $root ): string
The markup inside the artificial root used by the parser.
Source location: includes/page-model.php:500.
cantata_edit_ai_component_node#
function cantata_edit_ai_component_node( object $root, string $slug )
Resolve a component id and import its section into this document.
Implementation connections: cantata_edit_ai_children, cantata_edit_ai_parse, cantata_edit_components, cantata_edit_template_code_grant_html, cantata_edit_template_code_owner.
Source location: includes/page-model.php:509.
cantata_edit_ai_bad_path#
function cantata_edit_ai_bad_path( string $id ): WP_Error
A consistent error for an id which was not part of the revision the caller read.
Source location: includes/page-model.php:522.
cantata_edit_ai_apply_op#
function cantata_edit_ai_apply_op( object $root, array $op, ?array &$paths = null )
Apply one operation. Revision mode retains identities; sequential mode resolves the current outline.
Implementation connections: cantata_edit_ai_bad_path, cantata_edit_ai_children, cantata_edit_ai_classes, cantata_edit_ai_component_node, cantata_edit_ai_component_of, cantata_edit_ai_fresh_ids, cantata_edit_ai_item, cantata_edit_ai_path_map, cantata_edit_ai_set_inner, cantata_edit_ai_styles_available, cantata_edit_ai_tag.
Source location: includes/page-model.php:527.
cantata_edit_ai_apply_ops#
function cantata_edit_ai_apply_ops( string $html, array $ops, string $path_mode = 'revision' )
Apply a batch atomically in memory, then return sanitized HTML.
Implementation connections: cantata_edit_ai_apply_op, cantata_edit_ai_parse, cantata_edit_ai_path_map, cantata_edit_ai_root_html, cantata_edit_ai_store_draft, cantata_edit_linked_render, cantata_edit_sanitize_saved_content, cantata_edit_template_code_owner.
Source location: includes/page-model.php:680.