Templates final readonly class
Minn\Theme\Templates · public/minn/src/Minn/Theme/Templates.php · 251 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
| private | readonly Minn\Db $db | Promoted from the constructor. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Theme\Theme $theme | Promoted from the constructor. |
| private | readonly ?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)# | |
| method | forResolution(Minn\Front\Resolution $resolution): ?array# | The template that renders a resolution, or null; with the runtime up, its fields as the template object holds them too. @return array{slug: string, markup: string, fields?: array<string, mixed>}|null |
| method | template(string $slug): ?string# | A template's markup by slug, saved first. |
| method | part(string $slug): ?string# | A template part's markup by slug, saved first. |
| method | partSource(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} |
| method | userStyles(): ?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. |
| method | load(): void# | Has the theme's saved templates (and its term) read, if they are not yet: the template-part lookup answers from them. |
| method | savedPartIds(string $slug): array# | The ids the template-part lookup finds for a slug: the newest saved part of the theme by that name, or none. @return list<int> |
| method | customTemplate(int $pageId): ?string# | A page's chosen custom template, from _wp_page_template meta. |
Internals 6
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | found(array $slugs): ?array# | The first of these slugs a template answers, in their order. With the runtime up the answer is the reference's: the templates get_block_templates finds for the slugs (its pre and result filters let a plugin add one or change one, as The Events Calendar and WooCommerce do).
@return array{slug: string, markup: string, fields?: array<string, mixed>}|null | |||
| private | filtered(string $type, array $slugs): array# | Plugins reshape a template type's hierarchy through the reference's "{type}_template_hierarchy" filters (WooCommerce sends its taxonomies to archive-product that way, The Events Calendar its archive to its own); the filter sees PHP file names and hands back the same, which become slugs again.
@return list<string> | |||
| private | groups(Minn\Front\Resolution $resolution): array# | The block-theme template hierarchy for each kind of resolution, as the reference's template loader walks it: a template type at a time (the front page, the kind's own, then singular or archive, then index), each with its own slugs, until one has a template. @return array<string, list<string>> slugs by template type | |||
| private | savedOfTheme(): array# | Every published template, part and global styles post saved for the theme, newest first by type: read in one query once a request, with the theme's own wp_theme term (by name, as the reference finds it), so the term lookups the template queries make need no query of their own. @return array<string, list<array<string, mixed>>> | |||
| private | saved(string $type, ?string $slug): ?string# | ||||
| private | savedRow(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 |
Nothing matches.