Class MLA (Media Library Assistant) MIME filters WordPress MIME Type functions and supports the Views and Uploads Settings tabs

package Media Library Assistant
since 1.40

 Methods

Initialization function, similar to __construct()

initialize() : void

since 1.40

Add an MLA post_mime_type object

mla_add_post_mime_type(array $request) : array

since 1.40

Parameters

$request

array

Query variables for a single object, including slug

Returns

arrayMessage(s) reflecting the results of the operation

Add an MLA Upload MIME Type object

mla_add_upload_mime(array $request) : array

since 1.40

Parameters

$request

array

Query variables for a single object, including slug

Returns

arrayMessage(s) reflecting the results of the operation

Get the total number of MLA Upload MIME Type objects

mla_count_optional_upload_items(array $request) : integer

since 1.40

Parameters

$request

array

Query variables, e.g., from $_REQUEST

Returns

integerNumber of MLA Upload MIME Type objects

Get the total number of MLA Upload MIME Type objects

mla_count_upload_items(array $request) : integer

since 1.40

Parameters

$request

array

Query variables, e.g., from $_REQUEST

Returns

integerNumber of MLA Upload MIME Type objects

Get the total number of MLA post_mime_type objects

mla_count_view_items(array $request) : integer

since 1.40

Parameters

$request

array

Query variables, e.g., from $_REQUEST

Returns

integerNumber of MLA post_mime_type objects

Delete an MLA post_mime_type object

mla_delete_post_mime_type(string $slug) : array

since 1.40

Parameters

$slug

string

MLA post_mime_type slug

Returns

arrayMessage(s) reflecting the results of the operation

Delete an MLA Upload MIME Type object

mla_delete_upload_mime(string $slug) : array

since 1.40

Parameters

$slug

string

MLA Upload MIME Type slug

Returns

arrayMessage(s) reflecting the results of the operation

Update the file extension to icon type (e.g., xls => spreadsheet, doc => document) array

mla_ext2type_filter(array $standard_types) : array

Note that the calling function, wp_ext2type, takes an extension and returns an icon type. This filter updates the array of possible matches to support the calling function.

Called from /wp-includes/functions.php, function wp_ext2type(). That function is called from /wp-admin/includes/ajax-actions.php, function wp_ajax_send_link_to_editor(), /wp-admin/includes/media.php, function wp_media_upload_handler(), and /wp-includes/post.php, function wp_mime_type_icon(). The first two calls look for "audio" and "video" files to call the appropriate filter. The third call assigns the appropriate icon to the file for display purposes.

Defined as public because it's a filter.

since 1.40

Parameters

$standard_types

array

The type => ( extensions ) associations.

Returns

arrayThe updated associations array.

Retrieve a standard icon type, i.e., without MLA filtering

mla_get_core_icon_type(string $extension) : string

since 1.40

Parameters

$extension

string

file extension

Returns

stringicon type for the requested extension; 'default' if extension not found

Get an array of current Icon Type names

mla_get_current_icon_types() : array

since 1.40

Returns

array( icon_type ) or false on failure.

Get an HTML img element representing an attachment icon

mla_get_icon_type_image(string $icon_type, array $size) : string

since 1.40

Parameters

$icon_type

string

Icon Type, e.g., audio, video, spreadsheet

$size

array

( width, height ) optional image size, default (64, 64).

Returns

stringHTML img element or empty string on failure.

Get an attachment icon height and width

mla_get_icon_type_size(string $icon_type) : array

since 2.14

Parameters

$icon_type

string

Icon Type, e.g., audio, video, spreadsheet

Returns

array( width, height )

Retrieve an MLA Optional Upload MIME Type given an ID

mla_get_optional_upload_mime(integer $ID) : mixed

since 1.40

Parameters

$ID

integer

MLA Optional Upload MIME Type ID

Returns

mixedthe requested object; false if object not found

Retrieve an MLA post_mime_type object

mla_get_post_mime_type(string $slug) : mixed

since 1.40

Parameters

$slug

string

MLA post_mime_type slug

Returns

mixedArray of elements, including slug, for the requested object; false if object not found

Retrieve an MLA post_mime_type slug given a post_ID

