\MLAMime

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

Summary

Methods
Properties
Constants
initialize()
mla_sanitize_mime_type_filter()
mla_ext2type_filter()
mla_wp_check_filetype_and_ext_filter()
mla_mime_types_filter()
mla_upload_mimes_filter()
mla_post_mime_types_filter()
mla_icon_dir_filter()
mla_icon_dir_uri_filter()
mla_icon_dirs_filter()
mla_wp_mime_type_icon_filter()
mla_count_view_items()
mla_query_view_items()
mla_pluck_table_views()
mla_prepare_view_query()
mla_parse_view_specification()
mla_add_post_mime_type()
mla_update_post_mime_type()
mla_get_post_mime_type_slug()
mla_get_post_mime_type()
mla_delete_post_mime_type()
mla_count_upload_items()
mla_query_upload_items()
mla_tabulate_upload_items()
mla_get_core_icon_type()
mla_get_icon_type_size()
mla_get_icon_type_image()
mla_get_current_icon_types()
mla_add_upload_mime()
mla_update_upload_mime()
mla_get_upload_mime_slug()
mla_get_upload_mime()
mla_delete_upload_mime()
mla_count_optional_upload_items()
mla_query_optional_upload_items()
mla_get_optional_upload_mime()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_prepare_view_items_query()
_execute_view_items_query()
_get_post_mime_templates()
_put_post_mime_templates()
_prepare_upload_items_query()
_execute_upload_items_query()
_get_core_icon_types()
_get_current_icon_types()
_get_upload_mime_templates()
_put_upload_mime_templates()
_prepare_optional_upload_items_query()
_execute_optional_upload_items_query()
_get_optional_upload_mime_templates()
$disable_mla_filtering
$mla_icon_type_associations
$mla_post_mime_templates
$mla_post_mime_highest_ID
$mla_core_icon_types
$mla_current_icon_types
$mla_upload_mime_templates
$mla_upload_mime_descriptions
$mla_upload_mime_highest_ID
$mla_optional_upload_mime_templates
N/A

Properties

$disable_mla_filtering

$disable_mla_filtering : boolean

Disable MIME filtering during option initialization

Type

boolean

$mla_icon_type_associations

$mla_icon_type_associations : array

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

Type

array — slug => ( singular, plural, specification, post_mime_type, table_view, menu_order, description )

$mla_post_mime_templates

$mla_post_mime_templates : array

In-memory representation of the Post MIME Types

Type

array — slug => ( singular, plural, specification, post_mime_type, table_view, menu_order, description )

$mla_post_mime_highest_ID

$mla_post_mime_highest_ID : integer

Highest existing Post MIME Type ID value

Type

integer

$mla_core_icon_types

$mla_core_icon_types : array

Icon types without MLA filtering

Type

array — extension => ( core_icon_type )

$mla_current_icon_types

$mla_current_icon_types : array

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

Type

array — ( icon_type => icon_image_uri )

$mla_upload_mime_templates

$mla_upload_mime_templates : array

In-memory representation of the Upload MIME Types

Type

array — extension => ( post_ID, mime_type, core_type, mla_type, source, standard_source, disabled, description, icon_type, wp_icon_type, mla_icon_type, core_icon_type )

$mla_upload_mime_descriptions

$mla_upload_mime_descriptions : array

In-memory cache of the default Upload MIME Type descriptions

Type

array — extension => description

$mla_upload_mime_highest_ID

$mla_upload_mime_highest_ID : integer

Highest existing Upload MIME Type ID value

Type

integer

$mla_optional_upload_mime_templates

$mla_optional_upload_mime_templates : array

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

Type

array — ( ID, slug, mime_type, core_type, mla_type, description )

Methods

initialize()

initialize() : void

Initialization function, similar to __construct()

mla_sanitize_mime_type_filter()

mla_sanitize_mime_type_filter(  $sanitized_mime_type,   $raw_mime_type) : string

Sanitize a MIME type

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

Parameters

$sanitized_mime_type
$raw_mime_type

Returns

string —

Updated sanitized MIME type

mla_ext2type_filter()

mla_ext2type_filter(  $standard_types) : array

Update the file extension to icon type (e.g., xls => spreadsheet, doc => document) 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.

Parameters

$standard_types

Returns

array —

The updated associations array.

mla_wp_check_filetype_and_ext_filter()

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

