Class MLA (Media Library Assistant) Polylang provides support for the Polylang Multilingual plugin

package Media Library Assistant
since 2.11

 Methods

Load the plugin's Style Sheet and Javascript files

admin_enqueue_scripts(string $page_hook) : void

since 2.11

Parameters

$page_hook

string

Name of the page being loaded

Load the plugin's Ajax handler(s)

admin_init() : void

since 2.11

Captures "before update" term assignments from the Media/Edit Media screen

attachment_fields_to_save(\WP_Post $post, array $attachment) 

since 2.13

Parameters

$post

\WP_Post

The WP_Post object.

$attachment

array

An array of attachment metadata.

Filters taxonomy updates by language for Bulk Edit during Add New Media and the Media/Edit Media screen

edit_attachment(integer $post_id) 

since 2.11

Parameters

$post_id

integer

ID of the current post

Initialization function, similar to __construct()

initialize() : void

since 2.11

Adds the "Language" tab to the Settings/Media Library Assistant list

mla_get_options_tablist(array | false $results, array $mla_tablist, string | NULL $tab) : array

since 2.11

Parameters

$results

arrayfalse

The entire tablist ( $tab = NULL ), a single tab entry or false if not found/not allowed.

$mla_tablist

array

The entire default tablist

$tab

stringNULL

tab slug for single-element return or NULL to return entire tablist

Returns

arrayupdated tablist or single tab element

MLA Tag Cloud Query Clauses

mla_get_terms_clauses(array $clauses) : array

Adds language-specific clauses to filter the cloud terms.

since 2.11

Parameters

$clauses

array

SQL clauses ( 'fields', 'join', 'where', 'order', 'orderby', 'limits' )

Returns

arrayupdated SQL clauses

MLA Tag Cloud Query Arguments

mla_get_terms_query_arguments(array $all_query_parameters) : array

Saves [mla_tag_cloud] query parameters for use in MLA_Polylang::mla_get_terms_clauses.

since 2.11
uses \global\MLA_Polylang::$all_query_parameters

Parameters

$all_query_parameters

array

shortcode arguments merged with attachment selection defaults, so every possible parameter is present

Returns

arrayupdated attachment query arguments

Add styles for the pll_translations table column

mla_list_table_add_pll_styles() : void

since 2.11

Filter the data for inline (Quick and Bulk) editing

mla_list_table_build_inline_data(string $inline_data, object $item) : string

Adds item-specific translations data for the JS quick and bulk edit functions.

since 2.11

Parameters

$inline_data

string

The HTML markup for inline data.

$item

object

The current Media Library item.

Returns

stringupdated HTML markup for inline data.

Filter the list of item "Rollover" actions

mla_list_table_build_rollover_actions(array $actions, object $item, string $column) : array

Adds "Quick Translate" to the list of item-level "Rollover" actions.

since 2.11

Parameters

$actions

array

The list of item "Rollover" actions.

$item

object

The current Media Library item.

$column

string

The List Table column slug.

Returns

arrayupdated "Rollover" actions.

Process an MLA_List_Table bulk action

mla_list_table_bulk_action(array $item_content, string $bulk_action, integer $post_id) : object

Sets the new item language from the Language dropdown selection.

since 2.11

Parameters

$item_content

array

NULL, to indicate no handler.

$bulk_action

string

the requested action.

$post_id

integer

the affected attachment.

Returns

objectupdated $item_content. NULL if no handler, otherwise ( 'message' => error or status message(s), 'body' => '', 'prevent_default' => true to bypass the MLA handler )

Captures the Bulk Edit parameters during "Upload New Media"

mla_list_table_bulk_action_initial_request(array $request, string $bulk_action, array $custom_field_map) : array

since 2.11

Parameters

$request

array

bulk action request parameters, including ['mla_bulk_action_do_cleanup'].

$bulk_action

string

the requested action.

$custom_field_map

array

[ slug => field_name ]

Returns

arrayupdated bulk action request parameters

Converts Bulk Edit taxonomy inputs to language-specific values

mla_list_table_bulk_action_item_request(array $request, string $bulk_action, integer $post_id, array $custom_field_map) : array

since 2.11

Parameters

$request

array

bulk action request parameters, including ['mla_bulk_action_do_cleanup'].

$bulk_action

string

the requested action.

$post_id

integer

the affected attachment.

$custom_field_map

array

[ slug => field_name ]

Returns

arrayupdated bulk action request parameters

Supply a column value if no column-specific function has been defined

mla_list_table_column_default(string $content, array $item, array $column_name) : string

Fills in the Language columns with the item's translation status values.

since 2.11

Parameters

$content

string

NULL, indicating no default content

$item

array

