/** * Constructs instance of Document. * * @param WP_Post $attachment Attachment object used to initalize fields. * @param DG_Gallery $gallery Instance of Gallery class. */ public function __construct($attachment, $gallery) { // init general document data $this->gallery = $gallery; $this->description = wptexturize($attachment->post_content); $this->ID = $attachment->ID; $this->link = $gallery->linkToAttachmentPg() ? get_attachment_link($attachment->ID) : wp_get_attachment_url($attachment->ID); $this->title = wptexturize($attachment->post_title); $this->title_attribute = esc_attr(strip_tags($this->title)); $this->path = get_attached_file($attachment->ID); $wp_filetype = wp_check_filetype_and_ext($this->path, basename($this->path)); $this->extension = $wp_filetype['ext']; $this->size = size_format(filesize($this->path)); }