Adds helper function for displaying download links to documents.
This commit is contained in:
parent
911baf9f08
commit
2460c55b08
|
@ -688,8 +688,6 @@ class Item extends Entity {
|
|||
} else {
|
||||
$output .= $embed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -706,4 +704,27 @@ class Item extends Entity {
|
|||
$id = $this->get_id();
|
||||
return admin_url("?page=tainacan_admin#/collections/$collection_id/items/$id/edit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Document url of this item
|
||||
*/
|
||||
public function get_document_download_url() {
|
||||
$type = $this->get_document_type();
|
||||
|
||||
$link = null;
|
||||
|
||||
if ( $type == 'url' ) {
|
||||
$link = $this->get_document();
|
||||
} elseif ( $type == 'text' ) {
|
||||
$link = $this->get_document();
|
||||
} elseif ( $type == 'attachment' ) {
|
||||
if ( wp_attachment_is_image($this->get_document()) ) {
|
||||
$link = wp_get_attachment_url($this->get_document());
|
||||
} else {
|
||||
$link = wp_get_attachment_url($this->get_document());
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,20 @@ function tainacan_get_the_document() {
|
|||
return;
|
||||
|
||||
return apply_filters('tainacan-get-the-document', $item->get_document_as_html(), $item);
|
||||
}
|
||||
|
||||
function tainacan_the_item_document_download_link() {
|
||||
$item = tainacan_get_item();
|
||||
|
||||
if (!$item)
|
||||
return;
|
||||
|
||||
$link = $item->get_document_download_url();
|
||||
|
||||
if (!$link || $item->get_document_type() == 'text')
|
||||
return;
|
||||
|
||||
return '<a name="' . __('Download the item document', 'tainacan') . '" download="'. $link . '" href="' . $link . '">' . __('Download', 'tainacan') . '</a>';
|
||||
}
|
||||
|
||||
function tainacan_the_document() {
|
||||
|
|
Loading…
Reference in New Issue