Media

Media Library Utilities

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

attach_file_from_url()  : int
Downloads a file from a URL and attaches it to the document
get_file_url()  : string|bool
Convert file url to full path.
get_filename_without_extension()  : string
Removes extension from a filename
get_attachment_id_from_url()  : mixed
Retrieves an attachment object based on a URL
maybe_sanitize_dropbox_link()  : string
Cleans dropbox preview URLs for downloading.
set_uploaded_document_as_attachment()  : int
Set uploaded document as attachment.
upload_document_from_url()  : array<string|int, mixed>|WP_Error
Upload document from URL.

Methods

attach_file_from_url()

Downloads a file from a URL and attaches it to the document

public static attach_file_from_url(string $url, int $document_id) : int
Parameters
$url : string

Attachment URL.

$document_id : int

Document ID

Tags
throws
Exception

If attachment cannot be loaded.

Return values
int

get_file_url()

Convert file url to full path.

public static get_file_url(string $url) : string|bool
Parameters
$url : string

url of the file.

Tags
Return values
string|bool

get_filename_without_extension()

Removes extension from a filename

public static get_filename_without_extension(string $file_name) : string
Parameters
$file_name : string
Tags
Return values
string

get_attachment_id_from_url()

Retrieves an attachment object based on a URL

private static get_attachment_id_from_url(string $attachment_url) : mixed
Parameters
$attachment_url : string
Tags
Return values
mixed

Cleans dropbox preview URLs for downloading.

private static maybe_sanitize_dropbox_link(string $document_url) : string
Parameters
$document_url : string
Tags
Return values
string

set_uploaded_document_as_attachment()

Set uploaded document as attachment.

private static set_uploaded_document_as_attachment(array<string|int, mixed> $upload, int $id) : int
Parameters
$upload : array<string|int, mixed>

Upload information from wp_upload_bits.

$id : int

Post ID. Default to 0.

Tags
Return values
int

Attachment ID

upload_document_from_url()

Upload document from URL.

private static upload_document_from_url(string $document_url) : array<string|int, mixed>|WP_Error
Parameters
$document_url : string

File URL.

Tags
Return values
array<string|int, mixed>|WP_Error

Attachment data or error message.

Search results