mla_get_post_mime_type_slug(integer $post_ID) : mixed

since 1.40

Parameters

$post_ID

integer

MLA post_mime_type post_ID

Returns

mixedstring with slug of the requested object; false if object not found

Retrieve an MLA Upload MIME Type object

mla_get_upload_mime(string $slug) : mixed

since 1.40

Parameters

$slug

string

MLA Upload MIME Type slug

Returns

mixedArray of elements, including slug, for the requested object; false if object not found

Retrieve an MLA Upload MIME Type slug given a post_ID

mla_get_upload_mime_slug(integer $post_ID) : mixed

since 1.40

Parameters

$post_ID

integer

MLA Upload MIME Type post_ID

Returns

mixedstring with slug of the requested object; false if object not found

Retrieve the icon directory for a MIME type

mla_icon_dir_filter(string $path) : string

Called from /wp-includes/deprecated.php, function get_attachment_icon_src(). Called from /wp-includes/media.php, function wp_get_attachment_image_src(). Called from /wp-includes/post.php, function wp_mime_type_icon(). Defined as public because it's a filter.

since 1.40

Parameters

$path

string

Path to the icon directory

Returns

stringUpdated path to the icon directory, no trailing slash

Retrieve the icon directory URL for a MIME type

mla_icon_dir_uri_filter(string $uri) : string

Called from /wp-includes/post.php, function wp_mime_type_icon(). Defined as public because it's a filter.

since 1.40

Parameters

$uri

string

Path to the icon directory URL

Returns

stringUpdated path to the icon directory URL, no trailing slash

Retrieve the icon (directory => URI) array for a MIME type

mla_icon_dirs_filter(array $path_uri_array) : array

Called from /wp-includes/post.php, function wp_mime_type_icon(). Defined as public because it's a filter.

since 1.40

Parameters

$path_uri_array

array

Path(s) and URI(s) to the icon directories

Returns

arrayUpdated (path => URI) array

Retrieve list of MIME types and file extensions; use this filter to add types

mla_mime_types_filter(array $mime_types) : array

Called from /wp-includes/functions.php, function wp_get_mime_types(). That function is called from /wp-includes/class-wp-image-editor.php functions get_mime_type() and get_extension(), and from /wp-includes/functions.php, functions do_enclose() and get_allowed_mime_types().

Defined as public because it's a filter.

since 1.40

Parameters

$mime_types

array

Mime types keyed by the file extension regex corresponding to those types

Returns

arrayUpdated MIME types

Analyze a Library View/Post MIME Type specification, returning an array of the placeholders it contains

mla_parse_view_specification(string | array $specification) : array

Compatibility shim for MLACore::mla_parse_view_specification

since 1.40

Parameters

$specification

stringarray

A specification, e.g., "custom:Field,null" or "audio,application/vnd.ms"

Returns

array( ['prefix'] => string, ['name'] => string, ['value'] => string, ['option'] => string, optional ['error'] => string )

Retrieve views eligible for Media/Assistant table display

mla_pluck_table_views() : array

since 1.40

Returns

arraytable views array ( specification => Plural Label )

Get default Post MIME Types

mla_post_mime_types_filter(array $post_mime_types) : array

Called from /wp-includes/post.php, function get_post_mime_types(). That function is called from: /wp-admin/includes/media.php function get_media_item(), to validate the type of an attachment when it is edited, /wp-admin/includes/post.php, function wp_edit_attachments_query() to count the number of attachments of each type, and /wp-includes/media.php function wp_enqueue_media(), to populate the the Media Manager/Add Media "media items" drop down list.

Defined as public because it's a filter.

since 1.40

Parameters

$post_mime_types

array

Content types (image, audio, video) and presentation strings, e.g. 'image' => array(__('Images', 'media-library-assistant'), __('Manage Images', 'media-library-assistant'), _n_noop('Image (%s)', 'Images (%s)', 'media-library-assistant')),

Returns

arrayUpdated allowed MIME types

Convert a Library View/Post MIME Type specification to WP_Query parameters

mla_prepare_view_query(string $slug, string $specification) : array

Compatibility shim for MLACore::mla_prepare_view_query

since 1.40

Parameters

$slug

string

View slug, unique identifier

$specification