Attempts to determine the real file type of a file

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

Parameters

$validate
$file
$filename
$mimes

Returns

array —

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

mla_mime_types_filter()

mla_mime_types_filter(  $mime_types) : array

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

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.

Parameters

$mime_types

Returns

array —

Updated MIME types

mla_upload_mimes_filter()

mla_upload_mimes_filter(  $mime_types,   $user = NULL) : array

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

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.

Parameters

$mime_types
$user

Returns

array —

Updated allowed MIME types

mla_post_mime_types_filter()

mla_post_mime_types_filter(  $post_mime_types) : array

Get default Post MIME Types

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.

Parameters

$post_mime_types

Returns

array —

Updated allowed MIME types

mla_icon_dir_filter()

mla_icon_dir_filter(  $path) : string

Retrieve the icon directory for a MIME type

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.

Parameters

$path

Returns

string —

Updated path to the icon directory, no trailing slash

mla_icon_dir_uri_filter()

mla_icon_dir_uri_filter(  $uri) : string

Retrieve the icon directory URL for a MIME type

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

Parameters

$uri

Returns

string —

Updated path to the icon directory URL, no trailing slash

mla_icon_dirs_filter()

mla_icon_dirs_filter(  $path_uri_array) : array

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

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

Parameters

$path_uri_array

Returns

array —

Updated (path => URI) array

mla_wp_mime_type_icon_filter()

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

Retrieve the icon for a MIME type

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

Parameters

$icon
$mime
$post_id

Returns

array —

Updated URI to the MIME type icon

mla_count_view_items()

mla_count_view_items(  $request) : integer

Get the total number of MLA post_mime_type objects

Parameters

$request

Returns

integer —

Number of MLA post_mime_type objects

mla_query_view_items()

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

Retrieve MLA post_mime_type objects for list table display

Parameters

$request
$offset
$count

Returns

array —

MLA post_mime_type objects

mla_pluck_table_views()

mla_pluck_table_views() : array

Retrieve views eligible for Media/Assistant table display

Returns

array —

table views array ( specification => Plural Label )

mla_prepare_view_query()

mla_prepare_view_query(  $slug,   $specification) : array

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

Compatibility shim for MLACore::mla_prepare_view_query

Parameters

$slug
$specification

Returns

array —

post_mime_type specification or custom field query

mla_parse_view_specification()

mla_parse_view_specification(  $specification) : array

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

Compatibility shim for MLACore::mla_parse_view_specification

Parameters

$specification

Returns

array —

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

mla_add_post_mime_type()

mla_add_post_mime_type(  $request) : array

Add an MLA post_mime_type object

Parameters

$request

Returns

array —

Message(s) reflecting the results of the operation

mla_update_post_mime_type()

mla_update_post_mime_type(  $request) : array

Update an MLA post_mime_type object

Parameters

$request

Returns

array —

Message(s) reflecting the results of the operation

mla_get_post_mime_type_slug()

mla_get_post_mime_type_slug(  $post_ID) : mixed

Retrieve an MLA post_mime_type slug given a post_ID

Parameters

$post_ID

Returns

mixed —

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

mla_get_post_mime_type()

mla_get_post_mime_type(  $slug) : mixed

Retrieve an MLA post_mime_type object

Parameters

$slug

Returns

mixed —

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

mla_delete_post_mime_type()

mla_delete_post_mime_type(  $slug) : array

Delete an MLA post_mime_type object

Parameters

$slug

Returns

array —

Message(s) reflecting the results of the operation

mla_count_upload_items()

mla_count_upload_items(  $request) : integer

Get the total number of MLA Upload MIME Type objects

Parameters

$request

Returns

integer —

Number of MLA Upload MIME Type objects

mla_query_upload_items()

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

Retrieve MLA Upload MIME Type objects for list table display

Parameters

$request
$offset
$count

Returns

array —

MLA Upload MIME Type objects

mla_tabulate_upload_items()

mla_tabulate_upload_items(  $s = '') : array

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

Parameters

$s

Returns

array —

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

mla_get_core_icon_type()

mla_get_core_icon_type(  $extension) : string

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

Parameters

$extension

Returns

string —

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

mla_get_icon_type_size()

mla_get_icon_type_size(  $icon_type) : array

Get an attachment icon height and width

Parameters

