API / Minn\Content / MediaShortcodes

MediaShortcodes final class

Minn\Content\MediaShortcodes · public/minn/src/Minn/Content/MediaShortcodes.php · 187 lines

The [video] and [audio] shortcodes as the reference prints them: a plugin may take either over first (wp_*_shortcode_override, handed the shortcode's own attributes and its instance number), then the source by src or by each format's attribute (a file of another kind is only a link; YouTube and Vimeo addresses are video of their own; with none, the post's first attached video or audio), the player's attributes (a video no wider than the content, its height in proportion; the flags bare), each source numbered by the instance, a fallback link, and the class, library and final HTML through their filters.

Constants and properties

privateYOUTUBE = '#^https?://(?:www\\.)?(?:youtube\\.com/watch|youtu\\.be/)#'
privateVIMEO = '#^https?://(.+\\.)?vimeo\\.com/.*#'

Public

staticvideo(array|string $attr, string $content): ?string#

[video]. @param array<string, mixed>|string $attr

$attrarray<string, mixed>|string
staticaudio(array|string $attr, string $content): ?string#

[audio]. @param array<string, mixed>|string $attr

$attrarray<string, mixed>|string
staticattached(string $type, mixed $post): array#

get_attached_media: the post's attachments of a kind ("video", "audio", a MIME type), as the reference's children query finds them.

Internals 9

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

privatesources(array $atts, array $types, ?string $hosted, string $kind): array|string|null#

The sources a shortcode names: the order they print in, the first file, and the attachment when the post's own media stands in. A src of another kind answers as a link; nothing at all as null.

$attsarray<string, mixed>
$typeslist<string>
@return array{order: list<string>, file: string, attachment: ?\WP_Post, atts: array<string, mixed>}|string|null
privateanyOwnFormat(array $atts, array $types): bool#

Whether any format attribute names a file of its own kind. @param array<string, mixed> $atts @param list<string> $types

$attsarray<string, mixed>@param list<string> $types
privatesourceTags(array $atts, array $order, int $instance, ?string $hosted): string#

Each source as a source tag, numbered by the instance (src a hosted video's own type when it is one). @param array<string, mixed> $atts @param list<string> $order

$attsarray<string, mixed>@param list<string> $order
privateattributes(array $attributes, array $omitEmpty): string#

The attributes as written: the flags bare when on, the empty ones left out. @param array<string, mixed> $attributes @param list<string> $omitEmpty

$attributesarray<string, mixed>@param list<string> $omitEmpty
privatefitted(int $width, int $height): array#

A video no wider than the content: wider, it takes the content's width and keeps its proportion. @return array{0: int, 1: int}

@return array{0: int, 1: int}
privatelibrary(string $kind): string#

The player library (wp_*_shortcode_library), its scripts and styles queued when it is the reference's own.

privatefallback(string $file, string $library): string#

The link a player without the library falls back to (wp_mediaelement_fallback).

privatepostId(): int#
privateinstance(string $kind): int#

The shortcode's instance number this request, counted whether or not a plugin takes it over.