API / Minn\Content / Terms

Terms final readonly class

Minn\Content\Terms · public/minn/src/Minn/Content/Terms.php · 219 lines

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
methodfindBySlug(string $taxonomy, string $slug): ?Minn\Content\TermRecord#

A term joined with its taxonomy row: term_id, name, slug, term_taxonomy_id, parent, count.

methodfind(string $taxonomy, int $termId): ?Minn\Content\TermRecord#

One term in a taxonomy, or null.

methodrow(int $termId, string $taxonomy): ?Minn\Content\TermRecord#

The row shape the term controllers work with, including term_taxonomy_id.

methodidByName(string $name, string $taxonomy): ?int#

The id of the term with exactly this name in a taxonomy, or null.

methoduniqueSlug(string $base, string $taxonomy, int $skipId = 0): string#

A slug unique within the taxonomy: base, -2, -3 on collision.

methodcreate(string $name, string $slug, string $taxonomy, string $description, int $parent): int#

Inserts a term and its taxonomy row and returns the term id.

methodinsertRow(array $data): int#

Inserts a terms row alone (name, slug, term_group), as the reference writes it before the taxonomy row; returns the term id.

$dataarray{name: string, slug: string, term_group: int}
methodaddToTaxonomy(int $termId, string $taxonomy, string $description, int $parent): int#

Puts a term in a taxonomy; returns the term_taxonomy id.

methodupdateRow(int $termId, array $data): void#

Rewrites a terms row (name, slug, term_group).

$dataarray{name: string, slug: string, term_group: int}
methoddropRows(int $termId, int $ttId): void#

Drops a term's rows that a plugin's duplicate check said to give up.

methodrename(int $termId, string $name, string $slug): void#

Changes a term's name and slug.

methoddescribe(int $termId, string $taxonomy, string $description, int $parent): void#

Changes a term's description and parent within one taxonomy.

methoddelete(Minn\Content\TermRecord $term, bool $hierarchical): void#

Reparents children to the grandparent, detaches relationships, drops the rows.

methodpathOf(Minn\Content\TermRecord $term): string#

"parent/child" for hierarchical taxonomies, the bare slug otherwise.

Internals 3

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

privaterecord(?array $row): ?Minn\Content\TermRecord#
$rowarray<string, mixed>|null
privaterefreshHierarchy(string $taxonomy): void#

The reference keeps "{taxonomy}_children" (each parent's child term ids, by id) for a hierarchical taxonomy and rewrites it on every term change; one left stale hides new children from WordPress after a switch back. Callers take a taxonomy as hierarchical when the change has a parent, they know it is, or the option is already there.

privatekeepsHierarchy(string $taxonomy): bool#

Whether the taxonomy already has its children option, the mark of a hierarchical one.