TermSave final class
Minn\Runtime\TermSave · public/minn/src/Minn/Runtime/TermSave.php · 199 lines
wp_insert_term and wp_update_term in the reference's order (probe term-insert-filters, contracts/runtime.md "Terms plugins can change"). An insert asks pre_insert_term, refuses an empty name or a missing parent, runs every field through its db filters (sanitize_term), refuses a name the parent (or, for tags, the taxonomy) already has, makes the slug unique, hands the row to wp_insert_term_data, writes it (a slug left empty becomes the term's id), puts it in the taxonomy, lets a plugin name a duplicate to keep instead, and tells plugins. An update merges the stored term (slashed, so a backslash in it survives) under the changes, runs the same filters, asks wp_update_term_parent (where a parent that would put the term under itself becomes 0), and refuses a slug a sibling holds.
Constants and properties
| private | DEFAULTS = array ( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '', ) |
Public
| static | insert(mixed $term, string $taxonomy, array $args): WP_Error|array# | A new term's ids, or why not.
@return array{term_id: int, term_taxonomy_id: int}|\WP_Error | |||
| static | update(int $termId, string $taxonomy, array $changes): WP_Error|array# | A changed term's ids, or why not.
@return array{term_id: int, term_taxonomy_id: int}|\WP_Error |
Internals 5
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | write(WP_Term $term, array $data, string $description, int $parent, array $args): array# | The update's writes and their actions, in the reference's order.
@return array{term_id: int, term_taxonomy_id: int} | ||||||
| private | nameTaken(string $name, string $taxonomy, array $args): ?WP_Error# | The refusal for a name already in use: under the same parent in a hierarchical taxonomy (unless a different slug was asked for), or anywhere in a flat one. The lookup sanitizes the name again, as the reference's does.
| ||||||
| private | updatedSlug(string $slug, string $asked, int $parent, int $termId, array $args): WP_Error|string# | An update's slug: as asked when no other term holds it; made unique when it was made from the name (none was asked for) or the holder sits under another parent; refused otherwise.
| ||||||
| private | slugFromId(Minn\Content\Terms $terms, int $termId, string $taxonomy, array $data, array $args): void# | A slug saving left empty (a name with nothing a slug can keep) becomes the term's id, between edit_terms and edited_terms.
| ||||||
| private | row(mixed $data): array# | The row a plugin's filter handed back, with the columns it dropped put back. @return array{name: string, slug: string, term_group: int} |
Nothing matches.