API / Minn\Rest / PostObject

PostObject final readonly class

Minn\Rest\PostObject · public/minn/src/Minn/Rest/PostObject.php · 533 lines

Builds the wp/v2 post and page objects in the reference's shape: the view context, the edit context (raw+rendered dual fields, editor-only fields, and cap-gated wp:action-* links), and their _links blocks.

Constants and properties

privateNAVIGATION = 'wp_navigation'

The one post type whose REST shape is not post-shaped.

privateBLOCK = 'wp_block'

The other: a pattern carries its content raw, its category, and its sync status.

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Content\Users $users

Promoted from the constructor.

privatereadonly Minn\Front\Permalinks $permalinks

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Content\Users $users, Minn\Front\Permalinks $permalinks, Minn\Rest\RestUrl $url, Minn\Rest\Caller $caller)#
methodview(Minn\Content\PostRecord $p, ?Minn\Rest\Fields $fields = NULL): array#

The view-context object, through rest_prepare_{type} when a plugin hooks it; with a _fields selection, the rendered title, content and excerpt only when it asks for them, as the reference renders only what is asked.

methodedit(Minn\Content\PostRecord $p, int $userId, ?Minn\Rest\Fields $fields = NULL): array#

The edit-context object, its raw content given its hooked blocks, through rest_prepare_{type} when a plugin hooks it; with a _fields selection, rendered only as far as it asks.

methodpermalink(Minn\Content\PostRecord $p): string#

A post's permalink as of now: pretty once live with a slug, ?p= (or ?page_id=) before.

staticrestBase(string $type): string#

The rest_base of a type.

methodlinks(Minn\Content\PostRecord $p): array#

The _links of a post in the view context.

methodmodifiedUnsaved(Minn\Content\PostRecord $p, int $userId): bool#

Whether a live post carries an autosave newer than its saved revision.

methodlockHolder(int $id, int $userId): ?array#

The OTHER user holding a live _edit_lock (150 second window), or null.

methodeditLinks(Minn\Content\PostRecord $p, int $userId, ?array $viewLinks = NULL): array#

The view links plus the caller's verbs and cap-gated wp:action-* entries.

staticdate(string $mysql): string#

A MySQL datetime in the reference's ISO form.

Internals 12

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

privatemeta(Minn\Content\PostRecord $p, string $context): array#

The meta field: the keys registered to show in REST (probe rest-meta), or the footnotes alone without the runtime.

@return array<string, mixed>
privatenavigationView(Minn\Content\PostRecord $p): array#

A navigation menu is a post with almost nothing on it: no author, no excerpt, no featured image, no comments, no taxonomies, and so no class list either. What it does carry is a template field and the rendered menu.

privateblockView(Minn\Content\PostRecord $p): array#

A pattern (wp_block) is read by editors only, so its title and content come raw even in view context: no rendered title, no rendered content. It carries an excerpt, the footnotes meta, its pattern categories, and the sync status core registers beside meta.

privateviewFields(Minn\Content\PostRecord $p, ?Minn\Rest\Fields $fields = NULL): array#

The view-context object: the shared fields, then the type's own, then class_list and _links.

privateviewTerms(Minn\Content\PostRecord $p): array#

The taxonomies a non-page carries, each as [term_id, slug] pairs; the format terms only for posts.

@return array<string, list<array{0: int, 1: string}>>
privatetypeFields(Minn\Content\PostRecord $p, array $terms): array#

Pages carry parent and menu_order first; posts carry their term ids, and only the post type has sticky and format, among the shared fields.

$termsarray<string, list<array{0: int, 1: string}>>
@return array<string, mixed>
privateclassList(Minn\Content\PostRecord $p, bool $thumbnail, array $terms): array#

The reference's class_list order: identity, type, status, format (posts only), password, thumbnail, hentry, then one class per term.

$termsarray<string, list<array{0: int, 1: string}>>
@return list<string>
privateformat(array $formatTerms): string#
$formatTermslist<array{0: int, 1: string}>
privatetermLinks(string $type, int $id): ?array#

The taxonomy links a type carries: posts their categories and tags, patterns their pattern categories, pages and menus none.

privateeditFields(Minn\Content\PostRecord $p, int $userId, ?Minn\Rest\Fields $fields = NULL): array#

The edit-context object for a given caller: raw+rendered dual fields, password, permalink_template, generated_slug, block_version, Minn Admin's registered list fields, and the cap-gated action links.

privateallow(int $id, ?int $userId = NULL): array#

What the caller may do to this post, which the reference reports in every context: a reader sees GET, an editor of the post sees the write verbs, and DELETE only when they may delete it too.

@return list<string>
privategmt(string $local, string $gmt): string#

A gmt timestamp for the wire: the stored one, or, when it is the draft zero, the local time converted through the site's offset, the way the reference derives it.