MediaLibrary
Class.
Imports static assets of the instance into the media library, for content
that needs attachments: an #[Image] field takes the ID of an attachment,
not a file of the theme. Call it where content is created, for example in a
method with #[OnActivation] or in a WP-CLI command.
The import is idempotent per site: an asset already imported with the same content returns its attachment. A changed file becomes a new attachment; the old one stays, because content may use it. Attachments stay in the media library when the theme or plugin is removed.
Methods
import()
The attachment of an asset of the instance, imported on the first call.
Returns int: The ID of the attachment.
Throws InvalidArgumentException: If the name names no asset of the instance.
Throws RuntimeException: If WordPress cannot store the file or create the attachment.