templates.php
Maintains saved layout templates and idempotent creation reservations. Inserted copies are independent of the library source.
Responsibility#
Maintains saved layout templates and idempotent creation reservations. Inserted copies are independent of the library source.
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#
build-contract, editor, element-css, sanitize.
Module constants#
const CANTATA_EDIT_TEMPLATE_TYPE = 'kindly_template';
const CANTATA_EDIT_TEMPLATE_HOLD = '_cantata_edit_tplreq_';
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.
WordPress hooks#
| Operation | Hook |
|---|---|
add_action |
init |
add_action |
rest_api_init |
add_action and add_filter subscribe to a hook; do_action and apply_filters expose a hook. A subscription is not itself a new extension API. Dynamic hook names are not included in this literal inventory.
Function and method reference#
cantata_edit_template_clean#
function cantata_edit_template_clean( string $html )
Checks a template's HTML before it is stored: the reason it can't be kept, or the clean HTML.
Implementation connections: cantata_edit_build_contract_validate, cantata_edit_can_author_css, cantata_edit_sanitize.
Source location: includes/templates.php:38.
cantata_edit_template_access#
function cantata_edit_template_access(): bool
May this person use the template library (list, add, save)?
Implementation connections: cantata_edit_can_dev.
Source location: includes/templates.php:55.
cantata_edit_template_row#
function cantata_edit_template_row( WP_Post $t ): array
A template as the library lists it: no HTML (that is fetched when the template is used or exported).
Source location: includes/templates.php:60.
cantata_edit_template_insert#
function cantata_edit_template_insert( string $title, string $html, string $key )
Checks and stores one template; the response, or why it was refused.
Implementation connections: cantata_edit_template_clean, cantata_edit_template_row.
Source location: includes/templates.php:65.
cantata_edit_template_reservation_name#
function cantata_edit_template_reservation_name( int $user_id, string $key ): string
Internal implementation helper in this module. Its name and signature identify the operation and accepted PHP values; it is not a standalone authenticated endpoint.
Source location: includes/templates.php:86.
cantata_edit_template_reservation#
function cantata_edit_template_reservation( string $name ): ?array
Internal implementation helper in this module. Its name and signature identify the operation and accepted PHP values; it is not a standalone authenticated endpoint.
Source location: includes/templates.php:89.
cantata_edit_template_reserve#
function cantata_edit_template_reserve( int $user_id, string $key )
The reservation's pending value (owned by this request), the template already made for the key, or a retriable error.
Implementation connections: cantata_edit_template_finish, cantata_edit_template_reservation, cantata_edit_template_reservation_name, cantata_edit_template_reservations_prune.
Source location: includes/templates.php:96.
cantata_edit_template_finish#
function cantata_edit_template_finish( int $user_id, string $key, string $mine, int $post_id ): void
Internal implementation helper in this module. Its name and signature identify the operation and accepted PHP values; it is not a standalone authenticated endpoint.
Implementation connections: cantata_edit_template_reservation_name.
Source location: includes/templates.php:120.
cantata_edit_template_release#
function cantata_edit_template_release( int $user_id, string $key, string $mine ): void
Internal implementation helper in this module. Its name and signature identify the operation and accepted PHP values; it is not a standalone authenticated endpoint.
Implementation connections: cantata_edit_template_reservation_name.
Source location: includes/templates.php:124.
cantata_edit_template_reservations_prune#
function cantata_edit_template_reservations_prune(): void
Reservations older than a day go, oldest first, at most 50 per save: rows are read in the order they were added (option_id), so the oldest are always the ones looked at, and the walk stops at the first that is still young.
Implementation connections: cantata_edit_template_access, cantata_edit_template_finish, cantata_edit_template_insert, cantata_edit_template_release, cantata_edit_template_reserve, cantata_edit_template_row.
Source location: includes/templates.php:132.