API / Minn\Runtime / Attachments

Attachments final class

Minn\Runtime\Attachments · public/minn/src/Minn/Runtime/Attachments.php · 266 lines

Attachments as WordPress's media functions keep them: the uploads folder and its address, an attachment's file (stored relative to the folder), its address and metadata, and what kind of file it is; each as its filter leaves it.

Public

staticuploadDir(mixed $time = NULL): mixed#

The uploads folder and its address for a time, the month's folder too when uploads go by month (_wp_upload_dir, wp_get_upload_dir), as upload_dir leaves them.

@return array<string, mixed>
staticuploadDirMade(mixed $time = NULL, mixed $createDir = true, mixed $refreshCache = false): mixed#

The uploads folder made on disk when asked (wp_upload_dir), and returned.

staticmakeDir(mixed $target): bool#

A folder made with its parents (wp_mkdir_p): whether it is there and may be written to.

staticrelativePath(mixed $path): mixed#

A path under the uploads folder made relative to it (_wp_relative_upload_path), as _wp_relative_upload_path leaves it.

staticfile(mixed $attachmentId, mixed $unfiltered = false): mixed#

An attachment's file on disk (get_attached_file), the uploads folder before a relative one; through get_attached_file unless asked not to be.

staticsetFile(mixed $attachmentId, mixed $file): mixed#

An attachment's file recorded (update_attached_file), relative to the uploads folder; an empty one removes the record.

staticurl(mixed $attachmentId = 0): mixed#

An attachment's address (wp_get_attachment_url): its file under the uploads address, else its guid; false for no attachment or no address.

staticmetadata(mixed $attachmentId = 0, mixed $unfiltered = false): mixed#

An attachment's metadata (wp_get_attachment_metadata), the post being read's for none; one stored in a shape the meta reader refuses is parsed from its row; false for none; through wp_get_attachment_metadata unless asked not to be.

staticsetMetadata(mixed $attachmentId, mixed $data): mixed#

An attachment's metadata stored (wp_update_attachment_metadata) as wp_update_attachment_metadata leaves it; an empty one removed.

staticis(mixed $type, mixed $post = NULL): bool#

Whether an attachment is a kind of file (wp_attachment_is): image, audio, video, or a MIME type or extension.

staticisImage(mixed $post = NULL): bool#

Whether an attachment is an image (wp_attachment_is_image).

staticaudioExtensions(): mixed#

The audio file extensions the player takes (wp_get_audio_extensions), as wp_audio_extensions leaves them.

staticvideoExtensions(): mixed#

The video file extensions the player takes (wp_get_video_extensions), as wp_video_extensions leaves them.

staticinsert(mixed $args, mixed $file = false, mixed $parentPostId = 0, mixed $wpError = false, mixed $fireAfterHooks = true): mixed#

An attachment stored (wp_insert_attachment): the arguments over a file and no parent, the parent given, saved as a post of type attachment.

staticdelete(mixed $postId, mixed $force = false): mixed#

An attachment deleted (wp_delete_attachment): to the trash first unless forced or the media trash is off; unless pre_delete_attachment answers, its terms, comments and meta removed, the row between delete_post and deleted_post, then its files. The post, or null.

staticdeleteFiles(mixed $postId, mixed $meta, mixed $backupSizes, mixed $file): bool#

An attachment's files deleted, its sizes and backups too (wp_delete_attachment_files); false when any was missing or outside the uploads folder.

staticreadImageMetadata(mixed $file): mixed#

A photo's own description from its IPTC and EXIF (wp_read_image_metadata), through wp_read_image_metadata_types and wp_read_image_metadata; false when there is no such file.

Internals 1

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

privatefileUrl(string $file): string#

Where an attached file is served from, by where its stored path points: inside the uploads folder, its folder swapped for the uploads address; through an old uploads folder elsewhere, the part after that folder, reached from a level under the uploads address; otherwise relative to the uploads address.