Class MLA (Media Library Assistant) Query provides database query support for MLA Ajax, Shortcode and Admin needs

package Media Library Assistant
since 2.20

 Methods

Initialization function, similar to __construct()

initialize() 

since 0.1

Add Featured Image and inserted image/link references to an array of attachments

mla_attachment_array_fetch_references(array $attachments) : void

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

since 1.94

Parameters

$attachments

array

WP_Post objects, passed by reference

Get the total number of attachment posts

mla_count_list_table_items(array $request, int $offset, int $count) : integer

since 0.30

Parameters

$request

array

Query variables, e.g., from $_REQUEST

$offset

int

(optional) number of rows to skip over to reach desired page

$count

int

(optional) number of rows on each page

Returns

integerNumber of attachment posts

Fetch custom field option value given a slug

mla_custom_field_option_value(string $slug) : array

since 1.10

Parameters

$slug

string

slug, e.g., 'c_File Size' for the 'File Size' field

Returns

arrayoption value, e.g., array( 'name' => 'File Size', ... )

Returns information about an attachment's parent, if found

mla_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

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

mla_fetch_attachment_references(int $ID, int $parent, boolean $add_references) : 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

$add_references

boolean

True to compute references, false to return empty values

Returns

arrayReference information; see $references array comments

Invalidates the $mla_galleries or $galleries array and cached values

mla_flush_mla_galleries(string $option_name) : void

since 1.00

Parameters

$option_name

string

name of the gallery's cache/option variable

Return the names and display values of the sortable columns

mla_get_sortable_columns() : array

since 0.30

Returns

arrayname => array( orderby value, heading ) for sortable columns

Builds the $default_columns array with translated source texts.

mla_localize_default_columns_array() 

Called from MLATest::initialize because the $default_columns information might be accessed from "front end" posts/pages.

since 1.71

Retrieve attachment objects for list table display

