MLA_Polylang

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

package

Media Library Assistant

since 2.11

Methods

Adds a term and/or its translations to $relevant_terms

_add_relevant_term( $term,  $translations = NULL) 
static
since 2.11
uses

Arguments

$term

$translations

Compute Term Synchronization replacement $tax_inputs

_apply_synch_input(string $language) : array
static

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

since 2.11
uses

Arguments

$language

string

the target translation code

Response

array

$tax_inputs for Term Synchronization

Filter the $tax_input array to a specific language

_apply_tax_input(integer $post_id, string $post_language = NULL) : array
static
since 2.11
uses

Arguments

$post_id

integer

ID of the post to be updated

$post_language

string

explicit language_code; optional

Response

array

language-specific $tax_inputs

Apply Term Synchronization

_apply_term_synchronization(integer $post_id) : array
static
since 2.15
uses

Arguments

$post_id

integer

the item we're synchronizing to

Response

array

$tax_inputs for Term Synchronization

Build the $existing_terms array

_build_existing_terms(integer $post_id) 
static

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

Arguments

$post_id

integer

ID of the current post

Build the $tax_input array

_build_tax_input(integer $post_id, array $tax_inputs = NULL, array $tax_actions = NULL, boolean $add_new_names = false) 
static

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

Arguments

$post_id

integer

ID of the current post

$tax_inputs

array

'tax_input' request parameter

$tax_actions

array

'tax_action' request parameter

$add_new_names

boolean

Add term and translations for new names

Creates a $relevant_term given a name, taxonomy and language

_create_relevant_term(string $name, string $taxonomy, string $language) 
static
since 2.40

Arguments

$name

string

new term name

$taxonomy

string

slug

$language

string

code/slug

Creates a translation given a $relevant_term and language

_create_relevant_translation(string $relevant_term, string $language) 
static
since 2.40

Arguments

$relevant_term

string

current term

$language

string

code/slug

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

_get_relevant_term(string $field, mixed $value, string $taxonomy, string $language = NULL, boolean $test_only = false) 
static
since 2.11
uses

Arguments

$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( $post_id,  $new_language) : integer
static
since 2.11

Arguments

$post_id

$new_language

Response

integer

ID of the corresponding item in the desired language

Delete saved settings, restoring default values

_reset_language_settings() : array
static
since 2.11

Response

array

Message(s) reflecting the results of the operation

Save Language settings to the options table

_save_language_settings() : array
static
since 2.11
uses

Response

array

Message(s) reflecting the results of the operation

Update the $existing_terms array

_update_existing_terms(integer $post_id) : array
static

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

Arguments

$post_id

integer

ID of the current post

Response

array

( taxonomy => term assignments ) before the update

Load the plugin's Style Sheet and Javascript files

admin_enqueue_scripts( $page_hook) : void
static
since 2.11

Arguments

$page_hook

Load the plugin's Ajax handler(s)

admin_init() : void
static
since 2.11

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

attachment_fields_to_save(\WP_Post $post, array $attachment) 
static
since 2.13

Arguments

$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( $post_id) 
static
since 2.11

Arguments

$post_id

Initialization function, similar to __construct()

initialize() : void
static
since 2.11

Force "All languages" mode for IPTC/EXIF mapping, which uses mla_get_shortcode_attachments

mla_begin_mapping( $source,  $post_id = NULL) 
static
since 2.20

Arguments

$source

$post_id

Remove "All languages" filter

mla_end_mapping() : void
static
since 2.20

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

mla_get_options_tablist( $results,  $mla_tablist,  $tab) : array
static
since 2.11

Arguments

$results

$mla_tablist

$tab

Response

array

updated tablist or single tab element

Force "All languages" mode for IPTC/EXIF mapping, which uses mla_get_shortcode_attachments

mla_get_shortcode_attachments_final_terms( $arguments,  $return_found_rows) 
static
since 2.20

Arguments

$arguments

$return_found_rows

Add styles for the pll_translations table column

mla_list_table_add_pll_styles() : void
static
since 2.11

Filter the data for inline (Quick and Bulk) editing

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

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

since 2.11

Arguments

$inline_data

string

The HTML markup for inline data.

$item

object

The current Media Library item.

Response

string

updated 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
static

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

since 2.11

Arguments

$actions

array

The list of item "Rollover" actions.

$item

object

The current Media Library item.

$column

string

The List Table column slug.

Response

array

updated "Rollover" actions.

Sets the new item language from the Language dropdown selection.

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

Arguments

$item_content

array

NULL, to indicate no handler.

$bulk_action

string

the requested action.

$post_id

integer

the affected attachment.

Response

object

updated $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, "Upload New Media" parameters

mla_list_table_bulk_action_initial_request(array $request, string $bulk_action, array $custom_field_map) : array
static
since 2.11

Arguments

$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 ]

Response

array

updated 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
static
since 2.11

Arguments

$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 ]

Response

array

updated bulk action request parameters

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

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

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

since 2.11

Arguments

$content

$item

$column_name

Response

string

Text or HTML to be placed inside the column

Creates new items from the "Bulk Translate" list.

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

Arguments

$item_content

array

NULL, to indicate no handler.

$bulk_action

string

the requested action.

$post_id

integer

the affected attachment.

Response

object

updated $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
static

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

since 2.11

Arguments

$actions

array

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

Response

array

updated array of actions.

Filter the MLA_List_Table columns

mla_list_table_get_columns(array $columns) : array
static

Inserts the language columns just after the item thumbnail column

since 2.11

Arguments

$columns

array

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

Response

array

