API / Minn\Theme / Templates

Templates final readonly class

Minn\Theme\Templates · public/minn/src/Minn/Theme/Templates.php · 204 lines

Which template renders a resolution, and where its markup comes from: a wp_template post saved from the site editor (matched by slug and the theme term) wins over the theme's file. Parts resolve the same way through wp_template_part.

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Theme\Theme $theme

Promoted from the constructor.

privatereadonly ?Minn\Runtime\BlockTemplates $registered

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Theme\Theme $theme, ?Minn\Runtime\BlockTemplates $registered = NULL)#
methodforResolution(Minn\Front\Resolution $resolution): ?array#

The template that renders a resolution, or null.

@return array{slug: string, markup: string}|null
methodtemplate(string $slug): ?string#

A template's markup by slug, saved first.

methodpart(string $slug): ?string#

A template part's markup by slug, saved first.

methodpartSource(string $slug): array#

Where a template part comes from: a part saved for the theme (its post id), the theme's file (its path), or nowhere; with its markup.

@return array{0: 'post'|'file'|'none', 1: int|string, 2: ?string}
methodcandidates(Minn\Front\Resolution $resolution): array#

The block-theme template hierarchy for each kind of resolution.

@return list<string>
methoduserStyles(): ?array#

The site editor's saved global styles for the active theme, when any. An emptied node is stored as [] and reads as nothing, the way the reference reads it; a list where a map belongs is dropped the same way.

methodcustomTemplate(int $pageId): ?string#

A page's chosen custom template, from _wp_page_template meta.

Internals 5

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatefiltered(Minn\Front\Resolution $resolution, array $slugs): array#

Plugins reshape the hierarchy through the reference's "{type}_template_hierarchy" filters (WooCommerce sends its taxonomies to archive-product that way); the filter sees PHP file names and hands back the same, which become slugs again.

$slugslist<string>
@return list<string>
privatehierarchy(Minn\Front\Resolution $resolution): array#
@return list<string>
privatesavedOfTheme(): array#

Every published template, part and global styles post saved for the theme, newest first by type: read in one query once a request.

@return array<string, list<array<string, mixed>>>
privatesaved(string $type, ?string $slug): ?string#
privatesavedRow(string $type, ?string $slug): ?array#

The newest published template of a type (and slug) saved for the theme. Every saved one of the type is read once a request, newest first, so a template's candidates and its parts cost one query.

@return array{ID: int|string, post_content: string}|null