theme-templates.php
Chooses matching theme templates by rule specificity, handles draft and published rules, and renders against the requested post or archive context.
Responsibility#
Chooses matching theme templates by rule specificity, handles draft and published rules, and renders against the requested post or archive context.
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#
element-js, popups, render, rest, templates, theme.
Module constants#
const CANTATA_EDIT_THEME = 'kindly_theme';
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 |
|---|---|
apply_filters |
cantata_edit_themes_cap |
add_action |
init |
add_action |
cantata_edit_saved |
add_action |
transition_post_status |
add_action |
template_redirect |
add_filter |
template_include |
add_filter |
oembed_request_post_id |
add_filter |
body_class |
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_can_themes#
function cantata_edit_can_themes(): bool
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/theme-templates.php:25.
cantata_edit_theme_kinds#
function cantata_edit_theme_kinds(): array
The kinds of theme template, with their names.
Source location: includes/theme-templates.php:30.
cantata_edit_theme_kind#
function cantata_edit_theme_kind( int $id ): string
A template's kind ('single', 'archive', 'search', '404').
Implementation connections: cantata_edit_theme_kinds.
Source location: includes/theme-templates.php:45.
cantata_edit_theme_sample_type#
function cantata_edit_theme_sample_type( int $id ): string
The post type a single template is for: its first "type" rule (draft rules first), else posts.
Implementation connections: cantata_edit_theme_where.
Source location: includes/theme-templates.php:52.
cantata_edit_theme_sample_info#
function cantata_edit_theme_sample_info( int $id ): array
For the editor: which record the template is shown with, and a short list to choose another (newest first).
Implementation connections: cantata_edit_theme_sample_type.
Source location: includes/theme-templates.php:61.
cantata_edit_theme_where#
function cantata_edit_theme_where( int $id, bool $draft = false ): 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/theme-templates.php:75.
cantata_edit_theme_where_clean#
function cantata_edit_theme_where_clean( $where )
Rules checked like a popup's (the same parser), or WP_Error.
Implementation connections: cantata_edit_popup_parse.
Source location: includes/theme-templates.php:83.
cantata_edit_theme_default_where#
function cantata_edit_theme_default_where( string $kind ): array
Where a new theme template of a kind applies until someone says otherwise.
Source location: includes/theme-templates.php:90.
cantata_edit_theme_promote#
function cantata_edit_theme_promote( int $id ): void
Draft rules go live with the template (from the editor's Publish or WordPress's own).
Source location: includes/theme-templates.php:95.
cantata_edit_theme_rank#
function cantata_edit_theme_rank( array $r ): int
How specific a rule is: the most specific matching template wins.
Source location: includes/theme-templates.php:107.
cantata_edit_theme_request_kind#
function cantata_edit_theme_request_kind(): string
The kind of template this request would use, or ''.
Source location: includes/theme-templates.php:112.
cantata_edit_theme_for_request#
function cantata_edit_theme_for_request( ?array &$also = null ): ?WP_Post
The published template for this request, with every other one that matched as well ($also) and the rank: the most specific wins; a tie goes to the oldest. A search page with no search template uses an archive one.
Implementation connections: cantata_edit_popup_where_rule, cantata_edit_theme_rank, cantata_edit_theme_request_kind, cantata_edit_theme_where.
Source location: includes/theme-templates.php:124.
cantata_edit_theme_conflicts#
function cantata_edit_theme_conflicts(): array
Templates of one kind whose rules give the same rank for the same rule: [ [ a, b, rule ] ], for the manager.
Implementation connections: cantata_edit_is_editing, cantata_edit_theme_for_request, cantata_edit_theme_kind, cantata_edit_theme_where.
Source location: includes/theme-templates.php:147.
cantata_edit_theme_html#
function cantata_edit_theme_html( WP_Post $t ): string
A theme template's published design for this request, filled from the post or archive being shown.
Implementation connections: cantata_edit_element_js_owner_for_post, cantata_edit_missing_alts, cantata_edit_popup_seen, cantata_edit_public_forms, cantata_edit_public_links, cantata_edit_render.
Source location: includes/theme-templates.php:183.
cantata_edit_theme_out#
function cantata_edit_theme_out( WP_Post $p ): array
A theme template in lists: name, kind, state, rules in words, conflicts and where to edit it.
Implementation connections: cantata_edit_theme_kind, cantata_edit_theme_where, cantata_edit_url.
Source location: includes/theme-templates.php:199.
cantata_edit_theme_export#
function cantata_edit_theme_export( WP_Post $p ): array
An exported template: its name, kind, design and rules (a file for another site of this plugin).
Implementation connections: cantata_edit_template_clean, cantata_edit_theme_conflicts, cantata_edit_theme_kind, cantata_edit_theme_kinds, cantata_edit_theme_out, cantata_edit_theme_starter, cantata_edit_theme_where, cantata_edit_theme_where_clean.
Source location: includes/theme-templates.php:209.
cantata_edit_theme_starter#
function cantata_edit_theme_starter( string $kind ): string
A new template's first design: the parts its kind needs, as native elements with dynamic data.
Implementation connections: cantata_edit_config.
Source location: includes/theme-templates.php:296.
cantata_edit_theme_preview#
function cantata_edit_theme_preview( WP_Post $t ): string
The stage's preview: the template's latest version with a recent post (or ?kindly_preview=
Implementation connections: cantata_edit_element_js_owner_for_post, cantata_edit_missing_alts, cantata_edit_public_forms, cantata_edit_public_links, cantata_edit_render, cantata_edit_theme_kind, cantata_edit_theme_sample_type.
Source location: includes/theme-templates.php:312.