ImageTags final readonly class
Minn\Blocks\ImageTags · public/minn/src/Minn/Blocks/ImageTags.php · 312 lines
The attributes the reference adds to an <img> that carries a wp-image-{id} class: loading, decoding, width and height (prepended, in that order), and srcset plus sizes (appended). The srcset lists the displayed size first, then every same-ratio size in stored order, then the original.
Constants and properties
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Media\Uploads $uploads | Promoted from the constructor. |
| private | readonly Closure $front | Promoted from the constructor. |
Public
| new | __construct(Minn\Content\Posts $posts, Minn\Media\Uploads $uploads, Closure $front)# |
| |||
| method | enrich(string $html): string# | Rewrites every wp-image-* <img> in a fragment; other images pass through. | |||
| method | enrichGallery(string $html): string# | The same for a gallery: every image also carries its data-id. | |||
| method | enrichPlugin(string $html): string# | The same for a plugin block's output, where the reference adds no sizes="auto". | |||
| method | content(string $html, mixed $context = NULL): string# | Every <img> and <iframe> of a content fragment as the reference's wp_filter_content_tags leaves it: an attachment's image is enriched as above (a loading it already has is kept, and an eager large one is fetched first); any other image is decoded asynchronously and, when its size is known, loaded lazily or by the page's budget; an iframe with a size is loaded lazily. | |||
| method | finished(string $html, string $context): string# | Content the engine fitted out itself, with what the_content's other callbacks added on the way (an attachment's own link, a plugin's image): an image still without its loading attributes is fitted as the rest were, then each is offered to wp_content_img_tag, as wp_filter_content_tags would. | |||
| method | featured(int $attachmentId, string $alt, string $style): string# | A post's featured image at full size, in the reference's attribute order (dimensions, source, class, alt, style, then the loading attributes and the srcset). Empty when the attachment has no file. |
Internals 13
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | sized(string $tag): string# | A template's image: an attachment's gets its srcset and sizes in place, nothing more; any other is left as it is. |
| private | fit(string $tag): string# | One content image fitted out: an attachment's (by its wp-image class) in full, any other with its loading attributes. |
| private | attachmentOf(string $tag): int# | The attachment an image names in its wp-image-{id} class, or 0. |
| private | plainImage(string $tag): string# | An image that is not an attachment's: decoding always, loading when its size is known and it has none. |
| private | autoSized(string $tag): string# | A lazy image's sizes led by "auto" (wp_img_tag_add_auto_sizes), unless they already are or a plugin says not to (probe rest-attachments-controller). |
| private | lazyFrame(string $tag): string# | An iframe with a width and a height, and no loading of its own, loads lazily. |
| private | rewrite(string $html, bool $withDataId, bool $autoSizes): string# | |
| private | loadingPrefix(int $width = 0, int $height = 0): array# | On a page the first big-enough content image is fetched eagerly with high priority, the next few are eager, and the rest lazy; only lazy images carry the "auto" sizes hint. In a REST response every image is lazy. |
| private | givenLoading(string $loading, int $width, int $height): array# | An image that names its own loading keeps it: an eager one large enough is fetched first, every one is decoded asynchronously. @return array{0: string, 1: bool} @return array{0: string, 1: bool} |
| private | minimumPriorityPixels(): int# | The area an image must cover before it is worth fetching first. |
| private | enrichTag(string $tag, int $attachmentId, bool $withDataId, bool $autoSizes): string# | |
| private | candidates(string $tag, int $attachmentId): ?array# | The srcset candidates for an attachment's image, keyed by width: the shown size first, then same-ratio sizes in stored order, then the original; with the shown width and height, the metadata and the src. Null when the image is not one of the attachment's files. @return array{0: array<int, string>, 1: int, 2: int, 3: array<string, mixed>, 4: string}|null |
| private | srcsetAttributes(array $candidates, int $width, bool $auto, int $attachmentId = 0, array $meta = array ( ), string $src = '', int $height = 0): string# | A srcset needs a choice: one candidate yields no srcset and no sizes. With the runtime up, plugin code filters the candidates and the sizes hint the way the reference lets it (wp_calculate_image_srcset, wp_calculate_image_sizes). |
Nothing matches.