API / Minn\Runtime / TermWriter

TermWriter final readonly class

Minn\Runtime\TermWriter · public/minn/src/Minn/Runtime/TermWriter.php · 157 lines

The decisions behind wp_delete_term and the object-term relationships: which relationships to add and remove (saves are Runtime\TermSave). The rows themselves come from Content\Terms; the lifecycle actions fire from here in the reference's order. Behaviour pinned by contracts/fixtures/api/content.json.

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Terms $terms

Promoted from the constructor.

privatereadonly Minn\Runtime\TermQuery $query

Promoted from the constructor.

privatereadonly Minn\Content\PostWriter $posts

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Terms $terms, Minn\Runtime\TermQuery $query, Minn\Content\PostWriter $posts)#
methoddelete(array $row, string $taxonomy, bool $hierarchical, int $default): array#

Deletes a term; objects left without a category fall back to the default one. Returns the object ids the term was attached to.

$rowarray<string, mixed>
@return list<int>
methodrelate(int $objectId, array $keep, array $old, string $taxonomy, ?Closure $count = NULL): void#

Makes an object's relationships in a taxonomy exactly $keep (or $old plus $keep when appending), in the reference's order: each new relationship between add_term_relationship and added_term_relationship, the counts of those terms, then the ones that went, between delete_term_relationships and deleted_term_relationships, and their counts. $count recounts a list of term_taxonomy ids and tells plugins (wp_update_term_count); without it the taxonomy is recounted quietly.

$keeplist<int>term_taxonomy ids
$oldlist<int>the object's current term_taxonomy ids in the taxonomy
$count(Closure(list<int>): void)|null
methodunrelate(int $objectId, array $ttIds, string $taxonomy, ?Closure $count = NULL): bool#

Removes the given relationships between delete_term_relationships and deleted_term_relationships, then recounts those terms; true when any row went.

$ttIdslist<int>
$count(Closure(list<int>): void)|null
methodpublishedCount(int $ttId, array $statuses = array ( 0 => 'publish', )): int#

How many objects in the counted statuses a term holds, as the stored count keeps it (published ones unless a plugin widens the list).

$statuseslist<string>
methodsplit(int $termId, int $ttId): ?array#

Gives a taxonomy row that shares its term with another taxonomy a term of its own (the same name, slug and group), and moves its children under it. Null when no other taxonomy holds the term.

@return array{0: int, 1: string, 2: list<int>}|null the new term id, the taxonomy, the children moved
methodrelationshipCount(int $ttId): int#

Every object filed under a term, whatever it is: the count a taxonomy of links or other non-posts keeps.

methodstoreCount(int $ttId, int $count): void#

Stores a term's count.

methodtermIdsOf(array $ttIds): array#

The term ids behind term_taxonomy ids, as stored (strings), in the order given. @param list<int> $ttIds @return list<string>

$ttIdslist<int>@return list<string>

Internals 1

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

privatettIdOf(int $termId, string $taxonomy): int#