string

A specification, e.g., "custom:Field,null" or "audio,application/vnd.ms"

Returns

arraypost_mime_type specification or custom field query

Retrieve MLA Upload MIME Type objects for list table display

mla_query_optional_upload_items(array $request, int $offset, int $count) : array

since 1.40

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

$offset

int

number of rows to skip over to reach desired page

$count

int

number of rows on each page

Returns

arrayMLA Upload MIME Type objects

Retrieve MLA Upload MIME Type objects for list table display

mla_query_upload_items(array $request, int $offset, int $count) : array

since 1.40

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

$offset

int

number of rows to skip over to reach desired page

$count

int

number of rows on each page

Returns

arrayMLA Upload MIME Type objects

Retrieve MLA post_mime_type objects for list table display

mla_query_view_items(array $request, int $offset, int $count) : array

since 1.40

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

$offset

int

number of rows to skip over to reach desired page

$count

int

number of rows on each page

Returns

arrayMLA post_mime_type objects

Sanitize a MIME type

mla_sanitize_mime_type_filter(string $sanitized_mime_type, string $raw_mime_type) : string

Called from /wp-includes/formatting.php, function sanitize_mime_type(). Defined as public because it's a filter.

since 1.40

Parameters

$sanitized_mime_type

string

Sanitized MIME type

$raw_mime_type

string

Raw MIME type

Returns

stringUpdated sanitized MIME type

Tabulate MLA Upload MIME Type objects by view for list table display

mla_tabulate_upload_items(string $s) : array

since 1.40

Parameters

$s

string

keyword search criterion, optional

Returns

array( 'singular' label, 'plural' label, 'count' of items )

Update an MLA post_mime_type object

mla_update_post_mime_type(array $request) : array

since 1.40

Parameters

$request

array

Query variables for new object values, including optional original_slug

Returns

arrayMessage(s) reflecting the results of the operation

Update an MLA Upload MIME Type object

mla_update_upload_mime(array $request) : array

since 1.40

Parameters

$request

array

Query variables for new object values, including optional original_slug

Returns

arrayMessage(s) reflecting the results of the operation

Retrieve list of allowed MIME types and file extensions; use this filter to remove types

mla_upload_mimes_filter(array $mime_types, mixed $user) : array

Called from /wp-includes/functions.php, function get_allowed_mime_types(). That function is called from /wp-includes/formatting.php function sanitize_file_name() and from /wp-includes/functions.php, function wp_check_filetype(). wp_check_filetype returns only one MIME type for a given file extension, so the file extension should/must be a unique key.

This filter is also hooked by /wp-includes/ms-functions.php and processed in function check_upload_mimes(), which "is used to filter that list against the filetype whitelist provided by Multisite Super Admins at wp-admin/network/settings.php." Multisite installs must respect this restriction, so any list we produce will be passed thru that function if it exists.

This function is defined as public because it's a filter.

since 1.40

Parameters

$mime_types

array

Mime types keyed by the file extension regex corresponding to those types

$user

mixed

User ID (integer) or object for checking against 'unfiltered_html' capability

Returns

arrayUpdated allowed MIME types

Attempts to determine the real file type of a file

mla_wp_check_filetype_and_ext_filter(array $validate, string $file, string $filename, array $mimes) : array

Called from /wp-includes/functions.php, function wp_check_filetype_and_ext(). Defined as public because it's a filter.

since 1.40

Parameters

$validate

array

array( ext, type, proper_filename (string or false) )

$file

string

Full path to the image

$filename

string

The filename of the image

$mimes

array

Optional array of MIME types

Returns

arrayUpdated array( ext, type, proper_filename (string or false) )

Retrieve the icon for a MIME type

mla_wp_mime_type_icon_filter(string $icon, string $mime, integer $post_id) : array

Called from /wp-includes/post.php, function wp_mime_type_icon(). Defined as public because it's a filter.

since 1.40

Parameters

$icon

string

URI to the MIME type icon

$mime

string

MIME type represented by the icon

$post_id

integer

Attachment ID or zero (0) if MIME type passed in

Returns

arrayUpdated URI to the MIME type icon

Execute an Optional Upload MIME Types query

_execute_optional_upload_items_query(array $request) : array