A singular item (one full row's worth of data)

$column_name

array

The name/slug of the column to be processed

Returns

stringText or HTML to be placed inside the column

Process an MLA_List_Table custom bulk action

mla_list_table_custom_bulk_action(array $item_content, string $bulk_action, integer $post_id) : object

Creates new items from the "Bulk Translate" list.

since 2.11

Parameters

$item_content

array

NULL, to indicate no handler.

$bulk_action

string

the requested action.

$post_id

integer

the affected attachment.

Returns

objectupdated $item_content. NULL if no handler, otherwise ( 'message' => error or status message(s), 'body' => '' )

Filter the MLA_List_Table bulk actions

mla_list_table_get_bulk_actions(array $actions) : array

Adds the "Translate" action to the Bulk Actions list.

since 2.11

Parameters

$actions

array

An array of bulk actions. Format: 'slug' => 'Label'

Returns

arrayupdated array of actions.

Filter the MLA_List_Table columns

mla_list_table_get_columns(array $columns) : array

Inserts the language columns just after the item thumbnail column

since 2.11

Parameters

$columns

array

An array of columns. format: column_slug => Column Label

Returns

arrayupdated array of columns.

Captures the Quick Edit "before update" term assignments and process the Language dropdown selection, if changed

mla_list_table_inline_action(array $item_content, integer $post_id) : object

since 2.11

Parameters

$item_content

array

NULL, to indicate no handler.

$post_id

integer

the affected attachment.

Returns

objectupdated $item_content. NULL if no handler, otherwise ( 'message' => error or status message(s), 'body' => '', 'prevent_default' => true to bypass the MLA handler )

Define the fields for inline (Quick) editing

mla_list_table_inline_fields(array $fields) : string

Adds Language dropdown and Quick Translate links.

since 2.11

Parameters

$fields

array

The field names for inline data.

Returns

stringupdated fields for inline data.

MLA_List_Table inline edit parse

mla_list_table_inline_parse(string $html_markup, string $item_template, array $item_values) : array

since 2.11 Adds Bulk Translate form and the Language dropdown markup used for the Quick and Bulk Edit forms.

Parameters

$html_markup

string

HTML markup returned by the template parser

$item_template

string

template used to generate the HTML markup

$item_values

array

parameter_name => parameter_value pairs

Returns

arrayupdated HTML markup for the Quick and Bulk Edit forms

MLA_List_Table inline edit item values

mla_list_table_inline_values(array $item_values) : array

Builds the Language dropdown and edit translation links for the Quick and Bulk Edit forms.

since 2.11

Parameters

$item_values

array

parameter_name => parameter_value pairs

Returns

arrayupdated substitution parameter name => value pairs

Filter the pagination parameters for prepare_items()

mla_list_table_prepare_items_pagination(array $pagination, object $mla_list_table) : array

Records the pagination parameters for use with custom table views, e.g., "attached".

since 2.11

Parameters

$pagination

array

Contains 'per_page', 'current_page'.

$mla_list_table

object

The MLA_List_Table object, passed by reference.

Returns

arrayupdated pagination array.

Filter the total items count for prepare_items()

mla_list_table_prepare_items_total_items(integer $total_items, object $mla_list_table) : integer

A convenient place to add the query argument required for the "Bulk Translate" custom view.

since 2.11

Parameters

$total_items

integer

NULL, indicating no substitution.

$mla_list_table

object

The MLA_List_Table object, passed by reference.

Returns

integerupdated total_items.

Filter the "sticky" submenu URL parameters

mla_list_table_submenu_arguments(array $submenu_arguments, object $include_filters) : array

Adds a language ('lang') parameter to the URL parameters that will be retained when the submenu page refreshes. Maintains the list of Bulk Translate items in the URLs for paging through the results.

since 2.11

Parameters

$submenu_arguments

array

Current view, pagination and sort parameters.

$include_filters

object

True to include "filter-by" parameters, e.g., year/month dropdown.

Returns

arrayupdated submenu_arguments.

Localize $mla_language_option_definitions array

mla_localize_language_option_definitions() : void

Localization must be done at runtime, and these calls cannot be placed in the "public static" array definition itself.

since 2.11

Captures the existing term assignments before the Media Manager Modal Window ATTACHMENT DETAILS taxonomy meta boxes updates

mla_media_modal_begin_update_compat_fields(object $post) 

since 2.11

Parameters

$post

object

the current post

Applies Term Synchronization after the Media Manager Modal Window taxonomy updates

mla_media_modal_end_update_compat_fields(string $results, array $taxonomies, object $post) 

since 2.11

Parameters

$results

string

HTML markup for the taxonomy meta box elements

$taxonomies

array

supported taxonomy objects

$post

object

current post object

Applies Term Assignment to the terms assigned to one Media Manager Modal Window ATTACHMENT DETAILS taxonomy

mla_media_modal_update_compat_fields_terms(array $terms, string $key, object $value, integer $post_id) 

since 2.11

Parameters

$terms

array

assigned term id/name values

$key

string

taxonomy slug

$value

object

taxonomy object

$post_id

integer

current post ID

Renders the Settings/Media Library Assistant "Language" tab

mla_render_language_tab() : array

since 2.11

Returns

array( 'message' => '', 'body' => '' )

Copies taxonomy terms from the source item to the new translated item

pll_translate_media(integer $duplicated_attachment_id, object $duplicated_attachment_object, array $translations) 

since 2.11

Parameters

$duplicated_attachment_id

integer

ID of the new item

$duplicated_attachment_object

object

post object of the new item

$translations

array

an associative array of translations with language code as key and translation id as value

Ajax handler to Quick Translate a single attachment

quick_translate() : void

since 2.11

Adds a term and its translations to $relevant_terms

_add_relevant_term(object $term, object $translations) 

since 2.11
uses \global\MLA_Polylang::$relevant_terms

Parameters

$term

object

WordPress term object

$translations

object

Polylang translations object; optional

Compute Term Synchronization replacement $tax_inputs

_apply_synch_input(string $language) : array

Assumes the "current post" in $existing_terms is the source and $existing_terms contains the target translation

since 2.11
uses \global\MLA_Polylang::$existing_terms

Parameters

$language

string

the target translation code

Returns

array$tax_inputs for Term Synchronization

Filter the $tax_input array to a specific language

_apply_tax_input(integer $post_id, string $post_language) : array

since 2.11
uses \global\MLA_Polylang::$tax_input
uses \global\MLA_Polylang::$existing_terms

Parameters

$post_id

integer

ID of the post to be updated

$post_language

string

explicit language_code; optional

Returns

arraylanguage-specific $tax_inputs

Build the $existing_terms array

_build_existing_terms(integer $post_id) 

Takes each translatable taxonomy and builds an array of language-specific term_id to term_id/term_name mappings for terms already assigned to the item translation.

since 2.11
uses \global\MLA_Polylang::$existing_terms
uses \global\MLA_Polylang::$relevant_terms

Parameters

$post_id

integer

ID of the current post

Build the $tax_input array

_build_tax_input(integer $post_id, array $tax_inputs, array $tax_actions) 

Takes each term from the $tax_inputs parameter and builds an array of language-specific term_id to term_id/term_name mappings for all languages.

since 2.11
uses \global\MLA_Polylang::$tax_input
uses \global\MLA_Polylang::$existing_terms

Parameters

$post_id

integer

ID of the current post

$tax_inputs

array

'tax_input' request parameter

$tax_actions

array

'tax_action' request parameter

Finds a $relevant_term (if defined) given a key and (optional) a language

_get_relevant_term(string $field, mixed $value, string $taxonomy, string $language, boolean $test_only) 

since 2.11
uses \global\MLA_Polylang::$relevant_terms

Parameters

$field

string

to search in; 'id', 'name', or 'term_taxonomy_id'

$value

mixed

to search for; integer, string or integer

$taxonomy

string

to search in; slug

$language

string

code; string; optional

$test_only

boolean

false (default) to add missing term, true to leave term out

Find or create an item translation

_get_translation(integer $post_id, string $new_language) : integer

since 2.11

Parameters

$post_id

integer

item ID

$new_language

string

Slug of the desired language

Returns

integerID of the corresponding item in the desired language

Delete saved settings, restoring default values

_reset_language_settings() : array

since 2.11

Returns

arrayMessage(s) reflecting the results of the operation

Save Language settings to the options table

_save_language_settings() : array

since 2.11
uses \global\$_REQUEST

Returns

arrayMessage(s) reflecting the results of the operation

Update the $existing_terms array

_update_existing_terms(integer $post_id) : array

Takes each translatable taxonomy and rebuilds the array of language-specific term_id to term_id/term_name mappings for the "current translation" represented by the $post_id.

since 2.11
uses \global\MLA_Polylang::$existing_terms
uses \global\MLA_Polylang::$relevant_terms

Parameters

$post_id

integer

ID of the current post

Returns

array( taxonomy => term assignments ) before the update

 Properties

 

$mla_language_option_definitions defines the language-specific database options and admin page areas for setting/updating them

$mla_language_option_definitions 

The array must be populated at runtime in MLA_Polylang::mla_localize_language_option_definitions(), because localization calls cannot be placed in the "public static" array definition itself.

Each option is defined by an array with the elements documented in class-mla-options.php

 

Table language column definitions

$language_columns : array

since 2.11
 

Save the query arguments

$all_query_parameters : array

since 2.11
 

Items returned by custom bulk action(s)

$bulk_action_includes : array

since 2.11
 

Duplicates created during media upload

$duplicate_attachments : array

since 2.11
 

Taxonomy terms for the current item translation in the database

$existing_terms : array

since 2.11
 

Data selection parameters for custom views

$list_table_parameters : array

since 2.11
 

Taxonomy terms and translations

$relevant_terms : array

NOTE: WPML uses term_taxonomy_id as the "element_id" in its translations; Polylang uses term_id as the "element_id".

since 2.11
 

Replacement tax_input values in all languages

$tax_input : array

since 2.11
 

Bulk Edit parameters during "Upload New Media"

$upload_bulk_edit_args : array

since 2.11
 

Custom Field Map during "Upload New Media"

$upload_bulk_edit_map : array

since 2.11

 Constants

 

Uniquely identifies the Quick Translate action

MLA_PLL_QUICK_TRANSLATE : string

since 2.11