Class MLA (Media Library Assistant) Shortcode Support provides the functions that implement the [mla_gallery] and [mla_tag_cloud] shortcodes.

It also implements the mla_get_shortcode_attachments() and mla_get_terms() database access functions.

package Media Library Assistant
since 2.20

 Methods

Compose one level of an mla_term_list

_compose_term_list(string $list, array $links, array $terms, array $markup_values, array $arguments, array $attr) : void

Adds shortcode output text and term-specific links to arrays passed by reference.

since 2.25

Parameters

$list

string

Shortcode output text, by reference

$links

array

Term-specific links for flat/array output, by reference

$terms

array

Term objects, by reference

$markup_values

array

Style and list-level substitution parameters, by reference

$arguments

array

Shortcode parameters, including defaults, by reference

$attr

array

Shortcode parameters, explicit, by reference

Parses shortcode parameters and returns the gallery objects

mla_get_shortcode_attachments(int $post_parent, array $attr, boolean $return_found_rows) : array

since 2.20

Parameters

$post_parent

int

Post ID of the parent

$attr

array

Attributes of the shortcode

$return_found_rows

boolean

true to calculate and return ['found_posts'] as an array element

Returns

arrayList of attachments returned from WP_Query

Retrieve the terms in one or more taxonomies.

mla_get_terms(array $attr) : array

Alternative to WordPress /wp-includes/taxonomy.php function get_terms() that provides an accurate count of attachments associated with each term.

taxonomy - string containing one or more (comma-delimited) taxonomy names or an array of taxonomy names. Default 'post_tag'.

post_mime_type - MIME type(s) of the items to include in the term-specific counts. Default 'all'.

post_type - The post type(s) of the items to include in the term-specific counts. The default is "attachment".

post_status - The post status value(s) of the items to include in the term-specific counts. The default is "inherit".

ids - A comma-separated list of attachment ID values for an item-specific cloud.

include - An array, comma- or space-delimited string of term ids to include in the return array.

exclude - An array, comma- or space-delimited string of term ids to exclude from the return array. If 'include' is non-empty, 'exclude' is ignored.

parent - term_id of the terms' immediate parent; 0 for top-level terms.

minimum - minimum number of attachments a term must have to be included. Default 0.

no_count - 'true', 'false' (default) to suppress term-specific attachment-counting process.

number - maximum number of term objects to return. Terms are ordered by count, descending and then by term_id before this value is applied. Default 0.

orderby - 'count', 'id', 'name' (default), 'none', 'random', 'slug'

order - 'ASC' (default), 'DESC'

no_orderby - 'true', 'false' (default) to suppress ALL sorting clauses else false.

preserve_case - 'true', 'false' (default) to make orderby case-sensitive.

pad_counts - 'true', 'false' (default) to to include the count of all children in their parents' count.

limit - final number of term objects to return, for pagination. Default 0.

offset - number of term objects to skip, for pagination. Default 0.

fields - string with fields for the SQL SELECT clause, e.g., 't.term_id, t.name, t.slug, COUNT(p.ID) AS count'

since 2.20

Parameters

$attr

array

taxonomies to search and query parameters

Returns

arrayarray of term objects, empty if none found

Verify the presence of Ghostscript for mla_viewer

mla_ghostscript_present(string $explicit_path, boolean $ghostscript_only) : boolean

since 2.20

Parameters

$explicit_path

string

Non-standard location to override default search, e.g., 'C:\Program Files (x86)\gs\gs9.15\bin\gswin32c.exe'

$ghostscript_only

boolean

Force ghostscript-only tests, used by MLASettings::_compose_mla_gallery_tab()

Returns

booleantrue if Ghostscript available else false

Filters all clauses for shortcode queries, pre caching plugins

mla_shortcode_query_posts_clauses_filter(array $pieces) : array

This is for debug purposes only. Defined as public because it's a filter.

since 2.20

Parameters

$pieces

array

query clauses before modification

Returns

arrayquery clauses after modification (none)

