\MLA_Polylang

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

Summary

Methods
Properties
Constants
initialize()
mla_get_terms_query_arguments()
mla_get_terms_clauses()
admin_init()
quick_translate()
admin_enqueue_scripts()
pll_translate_media()
mla_get_shortcode_attachments_final_terms()
mla_begin_mapping()
mla_mapping_rule()
mla_mapping_new_text()
mla_end_mapping()
mla_updated_single_item()
attachment_fields_to_save()
edit_attachment()
mla_media_modal_terms_options()
mla_media_modal_begin_update_compat_fields()
mla_media_modal_update_compat_fields_terms()
mla_media_modal_end_update_compat_fields()
mla_list_table_inline_action()
mla_list_table_bulk_action_initial_request()
mla_list_table_bulk_action_item_request()
mla_list_table_bulk_action()
mla_list_table_custom_bulk_action()
mla_list_table_get_bulk_actions()
mla_list_table_inline_values()
mla_list_table_inline_parse()
mla_list_table_get_columns()
mla_list_table_add_pll_styles()
mla_list_table_column_default()
mla_list_table_submenu_arguments()
mla_list_table_prepare_items_pagination()
mla_list_table_prepare_items_total_items()
mla_list_table_build_rollover_actions()
mla_list_table_inline_fields()
mla_list_table_build_inline_data()
mla_taxonomy_get_columns()
mla_get_options_tablist()
mla_localize_language_option_definitions()
mla_render_language_tab()
$mla_language_option_definitions
MLA_PLL_QUICK_TRANSLATE
No protected methods found
$language_columns
N/A
_get_translation()
_add_relevant_term()
_get_relevant_term()
_build_existing_terms()
_update_existing_terms()
_build_tax_input()
_apply_tax_input()
_apply_synch_input()
_apply_term_synchronization()
_save_language_settings()
_reset_language_settings()
$polylang_1dot8_plus
$all_query_parameters
$duplicate_attachments
$current_mapping_rule
$relevant_terms
$existing_terms
$tax_input
$bulk_edit_map
$bulk_edit_request
$bulk_action_includes
$list_table_parameters
N/A

Constants

MLA_PLL_QUICK_TRANSLATE

MLA_PLL_QUICK_TRANSLATE

Uniquely identifies the Quick Translate action

Properties

$mla_language_option_definitions

$mla_language_option_definitions : 

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

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

$language_columns

$language_columns : array

Table language column definitions

Type

array

$polylang_1dot8_plus

$polylang_1dot8_plus : boolean

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

Type

boolean

$all_query_parameters

$all_query_parameters : array

Save the query arguments

Type

array

$duplicate_attachments

$duplicate_attachments : array

Duplicates created during media upload

Type

array — [ $post_id ] => $language;

$current_mapping_rule

$current_mapping_rule : array

Current mapping rule for term creation

Type

array — mapping rule

$relevant_terms

$relevant_terms : array

Taxonomy terms and translations

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

Type

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

$existing_terms

$existing_terms : array

Taxonomy terms for the current item translation in the database

Type

