API / Minn\Runtime / RewriteRules

RewriteRules final class

Minn\Runtime\RewriteRules · public/minn/src/Minn/Runtime/RewriteRules.php · 334 lines

The rewrite rules WordPress makes from its structures, as the reference makes them (probes rewrite-generate, rewrite-rules), so plugins that read, filter or add to them see the same list.

A structure is walked a directory at a time (one at a time only when asked), each level that names something getting its rules: its feeds and embed, its pages, its comment pages (for posts and pages), a static front page's comment pages at the root, the endpoints placed there, and the level itself; deepest level first. The level that names a post (a name, an id, a page path, or a plugin post type's own tag) is the post's: its embed and trackback, its feeds, pages and comment pages, its endpoints and its attachments', then the post with its page number, between the rules for attachments under it (by /attachment/ and, but for a hierarchical type, directly). A tag nobody registered stays as written.

The full list is the plugins' top rules (each permastruct's rules join them as they are made, and stay), the fixed files, then root, comments, search, author and dates, then pages and posts (posts first unless the structure begins ambiguously), then the plugins' bottom rules; each section through its filter, the whole through generate_rewrite_rules and rewrite_rules_array.

Uses 1

Constants and properties

privateDEFAULTS = array ( 'ep_mask' => 0, 'paged' => true, 'feed' => true, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => true, )

What a permastruct's flags default to (no endpoint places).

privatePOST_BY_TIME = array ( 0 => '%year%', 1 => '%monthnum%', 2 => '%day%', 3 => '%hour%', 4 => '%minute%', 5 => '%second%', )

The six date and time tags that together name a post.

Public

staticgenerate(WP_Rewrite $rewrite, array $args): array#

generate_rewrite_rules: the rules for one structure.

$argsarray{struct: string, ep_mask?: int, paged?: bool, feed?: bool, forcomments?: bool, walk_dirs?: bool, endpoints?: bool}
@return array<string, string>
staticall(WP_Rewrite $rewrite): array#

rewrite_rules: every rule, assembled and filtered.

@return array<string, string>
staticunfiltered(WP_Rewrite $rewrite): array#

The rules as the engine itself would make them, in their stored form and with no plugin's filter or action on them: what the stored rules are when no plugin changed them. The site's rewrite is left as it is.

@return array<string, string>
staticbuiltins(WP_Rewrite $rewrite): void#

The built-in taxonomies' tags and patterns, set once on the site's rewrite under the front of the structure then; a structure set later leaves them, and a plugin's, as they were (probe registry-rewrites).

statictypeArchive(WP_Rewrite $rewrite, string $name, array $type): array#

A post type's archive rules, which join the top rules as it registers (probe cpt-rules): its archive slug (the rewrite slug when the archive is just true) under the front of the structure, or the root when the type opts out of the front; the archive, its two feed rules when the type has feeds, its pages when it has those.

$typearray<string, mixed>the registered type
@return array<string, string>
staticverbosePages(string $structure): bool#

Whether a structure begins with a tag that could be a page's path too (use_verbose_page_rules).

Internals 10

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

privateassemble(WP_Rewrite $rewrite, Closure $section): array#

The sections in the reference's order, each through $section: the top rules (each permastruct's joining them), the fixed files, root, comments, search, author, dates, pages and posts, the bottom rules.

$sectionClosure(string, array<string, string>): array<string, string>
@return array{0: array<string, string>, 1: array<string, string>} the top rules, and every rule
privatequeries(WP_Rewrite $rewrite, string $struct): array#

Each level's query: the index, then each tag's var and its match, one more at a time.

@return list<string>
privatenamesPost(string $struct): array#

Whether the structure names a post, and whether that post is hierarchical. @return array{0: bool, 1: bool}

@return array{0: bool, 1: bool}
privatedirMask(string $dir): int#

The endpoint place a date directory is besides the structure's own.

privateplainLevel(WP_Rewrite $rewrite, array $level, array $args): array#

A level that is not a post's.

$levelarray{match: string, query: string, tokens: int, mask: int}
$argsarray<string, mixed>
@return array<string, string>
privatepostLevel(WP_Rewrite $rewrite, array $level, array $args, bool $hierarchical): array#

The post's level, between its attachments' rules.

$levelarray{match: string, query: string, tokens: int, mask: int}
$argsarray<string, mixed>
@return array<string, string>
privateattachments(WP_Rewrite $rewrite, string $base): array#

An attachment's rules under a base: itself, its trackback, feeds, comment pages and embed.

@return array<string, string>
privatefeeds(WP_Rewrite $rewrite, array $level, array $args): array#

A level's two feed rules (with comments when asked).

$levelarray{match: string, query: string, tokens: int, mask: int}
$argsarray<string, mixed>
@return array<string, string>
privatepagesAndComments(WP_Rewrite $rewrite, array $level, array $args): array#

A level's page rule, its comment pages (posts' and pages' places only), and a static front page's comment pages at the root.

$levelarray{match: string, query: string, tokens: int, mask: int}
$argsarray<string, mixed>
@return array<string, string>
privateendpoints(WP_Rewrite $rewrite, array $level, array $args): array#

The endpoints placed at a level (by the structure's place or the directory's own).

$levelarray{match: string, query: string, tokens: int, mask: int}
$argsarray<string, mixed>
@return array<string, string>