Media
Media Library Utilities
Tags
Table of Contents
- attach_file_from_url() : int
- Downloads a file from a URL and attaches it to the document
- get_allowed_preview_mime_types() : mixed
- Get allowed preview mime_types
- get_file_url() : string|bool
- Convert file url to full path.
- get_filename_without_extension() : string
- Removes extension from a filename
- get_ms_excel_mime_types() : array<string|int, string>
- Get the MS Excel mime types
- get_ms_powerpoint_mime_types() : array<string|int, string>
- Get the MS PowerPoint mime types
- get_ms_word_mime_types() : array<string|int, string>
- Get the MS Word mime types
- get_office_mime_types() : array<string|int, string>
- Returns the Office mime types for the Office Web Viewer.
- infer_external_file_mime_type() : string
- Determine the mime type of an external file
- is_dropbox_direct_link() : bool
- Check if a URL is a direct link to a Dropbox file
- is_dropbox_link() : bool
- Check if a URL is a Dropbox link
- is_dropbox_site_link() : bool
- Check if a URL is a Dropbox link
- maybe_get_dropbox_direct_link() : string
- Get raw dropbox link for direct linking.
- maybe_get_filename_from_url() : string|null
- Get the file extension from a file name
- 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
Return values
int —get_allowed_preview_mime_types()
Get allowed preview mime_types
public
static get_allowed_preview_mime_types() : mixed
Tags
Return values
mixed —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_ms_excel_mime_types()
Get the MS Excel mime types
public
static get_ms_excel_mime_types() : array<string|int, string>
Tags
Return values
array<string|int, string> —get_ms_powerpoint_mime_types()
Get the MS PowerPoint mime types
public
static get_ms_powerpoint_mime_types() : array<string|int, string>
Tags
Return values
array<string|int, string> —get_ms_word_mime_types()
Get the MS Word mime types
public
static get_ms_word_mime_types() : array<string|int, string>
Tags
Return values
array<string|int, string> —get_office_mime_types()
Returns the Office mime types for the Office Web Viewer.
public
static get_office_mime_types() : array<string|int, string>
Specifically, this is Excel, Word, and PowerPoint.
Tags
Return values
array<string|int, string> —infer_external_file_mime_type()
Determine the mime type of an external file
public
static infer_external_file_mime_type(string $filename) : string
Accepts a full URL to a file and returns the mime type
Parameters
- $filename : string
Tags
Return values
string —is_dropbox_direct_link()
Check if a URL is a direct link to a Dropbox file
public
static is_dropbox_direct_link(string $url) : bool
Parameters
- $url : string
Tags
Return values
bool —is_dropbox_link()
Check if a URL is a Dropbox link
public
static is_dropbox_link(string $url) : bool
Parameters
- $url : string
Tags
Return values
bool —is_dropbox_site_link()
Check if a URL is a Dropbox link
public
static is_dropbox_site_link(string $url) : bool
Parameters
- $url : string
Tags
Return values
bool —maybe_get_dropbox_direct_link()
Get raw dropbox link for direct linking.
public
static maybe_get_dropbox_direct_link(string $document_url) : string
Parameters
- $document_url : string
Tags
Return values
string —maybe_get_filename_from_url()
Get the file extension from a file name
public
static maybe_get_filename_from_url(string $url) : string|null
Parameters
- $url : string
Tags
Return values
string|null —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 —maybe_sanitize_dropbox_link()
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.