array — ['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

$tax_input

$tax_input : array

Replacement tax_input values in all languages

Type

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

$bulk_edit_map

$bulk_edit_map : array

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

Type

array — [ id ] => field name

$bulk_edit_request

$bulk_edit_request : array

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

Type

array — [ field ] => new value

$bulk_action_includes

$bulk_action_includes : array

Items returned by custom bulk action(s)

Type

array

$list_table_parameters

$list_table_parameters : array

Data selection parameters for custom views

Type

array

Methods

initialize()

initialize() : void

Initialization function, similar to __construct()

mla_get_terms_query_arguments()

mla_get_terms_query_arguments(  $all_query_parameters) : array

MLA Tag Cloud Query Arguments

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

Parameters

$all_query_parameters

Returns

array —

updated attachment query arguments

mla_get_terms_clauses()

mla_get_terms_clauses(  $clauses) : array

MLA Tag Cloud Query Clauses

Adds language-specific clauses to filter the cloud terms.

Parameters

$clauses

Returns

array —

updated SQL clauses

admin_init()

admin_init() : void

Load the plugin's Ajax handler(s)

quick_translate()

quick_translate() : void

Ajax handler to Quick Translate a single attachment

admin_enqueue_scripts()

admin_enqueue_scripts(  $page_hook) : void

Load the plugin's Style Sheet and Javascript files

Parameters

$page_hook

pll_translate_media()

pll_translate_media(  $duplicated_attachment_id,   $duplicated_attachment_object,   $translations) 

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

Parameters

$duplicated_attachment_id
$duplicated_attachment_object
$translations

mla_get_shortcode_attachments_final_terms()

mla_get_shortcode_attachments_final_terms(  $arguments,   $return_found_rows) 

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

Parameters

$arguments
$return_found_rows

mla_begin_mapping()

mla_begin_mapping(  $source,   $post_id = NULL) 

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

Parameters

$source
$post_id

mla_mapping_rule()

mla_mapping_rule(  $setting_value,   $post_id,   $category,   $attachment_metadata) 

Saves the current mapping rule for term creation

Parameters

$setting_value
$post_id
$category
$attachment_metadata

mla_mapping_new_text()

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

Manages the creation of new taxonomy terms from metadata values

Parameters

$new_text
$setting_key
$post_id
$category
$attachment_metadata

Returns

array —

updated rule EXIF/Template value

mla_end_mapping()

mla_end_mapping() : void

Remove "All languages" filter

mla_updated_single_item()

mla_updated_single_item(integer  $post_id, integer  $result) 

Applies Term Synchronization after item updates

Parameters

integer $post_id

ID of the item that was updated.

integer $result

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

attachment_fields_to_save()

attachment_fields_to_save(\WP_Post  $post, array  $attachment) 

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

Parameters

\WP_Post $post

The WP_Post object.

array $attachment

An array of attachment metadata.

edit_attachment()

edit_attachment(  $post_id) 

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

Parameters

$post_id

mla_media_modal_terms_options()

mla_media_modal_terms_options(  $term_values) 

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

Parameters

$term_values

mla_media_modal_begin_update_compat_fields()

mla_media_modal_begin_update_compat_fields(  $post) 

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

Parameters

$post

mla_media_modal_update_compat_fields_terms()

mla_media_modal_update_compat_fields_terms(  $terms,   $key,   $value,   $post_id) 

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

Parameters

$terms
$key
$value
$post_id

mla_media_modal_end_update_compat_fields()

mla_media_modal_end_update_compat_fields(  $results,   $taxonomies,   $post) 

Applies Term Synchronization after the Media Manager Modal Window taxonomy updates

Parameters

$results
$taxonomies
$post

mla_list_table_inline_action()

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

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

Parameters

array $item_content

NULL, to indicate no handler.

integer $post_id

the affected attachment.

Returns

object —

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

mla_list_table_bulk_action_initial_request()

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

Captures the Bulk Edit, "Upload New Media" parameters

Parameters

array $request

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

string $bulk_action

the requested action.

array $custom_field_map

[ slug => field_name ]

Returns

array —

updated bulk action request parameters

mla_list_table_bulk_action_item_request()

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

Converts Bulk Edit taxonomy inputs to language-specific values

Parameters

array $request

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

string $bulk_action

the requested action.

integer $post_id

the affected attachment.

array $custom_field_map

[ slug => field_name ]

Returns

array —

updated bulk action request parameters

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.

Parameters

array $item_content

NULL, to indicate no handler.

string $bulk_action

the requested action.

integer $post_id

the affected attachment.

Returns

object —

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

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.

Parameters

array $item_content

NULL, to indicate no handler.

string $bulk_action

the requested action.

integer $post_id

the affected attachment.

Returns

object —

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

mla_list_table_get_bulk_actions()

mla_list_table_get_bulk_actions(array  $actions) : array

Filter the MLA_List_Table bulk actions

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

Parameters

array $actions

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

Returns

array —

updated array of actions.

mla_list_table_inline_values()

mla_list_table_inline_values(array  $item_values) : array

MLA_List_Table inline edit item values

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.

Parameters

array $item_values

parameter_name => parameter_value pairs

Returns

array —

updated substitution parameter name => value pairs

mla_list_table_inline_parse()

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

MLA_List_Table inline edit parse

Parameters

$html_markup
$item_template
$item_values

Returns

array —

updated HTML markup for the Quick and Bulk Edit forms

mla_list_table_get_columns()

mla_list_table_get_columns(array  $columns) : array

Filter the MLA_List_Table columns

Inserts the language columns just after the item thumbnail column

Parameters

array $columns

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

Returns

array —

updated array of columns.

mla_list_table_add_pll_styles()

mla_list_table_add_pll_styles() : void

Add styles for the pll_translations table column

mla_list_table_column_default()

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

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

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

Parameters

$content
$item
$column_name

Returns

string —

Text or HTML to be placed inside the column

mla_list_table_submenu_arguments()

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

Filter the "sticky" submenu URL parameters

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.

Parameters

array $submenu_arguments

Current view, pagination and sort parameters.

object $include_filters

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

Returns

array —

updated submenu_arguments.

mla_list_table_prepare_items_pagination()

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

Filter the pagination parameters for prepare_items()

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

Parameters

array $pagination

Contains 'per_page', 'current_page'.

object $mla_list_table

The MLA_List_Table object, passed by reference.

Returns

array —

updated pagination array.

mla_list_table_prepare_items_total_items()

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

Filter the total items count for prepare_items()

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

Parameters

integer $total_items

NULL, indicating no substitution.

object $mla_list_table

The MLA_List_Table object, passed by reference.

Returns

integer —

updated total_items.

mla_list_table_build_rollover_actions()

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

Filter the list of item "Rollover" actions

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

Parameters

array $actions

The list of item "Rollover" actions.

object $item

The current Media Library item.

string $column

The List Table column slug.

Returns

array —

updated "Rollover" actions.

mla_list_table_inline_fields()

mla_list_table_inline_fields(array  $fields) : string

Define the fields for inline (Quick) editing

Adds Language dropdown and Quick Translate links.

Parameters

array $fields

The field names for inline data.

Returns

string —

updated fields for inline data.

mla_list_table_build_inline_data()

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

Filter the data for inline (Quick and Bulk) editing

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

Parameters

string $inline_data

The HTML markup for inline data.

object $item

The current Media Library item.

Returns

string —

updated HTML markup for inline data.

mla_taxonomy_get_columns()

mla_taxonomy_get_columns(  $filter_columns,   $columns,   $taxonomy) : array

Not used in this version of the plugin

Parameters

$filter_columns
$columns
$taxonomy

Returns

array —

NULL or replacement columns array.

mla_get_options_tablist()

mla_get_options_tablist(  $results,   $mla_tablist,   $tab) : array

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

Parameters

$results
$mla_tablist
$tab

Returns

array —

updated tablist or single tab element

mla_localize_language_option_definitions()

mla_localize_language_option_definitions() : void

Localize $mla_language_option_definitions array

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

mla_render_language_tab()

mla_render_language_tab() : array

Renders the Settings/Media Library Assistant "Language" tab

Returns

array —

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

_get_translation()

_get_translation(  $post_id,   $new_language) : integer

Find or create an item translation

Parameters

$post_id
$new_language

Returns

integer —

ID of the corresponding item in the desired language

_add_relevant_term()

_add_relevant_term(  $term,   $translations = NULL) 

Adds a term and its translations to $relevant_terms

Parameters

$term
$translations

_get_relevant_term()

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

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

Parameters

string $field

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

mixed $value

to search for; integer, string or integer

string $taxonomy

to search in; slug

string $language

code; string; optional

boolean $test_only

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

_build_existing_terms()

_build_existing_terms(integer  $post_id) 

Build the $existing_terms array

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.

Parameters

integer $post_id

ID of the current post

_update_existing_terms()

_update_existing_terms(integer  $post_id) : array

Update the $existing_terms 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.

Parameters

integer $post_id

ID of the current post

Returns

array —

( taxonomy => term assignments ) before the update

_build_tax_input()

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

Build the $tax_input array

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.

Parameters

integer $post_id

ID of the current post

array $tax_inputs

'tax_input' request parameter

array $tax_actions

'tax_action' request parameter

_apply_tax_input()

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

Filter the $tax_input array to a specific language

Parameters

integer $post_id

ID of the post to be updated

string $post_language

explicit language_code; optional

Returns

array —

language-specific $tax_inputs

_apply_synch_input()

_apply_synch_input(string  $language) : array

Compute Term Synchronization replacement $tax_inputs

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

Parameters

string $language

the target translation code

Returns

array —

$tax_inputs for Term Synchronization

_apply_term_synchronization()

_apply_term_synchronization(integer  $post_id) : array

Apply Term Synchronization

Parameters

integer $post_id

the item we're synchronizing to

Returns

array —

$tax_inputs for Term Synchronization

_save_language_settings()

_save_language_settings() : array

Save Language settings to the options table

Returns

array —

Message(s) reflecting the results of the operation

_reset_language_settings()

_reset_language_settings() : array

Delete saved settings, restoring default values

Returns

array —

Message(s) reflecting the results of the operation