Filters all clauses for shortcode queries, post caching plugins

mla_shortcode_query_posts_clauses_request_filter(array $pieces) : array

This is for debug purposes only. Defined as public because it's a filter.

since 2.20

Parameters

$pieces

array

query clauses before modification

Returns

arrayquery clauses after modification (none)

Filters the JOIN clause for shortcode queries

mla_shortcode_query_posts_join_filter(string $join_clause) : string

Defined as public because it's a filter.

since 2.20

Parameters

$join_clause

string

query clause before modification

Returns

stringquery clause after item modification

Filters the ORDERBY clause for shortcode queries

mla_shortcode_query_posts_orderby_filter(string $orderby_clause) : string

This is an enhanced version of the code found in wp-includes/query.php, function get_posts. Defined as public because it's a filter.

since 2.20

Parameters

$orderby_clause

string

query clause before modification

Returns

stringquery clause after modification

Filters the WHERE clause for shortcode queries

mla_shortcode_query_posts_where_filter(string $where_clause) : string

Captures debug information. Adds whitespace to the post_type = 'attachment' phrase to circumvent subsequent Role Scoper modification of the clause. Handles post_parent "any" and "none" cases. Defined as public because it's a filter.

since 2.20

Parameters

$where_clause

string

query clause before modification

Returns

stringquery clause after modification

The MLA Tag Cloud support function.

mla_tag_cloud(array $attr) : string

This is an alternative to the WordPress wp_tag_cloud function, with additional options to customize the hyperlink behind each term.

since 2.20

Parameters

$attr

array

Attributes of the shortcode.

Returns

stringHTML content to display the tag cloud.

The MLA Tag Cloud shortcode.

mla_tag_cloud_shortcode(array $attr, string $content) : string

This is an interface to the mla_tag_cloud function.

since 2.20

Parameters

$attr

array

Attributes of the shortcode.

$content

string

Optional content for enclosing shortcodes

Returns

stringHTML content to display the tag cloud.

The MLA Term List support function.

mla_term_list(array $attr) : string

This is an alternative to the WordPress wp_list_categories, wp_dropdown_categories and wp_terms_checklist functions, with additional options to customize the hyperlink behind each term.

since 2.25

Parameters

$attr

array

Attributes of the shortcode.

Returns

stringHTML content to display the term list, dropdown control or checklist.

The MLA Term List shortcode.

mla_term_list_shortcode(array $attr, string $content) : string

This is an interface to the mla_term_list function.

since 2.25

Parameters

$attr

array

Attributes of the shortcode.

$content

string

Optional content for enclosing shortcodes

Returns

stringHTML content to display the term list.

Add level to term children and count them, all levels.

_count_term_children(object $parent, integer $depth) : integer

Recalculates term counts by including items from child terms. Assumes all relevant children are already in the $terms argument.

since 2.25

Parameters

$parent

object

Parent Term objects, by reference

$depth

integer

Maximum depth of parent/child relationship

Returns

integerTotal number of children, all levels

Find a term that matches $child_of

_find_child_of(array $parents, integer $parent_id) : mixed

since 2.25

Parameters

$parents

array

Potential parent Term objects, by reference

$parent_id

integer

Term_id of the desired parent

Returns

mixedTerm object of the desired parent else false

Find the term(s) that match $include_tree

_find_include_tree(array $terms, array $include_tree) : mixed

since 2.25

Parameters

$terms

array

Potential term objects, by reference

$include_tree

array

term_id(s) of the desired terms

Returns

mixedTerm object(s) of the desired terms else false

Walk a list of terms and find hierarchy, preserving source order.

_get_term_tree(array $terms, array $arguments) : array

since 2.25

Parameters

$terms

array

Term objects, by reference

$arguments

array

Shortcode arguments, including defaults

Returns

