AttachmentAddresses final readonly class
Minn\Front\AttachmentAddresses · public/minn/src/Minn/Front/AttachmentAddresses.php · 80 lines
The addresses an attachment's page answers to besides those its rules find (Front\RuleTable: a loose one by its slug at the top, any by its slug under another address, "attachment/" between or not): by id or slug in the query (?attachment_id=, ?attachment=), and as a post (?p=, ?page_id=), which moves to its own page. With attachment pages off (wp_attachment_pages_enabled, the default) every address moves to the file itself; with them on, one that is not its own moves to its page. An attachment is readable as its parent is.
Constants and properties
| private | readonly Minn\Db $db | Promoted from the constructor. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Front\Permalinks $permalinks | Promoted from the constructor. |
| private | readonly Closure $readable | Promoted from the constructor. |
Public
| new | __construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Front\Permalinks $permalinks, Closure $readable)# | |
| static | names(Minn\Front\Resolution $resolution): bool# | Whether a resolution is an attachment's page. |
| method | fromQuery(Minn\Http\Request $request, Minn\Front\Redirects $redirects): ?Minn\Front\Resolution# | ?attachment_id= or ?attachment=: the attachment's page, or a 404; null when the request names neither. |
| method | asPost(Minn\Content\PostRecord $post, Minn\Http\Request $request, string $key, Minn\Front\Redirects $redirects): ?Minn\Front\Resolution# | An attachment asked for as a post (?p=, ?page_id=): it moves to its own page whatever the setting; null for any other post. |
| method | answer(Minn\Front\Resolution $resolution, Minn\Http\Request $request, Minn\Front\Redirects $redirects): Minn\Front\Resolution# | With attachment pages off (the default), a move to the file itself, from every address, its embed and feed among them: the query along, though an ?attachment_id= address leaves its id behind unless it asked for an embed. With them on, the page as typed, or (the address not its own) a move to its own: the other query arguments along, ?attachment= among them; an embed stays where it was asked for. |
Internals 1
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | readable(Minn\Content\PostRecord $attachment): bool# | An attachment is readable as its parent is; a loose one as it stands. |
Nothing matches.