API / Minn\Runtime / PostLinks

PostLinks final class

Minn\Runtime\PostLinks · public/minn/src/Minn/Runtime/PostLinks.php · 223 lines

Post addresses as the reference's link functions build them (probe permalinks): a post through pre_post_link (the structure) and post_link; a page from get_page_uri through _get_page_link and page_link; an attachment under its parent's address, or its own; a plugin's type by its address pattern (the permastruct its rewrite registered) through post_type_link, by its query var without one. Plain (?p=, ?page_id=, ?post_type=) unless its status is public, or private and readable by whoever asks, or it is a sample: a draft, a scheduled or trashed post, a revision, a private one a visitor asks for. "Leaving the name" keeps the slug as its placeholder (%postname%, %pagename%, %{type}%) for an editor to fill in, and get_sample_permalink shows a draft as it would be published.

Constants and properties

constLEAVE_NAME = 1

The slug kept as its placeholder.

constSAMPLE = 2

The address an editor previews: a draft as if published.

privateUNPUBLISHED = array ( 0 => 'draft', 1 => 'pending', 2 => 'auto-draft', 3 => 'future', )

Public

staticpermalink(mixed $post = 0, mixed $leavename = false): mixed#

A post's address by its kind (get_permalink): a page's, an attachment's, a plugin type's or a post's; false for no post. A post filtered for "sample" is shown as it would be published.

staticpageLink(mixed $post = 0, mixed $leavename = false, mixed $sample = false): mixed#

A page's address (get_page_link): the home address for the front page; then page_link.

staticpageAddress(mixed $post = 0, mixed $leavename = false, mixed $sample = false): mixed#

A page's own address, front page or not (_get_page_link); no such page is the plain address with no id.

staticattachmentLink(mixed $post = NULL, mixed $leavename = false): mixed#

An attachment's address (get_attachment_link), or false.

staticcustomLink(mixed $post = 0, mixed $leavename = false, mixed $sample = false): mixed#

A plugin type's post address (get_post_permalink), or false.

staticpost(Minn\Objects\Post $post, int $flags): string#

A post's address (not a page, attachment or plugin type).

staticpage(Minn\Objects\Post $post, int $flags): string#

A page's own address, before page_link: ?page_id= while unpublished, its tag when the name is left, else its path.

staticattachment(Minn\Objects\Post $post, int $flags): string#

An attachment's address: under a parent it belongs to, else its own slug, else ?attachment_id=.

staticcustom(Minn\Objects\Post $post, int $flags): string#

A plugin type's address by its pattern, by its query var, or by the type and id plainly.

staticsampleFor(mixed $post, mixed $title = NULL, mixed $name = NULL): array#

The address an editor shows with the slug to edit, and the slug (get_sample_permalink); two empty strings for no post.

@return array{0: string, 1: string}
staticsample(Minn\Objects\Post $post, ?string $title, ?string $name): array#

The address an editor shows with the slug to edit: the post as if published, its name made unique, the address with the name left, a page's parents written in.

@return array{0: string, 1: string}

Internals 4

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

privateflags(mixed $leavename, mixed $sample): int#

The flags for leaving the name and showing a sample.

privatetokens(Minn\Objects\Post $post, int $flags, string $structure): array#

What each structure tag of a post stands for; the name stays a tag when it is left, and the author is read only for a structure that names it.

privatecategory(Minn\Objects\Post $post): string#

The %category% part: the post's first category by id (post_link_category may choose another), under its parents.

privateplain(Minn\Objects\Post $post, int $flags): bool#

Whether a post's address is the plain one: its status neither public nor private and readable, unless it is a sample of a status that is not internal (a trashed post and a revision stay plain as samples).