mla_query_list_table_items(array $request, 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

$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

Retrieve attachment objects for the WordPress Media Manager

mla_query_media_modal_items(array $request, int $offset, int $count) : object

Supports month-year and taxonomy-term filters as well as the enhanced search box

since 1.20

Parameters

$request

array

query parameters from Media Manager

$offset

int

number of rows to skip over to reach desired page

$count

int

number of rows on each page

Returns

objectWP_Query object with query results

Filters all clauses for shortcode queries, pre caching plugins

mla_query_posts_clauses_filter(array $pieces) : array

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

since 1.80

Parameters

$pieces

array

query clauses before modification

Returns

arrayquery clauses after modification (none)

Filters all clauses for shortcode queries, post caching plugins

mla_query_posts_clauses_request_filter(array $pieces) : array

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

since 1.80

Parameters

$pieces

array

query clauses before modification

Returns

arrayquery clauses after modification (none)

Adds a GROUPBY clause, if required

mla_query_posts_groupby_filter(string $groupby_clause) : string

Taxonomy text queries and postmeta queries can return multiple results for the same ID. Defined as public because it's a filter.

since 1.90

Parameters

$groupby_clause

string

query clause before modification

Returns

stringupdated query clause

Adds a JOIN clause, if required, to handle sorting/searching on custom fields or ALT Text

mla_query_posts_join_filter(string $join_clause) : string

Defined as public because it's a filter.

since 0.30

Parameters

$join_clause

string

query clause before modification

Returns

stringquery clause after "LEFT JOIN view ON post_id" item modification

Adds a ORDERBY clause, if required

mla_query_posts_orderby_filter(string $orderby_clause) : string

Expands the range of sort options because the logic in WP_Query is limited. Defined as public because it's a filter.

since 0.30

Parameters

$orderby_clause

string

query clause before modification

Returns

stringupdated query clause

Adds a keyword search to the WHERE clause, if required

mla_query_posts_search_filter(string $search_string, object $query_object) : string

Defined as public because it's a filter.

since 0.60

Parameters

$search_string

string

query clause before modification

$query_object

object

WP_Query object

Returns

stringquery clause after keyword search addition

Adds/modifies the WHERE clause for meta values, LIKE patterns and detached items

mla_query_posts_where_filter(string $where_clause) : string

Modeled after _edit_attachments_query_helper in wp-admin/post.php. Defined as public because it's a filter.

since 0.1

Parameters

$where_clause

string

query clause before modification

Returns

stringquery clause after modification

Disable Relevanssi - A Better Search, v3.2 by Mikko Saari Defined as public because it's a filter.

mla_query_relevanssi_admin_search_ok_filter(boolean $admin_search_ok) : boolean

since 1.80

Parameters

$admin_search_ok

boolean

Default setting

Returns

booleanUpdated setting

Disable Relevanssi - A Better Search, v3.2 by Mikko Saari Defined as public because it's a filter.

mla_query_relevanssi_prevent_default_request_filter(boolean $prevent) : boolean

since 2.25

Parameters

$prevent

boolean

Default setting

Returns

booleanUpdated setting

Filters all clauses for get_terms queries

mla_query_terms_clauses_filter(array $pieces, array $taxonomies, array $args) 

Defined as public because it's a filter.

since 2.13

Parameters

$pieces

array

Terms query SQL clauses.

$taxonomies

array

An array of taxonomies.

$args

array

An array of terms query arguments.

Replaces a WordPress function deprecated in v3.7

mla_search_terms_tidy(string $term) : string

Defined as public because it's a callback from array_map().

since 1.51

Parameters

$term

string

search term before modification

Returns

stringcleaned up search term

Add filters, run query, remove filters

_execute_list_table_query(array $request) : object

since 0.30

Parameters

$request

array

query parameters from web page, usually found in $_REQUEST

Returns

objectWP_Query object with query results

Isolates keyword match results to word boundaries

_match_quoted_phrase(string $needle, string $haystack) : boolean

Eliminates matches such as "man" in "woman".

since 2.11

Parameters

$needle

string

the quoted phrase (without enclosing quotes)

$haystack

string

the entire term

Returns

boolean$needle is a word match within $haystack

Sanitize and expand query arguments from request variables

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

Prepare the arguments for WP_Query. Modeled after wp_edit_attachments_query in wp-admin/post.php

since 0.1

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 WP_Query

Detects wildcard searches, i.e., containing an asterisk outside quotes

_wildcard_search_string(string $search_string) : boolean

Defined as public because it's a callback from array_map().

since 2.13

Parameters

$search_string

string

search string

Returns

booleantrue if wildcard

 Properties

 

Table column definitions

$default_columns : array

This array defines table columns and titles where the key is the column slug (and class) and the value is the column's title text. If you need a checkbox for bulk actions, use the special slug "cb".

The 'cb' column is treated differently than the rest. If including a checkbox column in your table you must create a column_cb() method. If you don't need bulk actions or checkboxes, simply leave the 'cb' entry out of your array.

All of the columns are added to this array by MLA_List_Table::mla_admin_init_action.

since 0.1
 

Default values for hidden columns

$default_hidden_columns : array

This array is used when the user-level option is not set, i.e., the user has not altered the selection of hidden columns.

The value on the right-hand side must match the column slug, e.g., array(0 => 'ID_parent, 1 => 'title_name').

Taxonomy and custom field columns are added to this array by MLA_List_Table::mla_admin_init_action.

since 0.1
 

Sortable column definitions

$default_sortable_columns : array

This array defines the table columns that can be sorted. The array key is the column slug that needs to be sortable, and the value is database column to sort by. Often, the key and value will be the same, but this is not always the case (as the value is a column name from the database, not the list table).

The array value also contains a boolean which is 'true' if the initial sort order for the column is DESC/Descending.

Taxonomy and custom field columns are added to this array by MLA_List_Table::mla_admin_init_action.

since 0.1
 

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 _prepare_list_table_query function, and any further logic required to translate those values is contained in the filters.

Array index values are: use_alt_text_view, use_postmeta_view, use_orderby_view, alt_text_value, postmeta_key, postmeta_value, patterns, detached, orderby, order, mla-metavalue, debug (also in search_parameters)

since 0.30
 

WP_Query 'posts_search' filter "parameters"

$search_parameters : array

This array defines parameters for the query's posts_search filter, which uses 'search_string' to add a clause to the query's WHERE clause. It is shared between the list_table-query functions here and the mla_get_shortcode_attachments function in class-mla-shortcodes.php. This array passes the relevant parameters to the filter.

Array index values are: ['mla_terms_search']['phrases'] ['mla_terms_search']['taxonomies'] ['mla_terms_search']['radio_phrases'] => AND/OR ['mla_terms_search']['radio_terms'] => AND/OR ['s'] => numeric for ID/parent search ['mla_search_fields'] => 'content', 'title', 'excerpt', 'alt-text', 'name', 'terms' Note: 'alt-text' is not supported in [mla_gallery] ['mla_search_connector'] => AND/OR ['sentence'] => entire string must match as one "keyword" ['exact'] => entire string must match entire field value ['debug'] => internal element, console/log/shortcode/none ['tax_terms_count'] => internal element, shared with JOIN and GROUP BY filters

since 2.00
 

WordPress version test for $wpdb->esc_like() Vs esc_sql()

$wp_4dot0_plus : boolean

since 2.13
 

Cache the results of mla_count_list_table_items for reuse in mla_query_list_table_items

$mla_list_table_items : array

since 1.40

 Constants

 

Provides a unique value for the ALT Text "Search Media" subquery

MLA_ALT_TEXT_SUBQUERY 

The subquery is used to filter the Media/Assistant submenu table by ALT Text with the Search Media text box.

since 0.40
 

Provides a unique suffix for the custom field "orderby" subquery

MLA_ORDERBY_SUBQUERY 

The subquery is used to sort the Media/Assistant submenu table on ALT Text and custom field columns.

since 2.15
 

Provides a unique suffix for the "Table View custom:" SQL View

MLA_TABLE_VIEW_SUBQUERY 

The SQL View is used to filter the Media/Assistant submenu table on custom field Table Views.

since 2.15