since 1.40

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

Returns

arrayquery results; array of MLA Optional Upload MIME Type objects

Execute an Upload MIME Types query

_execute_upload_items_query(array $request) : array

since 1.40

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

Returns

arrayquery results; array of MLA Upload MIME Type objects

Add filters, run query, remove filters

_execute_view_items_query(array $request) : array

since 1.40

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

Returns

arrayquery results; array of MLA post_mime_type objects

Assemble the list of icon types without MLA filtering

_get_core_icon_types() : boolean

since 1.40

Returns

booleanSuccess (true) or failure (false) of the operation

Assemble the list of icon types with MLA filtering

_get_current_icon_types() : boolean

since 1.40

Returns

booleanSuccess (true) or failure (false) of the operation

Assemble the in-memory representation of the (read-only) Optional Upload MIME Types

_get_optional_upload_mime_templates() : boolean

since 1.40

Returns

booleanSuccess (true) or failure (false) of the operation

Assemble the in-memory representation of the Post MIME Types

_get_post_mime_templates(boolean $force_refresh) : boolean

since 1.40

Parameters

$force_refresh

boolean

Force a reload/recalculation of types

Returns

booleanSuccess (true) or failure (false) of the operation

Assemble the in-memory representation of the Upload MIME Types

_get_upload_mime_templates(boolean $force_refresh) : boolean

since 1.40

Parameters

$force_refresh

boolean

Force a reload/recalculation of types

Returns

booleanSuccess (true) or failure (false) of the operation

Sanitize and expand Optional Upload MIME Type query arguments from request variables

_prepare_optional_upload_items_query(array $raw_request, int $offset, int $count) : array

since 1.40

Parameters

$raw_request

array

query parameters from web page, usually found in $_REQUEST

$offset

int

Optional number of rows (default 0) to skip over to reach desired page

$count

int

Optional number of rows on each page (0 = all rows, default)

Returns

arrayrevised arguments suitable for query

Sanitize and expand Upload MIME Type query arguments from request variables

_prepare_upload_items_query(array $raw_request, int $offset, int $count) : array

since 1.40

Parameters

$raw_request

array

query parameters from web page, usually found in $_REQUEST

$offset

int

Optional number of rows (default 0) to skip over to reach desired page

$count

int

Optional number of rows on each page (0 = all rows, default)

Returns

arrayrevised arguments suitable for query

Sanitize and expand query arguments from request variables

_prepare_view_items_query(array $raw_request, int $offset, int $count) : array

since 1.40

Parameters

$raw_request

array

query parameters from web page, usually found in $_REQUEST

$offset

int

Optional number of rows (default 0) to skip over to reach desired page

$count

int

Optional number of rows on each page (0 = all rows, default)

Returns

arrayrevised arguments suitable for query

Store the custom entries of the Post MIME Types

_put_post_mime_templates() : boolean

since 1.40

Returns

booleanSuccess (true) or failure (false) of the operation

Store the options portion of the Upload MIME Types

_put_upload_mime_templates() : boolean

since 1.40

Returns

booleanSuccess (true) or failure (false) of the operation

 Properties

 

Disable MIME filtering during option initialization

$disable_mla_filtering : boolean

since 1.40
 

Icon types without MLA filtering

$mla_core_icon_types : array

since 1.40
 

Icon types with MLA filtering - basenames of files in the current icon directory

$mla_current_icon_types : array

since 1.40
 

In-memory representation of the Icon Type => file extension(s) associations

$mla_icon_type_associations : array

since 1.40
 

In-memory representation of the (read-only) Optional Upload MIME Types

$mla_optional_upload_mime_templates : array

since 1.40
 

Highest existing Post MIME Type ID value

$mla_post_mime_highest_ID : integer

since 1.40
 

In-memory representation of the Post MIME Types

$mla_post_mime_templates : array

since 1.40
 

In-memory cache of the default Upload MIME Type descriptions

$mla_upload_mime_descriptions : array

since 1.80
 

Highest existing Upload MIME Type ID value

$mla_upload_mime_highest_ID : integer

since 1.40
 

In-memory representation of the Upload MIME Types

$mla_upload_mime_templates : array

since 1.40