array( [taxonomy] => array( [root terms] => array( [fields], array( 'children' => [child terms] )

Add count of children to parent count.

_pad_term_counts(array $terms, string $taxonomy, array $post_types, array $post_stati) : null

Recalculates term counts by including items from child terms. Assumes all relevant children are already in the $terms argument.

since 2.20

Parameters

$terms

array

Array of Term objects, by reference

$taxonomy

string

Term Context

$post_types

array

Qualifying post type value(s)

$post_stati

array

Qualifying post status value(s)

Returns

nullWill break from function if conditions are not met.

Handles pagnation output types 'previous_page', 'next_page', and 'paginate_links'

_process_pagination_output_types(array $output_parameters, string $markup_values, string $arguments, string $attr, integer $found_rows, string $output) : mixed

since 2.20

Parameters

$output_parameters

array

value(s) for mla_output_type parameter

$markup_values

string

template substitution values, e.g., ('instance' => '1', ... )

$arguments

string

merged default and passed shortcode parameter values

$attr

string

raw passed shortcode parameter values

$found_rows

integer

number of attachments in the gallery, without pagination

$output

string

output text so far, may include debug values

Returns

mixedfalse or string with HTML for pagination output types

Handles brace/bracket escaping and parses template for a shortcode parameter

_process_shortcode_parameter(string $text, string $markup_values) : string

since 2.20

Parameters

$text

string

raw shortcode parameter, e.g., "text {+field+} {brackets} \{braces\}"

$markup_values

string

template substitution values, e.g., ('instance' => '1', ... )

Returns

stringparameter with brackets, braces, substitution parameters and templates processed

Computes image dimensions for scalable graphics, e.g., SVG

_registered_dimensions() : array

since 2.20

Returns

array

Remove the term(s) that match $exclude_tree

_remove_exclude_tree(array $terms, array $exclude_tree) : void

since 2.25

Parameters

$terms

array

Potential term objects, by reference

$exclude_tree

array

term_id(s) of the desired terms

Cleans up damage caused by the Visual Editor to the tax_query and meta_query specifications

_sanitize_query_specification(string $specification) : string

since 2.20

Parameters

$specification

string

query specification; PHP nested arrays

Returns

stringquery specification with HTML escape sequences and line breaks removed

Make sure $attr is an array, repair line-break damage, merge with $content

_validate_attributes(mixed $attr, string $content) : array

since 2.20

Parameters

$attr

mixed

Array or string containing shortcode attributes

$content

string

Optional content for enclosing shortcodes; might be used with mla_alt_shortcode

Returns

arrayclean attributes array

Translates query parameters to a valid SQL order by clause.

_validate_sql_orderby(array $query_parameters, string $table_prefix, array $allowed_keys, array $binary_keys) : string | bool

Accepts one or more valid columns, with or without ASC/DESC. Enhanced version of /wp-includes/formatting.php function sanitize_sql_orderby().

since 2.20

Parameters

$query_parameters

array

Validated query parameters; 'order', 'orderby', 'meta_key', 'post__in'.

$table_prefix

string

Optional. Database table prefix; can be empty. Default taken from $wpdb->posts.

$allowed_keys

array

Optional. Field names (keys) and database column equivalents (values). Defaults from [mla_gallery].

$binary_keys

array

Optional. Field names (values) that require a BINARY prefix to preserve case order. Default array()

Returns

stringboolReturns the orderby clause if present, false otherwise.

 Properties

 

Turn debug collection and display on or off

$mla_debug : boolean

since 2.20
 

Data selection parameters for the WP_Query in [mla_gallery]

$mla_get_shortcode_attachments_parameters : array

since 2.20
 

Data selection parameters for [mla_tag_cloud], [mla_term_list]

$mla_get_terms_parameters : array

since 2.20
 

WP_Query filter "parameters"

$query_parameters : array

This array defines parameters for the query's join, where and orderby filters. The parameters are set up in the mla_get_shortcode_attachments function, and any further logic required to translate those values is contained in the filter.

Array index values are: orderby, post_parent

since 2.20
 

These are the default parameters for term list display

$term_list_item_specific_arguments : array

since 2.30