API / Minn\Theme / Theme

Theme final class

Minn\Theme\Theme · public/minn/src/Minn/Theme/Theme.php · 347 lines

The active block theme on disk, read as data: theme.json, the templates and parts directories, and the patterns index. A child theme's files win and its parent fills in what the child does not define; theme.json merges the same way, with the child's preset lists replacing the parent's whole. The engine reads the site's installed theme the way it reads the site's database; it never runs the theme's PHP.

Constants and properties

private?array $json
private?array $patterns
propreadonly string $slug

Promoted from the constructor.

propreadonly string $dir

Promoted from the constructor.

propreadonly string $uri

Promoted from the constructor.

propreadonly ?Minn\Theme\Theme $parent

Promoted from the constructor.

Public

new__construct(string $slug, string $dir, string $uri, ?Minn\Theme\Theme $parent = NULL)#
staticactive(Minn\Content\Site $site, Minn\Front\Permalinks $permalinks, string $themesDir): ?self#

The active block theme, or null under a classic one.

staticforStyles(Minn\Content\Site $site, Minn\Front\Permalinks $permalinks, string $themesDir): ?self#

The active theme as styling data (theme.json present), whether or not it is a block theme; the classic renderer prints its presets where the reference prints a classic theme's global styles.

methodparentSlug(): ?string#

The theme's own name, and the parent's, for body classes.

methodjson(): array#

The theme.json with the parent's merged in; with plugins loaded, through wp_theme_json_data_theme.

methodstyleFiles(): array#

Every JSON file under styles/, the parent theme's first and each theme's in path order: block style partials and style variations alike.

@return list<string>
staticmerge(array $base, array $over): array#

Layered theme.json: maps merge key by key, lists (palettes, font sizes, template parts) replace as a whole.

methodtemplateFile(string $slug): ?string#

A template file's markup, or null.

methodtemplatePath(string $slug): ?string#

The file a template is read from: this theme's, else its parent's; null when neither has one.

methodpartFile(string $slug): ?string#

A template part file's markup, or null.

methodpartPath(string $slug): ?string#

The file a template part is read from: this theme's, else its parent's; null when neither has one.

methodname(): string#

The theme's display name, as the stylesheet header states it; a child theme answers with its own. Falls back to theme.json's title, then the folder name.

methodfileSlugs(string $folder): array#

Every template (or part) slug the theme offers, the child's files first and the parent's after, each in the order the directory hands them back: the reference walks these directories unsorted and its template list carries that order through.

@return list<string>
methodcustomTemplate(string $slug): ?array#

A template title and description the theme declares for a custom template slug.

methodpartTitle(string $slug): ?string#

The title theme.json gives a template part, when it names one.

methodpartArea(string $slug): string#

The template-part area declared in theme.json (header, footer, or uncategorized).

methodpattern(string $slug): ?string#

A pattern's markup, with its PHP text subset interpreted; null when unknown.

methodpatternMeta(string $slug): array#

A pattern's declared Block Types and Categories, the header fields a plugin reads to tell (say) a header pattern from any other.

@return array{blockTypes: list<string>, categories: list<string>}
methodpatternHeader(string $slug): ?array#

The header fields a pattern declares, as the metadata attribute the reference writes onto the pattern's first block when it splices the pattern into a template. A field the header omits is omitted here.

@return array{patternName: string, name: string, description?: string, categories?: list<string>}|null
methodstyleUri(): ?string#

The theme's stylesheet URL when it ships one; a child's own, else nothing (the parent's is not enqueued for it).

Internals 7

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

privateat(string $slug, string $themesDir, Minn\Front\Permalinks $permalinks, ?Minn\Theme\Theme $parent = NULL): ?self#
privaterawJson(): array#

The theme.json as written, the parent's merged in.

privatewithStylePartials(array $json): array#

A theme's styles/ folder can hold block style variations: a JSON file with blockTypes and a slug (else the file name) whose styles become styles.blocks.{type}.variations.{slug} for each named block type. The parent's partials load first, the child's over them.

privatepartialFiles(string $dir): array#
@return list<string>
privatesafe(string $slug): bool#

A template or part name is a file name, never a path.

privatehtmlFiles(string $dir): array#
@return list<string>
privatepatternIndex(): array#
@return array<string, string>