$icon_type

Returns

array —

( width, height )

mla_get_icon_type_image()

mla_get_icon_type_image(  $icon_type,   $size = NULL) : string

Get an HTML img element representing an attachment icon

Parameters

$icon_type
$size

Returns

string —

HTML img element or empty string on failure.

mla_get_current_icon_types()

mla_get_current_icon_types() : array

Get an array of current Icon Type names

Returns

array —

( icon_type ) or false on failure.

mla_add_upload_mime()

mla_add_upload_mime(  $request) : array

Add an MLA Upload MIME Type object

Parameters

$request

Returns

array —

Message(s) reflecting the results of the operation

mla_update_upload_mime()

mla_update_upload_mime(  $request = NULL) : array

Update an MLA Upload MIME Type object

Parameters

$request

Returns

array —

Message(s) reflecting the results of the operation

mla_get_upload_mime_slug()

mla_get_upload_mime_slug(  $post_ID) : mixed

Retrieve an MLA Upload MIME Type slug given a post_ID

Parameters

$post_ID

Returns

mixed —

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

mla_get_upload_mime()

mla_get_upload_mime(  $slug) : mixed

Retrieve an MLA Upload MIME Type object

Parameters

$slug

Returns

mixed —

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

mla_delete_upload_mime()

mla_delete_upload_mime(  $slug) : array

Delete an MLA Upload MIME Type object

Parameters

$slug

Returns

array —

Message(s) reflecting the results of the operation

mla_count_optional_upload_items()

mla_count_optional_upload_items(  $request) : integer

Get the total number of MLA Upload MIME Type objects

Parameters

$request

Returns

integer —

Number of MLA Upload MIME Type objects

mla_query_optional_upload_items()

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

Retrieve MLA Upload MIME Type objects for list table display

Parameters

$request
$offset
$count

Returns

array —

MLA Upload MIME Type objects

mla_get_optional_upload_mime()

mla_get_optional_upload_mime(  $ID) : mixed

Retrieve an MLA Optional Upload MIME Type given an ID

Parameters

$ID

Returns

mixed —

the requested object; false if object not found

_prepare_view_items_query()

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

Sanitize and expand query arguments from request variables

Parameters

$raw_request
$offset
$count

Returns

array —

revised arguments suitable for query

_execute_view_items_query()

_execute_view_items_query(  $request) : array

Add filters, run query, remove filters

Parameters

$request

Returns

array —

query results; array of MLA post_mime_type objects

_get_post_mime_templates()

_get_post_mime_templates(  $force_refresh = false) : boolean

Assemble the in-memory representation of the Post MIME Types

Parameters

$force_refresh

Returns

boolean —

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

_put_post_mime_templates()

_put_post_mime_templates() : boolean

Store the custom entries of the Post MIME Types

Returns

boolean —

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

_prepare_upload_items_query()

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

Sanitize and expand Upload MIME Type query arguments from request variables

Parameters

$raw_request
$offset
$count

Returns

array —

revised arguments suitable for query

_execute_upload_items_query()

_execute_upload_items_query(  $request) : array

Execute an Upload MIME Types query

Parameters

$request

Returns

array —

query results; array of MLA Upload MIME Type objects

_get_core_icon_types()

_get_core_icon_types() : boolean

Assemble the list of icon types without MLA filtering

Returns

boolean —

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

_get_current_icon_types()

_get_current_icon_types() : boolean

Assemble the list of icon types with MLA filtering

Returns

boolean —

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

_get_upload_mime_templates()

_get_upload_mime_templates(  $force_refresh = false) : boolean

Assemble the in-memory representation of the Upload MIME Types

Parameters

$force_refresh

Returns

boolean —

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

_put_upload_mime_templates()

_put_upload_mime_templates() : boolean

Store the options portion of the Upload MIME Types

Returns

boolean —

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

_prepare_optional_upload_items_query()

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

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

Parameters

$raw_request
$offset
$count

Returns

array —

revised arguments suitable for query

_execute_optional_upload_items_query()

_execute_optional_upload_items_query(  $request) : array

Execute an Optional Upload MIME Types query

Parameters

$request

Returns

array —

query results; array of MLA Optional Upload MIME Type objects

_get_optional_upload_mime_templates()

_get_optional_upload_mime_templates() : boolean

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

Returns

boolean —

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