updated 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
static
since 2.11

Arguments

$item_content

array

NULL, to indicate no handler.

$post_id

integer

the affected attachment.

Response

object

updated $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
static

Adds Language dropdown and Quick Translate links.

since 2.11

Arguments

$fields

array

The field names for inline data.

Response

string

updated fields for inline data.

MLA_List_Table inline edit parse

mla_list_table_inline_parse( $html_markup,  $item_template,  $item_values) : array
static
since 2.11

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

Arguments

$html_markup

$item_template

$item_values

Response

array

updated 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
static

Builds the Language dropdown and edit translation links for the Quick and Bulk Edit forms, adding them to the 'custom_fields' and 'bulk_custom_fields' substitution parameters.

since 2.11

Arguments

$item_values

array

parameter_name => parameter_value pairs

Response

array

updated 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
static

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

since 2.11

Arguments

$pagination

array

Contains 'per_page', 'current_page'.

$mla_list_table

object

The MLA_List_Table object, passed by reference.

Response

array

updated 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
static

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

since 2.11

Arguments

$total_items

integer

NULL, indicating no substitution.

$mla_list_table

object

The MLA_List_Table object, passed by reference.

Response

integer

updated total_items.

Filter the "sticky" submenu URL parameters

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

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

Arguments

$submenu_arguments

array

Current view, pagination and sort parameters.

$include_filters

object

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

Response

array

updated submenu_arguments.

Localize $mla_language_option_definitions array

mla_localize_language_option_definitions() : void
static

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

since 2.11

Manages the creation of new taxonomy terms from metadata values

mla_mapping_new_text( $new_text,  $setting_key,  $post_id,  $category,  $attachment_metadata) : array
static
since 2.20

Arguments

$new_text

$setting_key

$post_id

$category

$attachment_metadata

Response

array

updated rule EXIF/Template value

Saves the current mapping rule for term creation

mla_mapping_rule( $setting_value,  $post_id,  $category,  $attachment_metadata) 
static
since 2.20

Arguments

$setting_value

$post_id

$category

$attachment_metadata

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

mla_media_modal_begin_update_compat_fields( $post) 
static
since 2.11

Arguments

$post

Applies Term Synchronization after the Media Manager Modal Window taxonomy updates

mla_media_modal_end_update_compat_fields( $results,  $taxonomies,  $post) 
static
since 2.11

Arguments

$results

$taxonomies

$post

Return terms in all languages when "Activate languages and translations for media" is disabled

mla_media_modal_terms_options( $term_values) 
static
since 2.22

Arguments

$term_values

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

mla_media_modal_update_compat_fields_terms( $terms,  $key,  $value,  $post_id) 
static
since 2.11

Arguments

$terms

$key

$value

$post_id

Renders the Settings/Media Library Assistant "Language" tab

mla_render_language_tab() : array
static
since 2.11

Response

array

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

Not used in this version of the plugin

mla_taxonomy_get_columns( $filter_columns,  $columns,  $taxonomy) : array
static
since 2.15

Arguments

$filter_columns

$columns

$taxonomy

Response

array

NULL or replacement columns array.

Applies Term Synchronization after item updates

mla_updated_single_item(integer $post_id, integer $result) 
static
since 2.15

Arguments

$post_id

integer

ID of the item that was updated.

$result

integer

Zero if the update failed else ID of the item that was updated.

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

pll_translate_media( $duplicated_attachment_id,  $duplicated_attachment_object,  $translations) 
static
since 2.11

Arguments

$duplicated_attachment_id

$duplicated_attachment_object

$translations

Ajax handler to Quick Translate a single attachment

quick_translate() : void
static
since 2.11

Constants

Uniquely identifies the Quick Translate action

MLA_PLL_QUICK_TRANSLATE
since
var

Properties

Polylang version conditional to avoid deprecated functions in v1.8+

polylang_1dot8_plus : boolean
static
since
var

Type(s)

boolean

Duplicates created during media upload

duplicate_attachments : array
static
since
var

[ $post_id ] => $language;

Type(s)

array

Current mapping rule for term creation

current_mapping_rule : array
static
since
var

mapping rule

Type(s)

array

Taxonomy terms and translations

relevant_terms : array
static

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

since
var

[ $term_taxonomy_id ] => array( $term, $translations )

Type(s)

array

Taxonomy terms for the current item translation in the database

existing_terms : array
static
since
var

['element_id'] => $post_id; [ 'language_code' ] => WPML item language or default language, e.g., 'en' [ 'slug' ] => Polylang item language or default language, e.g., 'en' [ $language ][ translation_details ] [ $language ][ $taxonomy ][ $term_taxonomy_id ] => $term

Type(s)

array

Replacement tax_input values in all languages

tax_input : array
static
since
var

['tax_input_post_id'] => $post_id; [ $language ][ $taxonomy ] => array of integer term_ids (hierarchical) [ $language ][ $taxonomy ] => comma-delimited string of term names (flat)

Type(s)

array

Custom Field Map during Bulk Edit, "Upload New Media"

bulk_edit_map : array
static
since
var

[ id ] => field name

Type(s)

array

Bulk Edit parameters during Bulk Edit, "Upload New Media"

bulk_edit_request : array
static
since
var

[ field ] => new value

Type(s)

array

Items returned by custom bulk action(s)

bulk_action_includes : array
static
since
var

Type(s)

array

Table language column definitions

language_columns : array
static
since
var

Type(s)

array

Data selection parameters for custom views

list_table_parameters : array
static
since
var

Type(s)

array

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

mla_language_option_definitions : 
static

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

Type(s)