Class MLA (Media Library Assistant) Data provides database and template file access for MLA needs.

The _template functions are inspired by the book "WordPress 3 Plugin Development Essentials." Templates separate HTML markup from PHP code for easier maintenance and localization.

package Media Library Assistant
since 0.1

 Methods

Initialization function, similar to __construct()

initialize() 

since 0.1

Find Featured Image and inserted image/link references to an attachment.

mla_fetch_attachment_references(int $ID, int $parent) : array

Searches all post and page content to see if the attachment is used as a Featured Image or inserted in the post as an image or link.

since 0.1

Parameters

$ID

int

post ID of attachment

$parent

int

post ID of attachment's parent, if any

Returns

arrayReference information; see $references array comments

Retrieve an Attachment array given a $post_id.

mla_get_attachment_by_id(int $post_id) : Null

The (associative) array will contain every field that can be found in the posts and postmeta tables, and all references to the attachment.

since 0.1

Parameters

$post_id

int

The ID of the attachment post.

Returns

Nullon failure else associative array.

Load an HTML template from a file

mla_load_template(string $filepath) : string

Loads a template to a string or a multi-part template to an array. Multi-part templates are divided by comments of the form , where "key" becomes the key part of the array.

since 0.1

Parameters

$filepath

string

Complete path and name of the template file

Returns

stringFor files that do not contain template divider comments array For files containing template divider comments false If file does not exist NULL If file could not be loaded

Expand a template, replacing place holders with their values.

mla_parse_template(string $tpl, array $hash) : string

A simple parsing function for basic templating.

since 0.1

Parameters

$tpl

string

A formatting string containing [+placeholders+]

$hash

array

An associative array containing keys and values e.g. array('key' => 'value');

Returns

stringPlaceholders corresponding to the keys of the hash will be replaced with their values.

Sanitize and expand query arguments from request variables.

mla_prepare_list_table_query(array $request) : array

Prepare the arguments for WP_Query. Modeled after wp_edit_attachments_query in wp-admin/post.php NOTE: The caller must remove the 'posts_where' filter, if required.

since 0.1

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

Returns

arrayrevised arguments suitable for WP_Query

Retrieve attachment objects for list table display.

mla_query_list_table_items(array $request, string $orderby, string $order, int $offset, int $count) : array

Supports prepare_items in class-mla-list-table.php Modeled after wp_edit_attachments_query in wp-admin/post.php

since 0.1

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

$orderby

string

database column to sort by

$order

string

ASC or DESC

$offset

int

number of rows to skip over to reach desired page

$count

int

number of rows on each page

Returns

arrayattachment objects (posts) including parent data, meta data and references

Adds a WHERE clause for detached items

mla_query_list_table_items_helper(string $where) : string

Modeled after _edit_attachments_query_helper in wp-admin/post.php Defined as public so callers can remove it after the query

since 0.1

Parameters

$where

string

query clause before modification

Returns

stringquery clause after "detached" item modification

Returns information about an attachment's parent, if found.

_fetch_attachment_parent_data(int $parent_id) : array

since 0.1

Parameters

$parent_id

int

post ID of attachment's parent, if any

Returns

arrayParent information; post_date, post_title and post_type