1. Home
  2. Docs
  3. Post Gallery
  4. Developers
  5. Attachment Model

Attachment Model

The Attachment model object is used across Post Gallery to hold and manipulate data related to an attachment (image, video or any kind of media).

Properties

title

$attachment->title

string
Attachment’s title / name.

date

$attachment->date

string
Attachment’s creation date. Database format.

mime

$attachment->mime

string
Attachment’s mime type. (i.e. image/png)

url

$attachment->url

string
Attachment’s url (if image, this will be the default resolution url).

caption

$attachment->caption

string
Attachment’s caption.

alt

$attachment->caption

string
Attachment’s alternative text.

path

$attachment->path

string
Attachment’s storage path.

thumb_url

$attachment->thumb_url

string
Attachment’s WordPress thumbnail resolution url (if object is an image).

medium_url

$attachment->medium_url

string
Attachment’s WordPress medium resolution url (if object is an image).

large_url

$attachment->large_url

string
Attachment’s WordPress large resolution url (if object is an image).

edit_url

$attachment->edit_url

string
Attachment’s edit resolution url. This is the thumbnail resolution used when displaying the media in the post edit form.

embed

$attachment->embed

string
Embed code (for external videos).

embed_size

$attachment->embed_size

string
Embed size (for external videos).

is_video

$attachment->is_video

bool
Flag that indicates if the attachment is a video or not.

video_id

$attachment->video_id

string
External video ID. (i.e. YouTube video ID)

video_url

$attachment->video_url

string
External video url.

video_provider

$attachment->video_provider

string
Slug or tag of the external video provider. (i.e. ‘youtube’ for YouTube)

is_uploaded

$attachment->is_uploaded

bool
Flag that indicates if attachment is an uploaded video. (i.e. mp4 would be uploaded)

is_lightbox

$attachment->is_lightbox

bool
Flag that indicates if the media is supported by a lightbox solution.

video_thumb

$attachment->video_thumb

string
Default video thumbnail URL (for uploaded MP4).

no_thumb_path

$attachment->no_thumb_path

string
Path to where default video thumb is located (for uploaded MP4).

no_thumb_url

$attachment->no_thumb_url

string
Thumbnail url to attachments without WordPress thumbnail resolution (for uploaded MP4).


Methods

find()

Static method used to find an individual attachment based on an ID.
Returns an attachment data object.

$attachment = PostGallery\Models\Attachment::find( $attachent_id )

$attachment_id

int
Attachment (post) ID.


save()

$attachment->save()

Saves any changes made to the attachment. USE IT CAREFULLY.


get_res()

Returns the url of the custom resolution set via parameters.

$attachment->get_res( $width, $height, $crop = true, $cache = true )

$width

int
Wanted resolution width.

$height

int
Wanted resolution width.

$crop

bool, default: true
Flag that indicates if result should be cropped to fit resolution.

$cache

bool, default: true
Flag that indicates if resulting url should be cached.

returns

string
Custom resolution url.

Was this article helpful to you? Yes No