first commit
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @var SitePress $sitepress
|
||||
* @var wpdb $wpdb
|
||||
*/
|
||||
|
||||
global $sitepress, $wpdb;
|
||||
|
||||
$sitepress->noscript_notice();
|
||||
|
||||
$element_id = isset( $term->term_taxonomy_id ) ? $term->term_taxonomy_id : false;
|
||||
|
||||
$element_type = isset( $_GET['taxonomy'] ) ? esc_sql( $_GET['taxonomy'] ) : 'post_tag';
|
||||
$icl_element_type = 'tax_' . $element_type;
|
||||
|
||||
$default_language = $sitepress->get_default_language();
|
||||
$current_language = $sitepress->get_current_language();
|
||||
|
||||
if ( $element_id ) {
|
||||
$res_prepared = $wpdb->prepare(
|
||||
"SELECT trid, language_code, source_language_code
|
||||
FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type=%s",
|
||||
array( $element_id, $icl_element_type )
|
||||
);
|
||||
/** @var \stdClass $res */
|
||||
$res = $wpdb->get_row( $res_prepared );
|
||||
$trid = $res->trid;
|
||||
if ( $trid ) {
|
||||
$element_lang_code = $res->language_code;
|
||||
} else {
|
||||
$element_lang_code = $current_language;
|
||||
|
||||
$translation_id = $sitepress->set_element_language_details( $element_id, $icl_element_type, null, $element_lang_code );
|
||||
// get trid of $translation_id
|
||||
$trid = $wpdb->get_var( $wpdb->prepare( "SELECT trid FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", array( $translation_id ) ) );
|
||||
}
|
||||
} else {
|
||||
$trid = isset( $_GET['trid'] ) ? (int) $_GET['trid'] : false;
|
||||
|
||||
$element_lang_code = $current_language;
|
||||
if ( array_key_exists( 'lang', $_GET ) ) {
|
||||
$element_lang_code = filter_var( $_GET['lang'], FILTER_SANITIZE_FULL_SPECIAL_CHARS );
|
||||
}
|
||||
}
|
||||
|
||||
$translations = false;
|
||||
if ( $trid ) {
|
||||
$translations = $sitepress->get_element_translations( $trid, $icl_element_type );
|
||||
}
|
||||
$terms_translations = empty( $translations ) ? array() : $translations;
|
||||
|
||||
$active_languages = $sitepress->get_active_languages();
|
||||
$selected_language = $element_lang_code ? $element_lang_code : $default_language;
|
||||
$source_language = isset( $_GET['source_lang'] ) ? strip_tags( filter_input( INPUT_GET, 'source_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) : false;
|
||||
$untranslated_ids = $sitepress->get_elements_without_translations( $icl_element_type, $selected_language, $default_language );
|
||||
|
||||
$dropdown = new WPML_Taxonomy_Element_Language_Dropdown();
|
||||
$dropdown->add_language_selector_to_page(
|
||||
$active_languages,
|
||||
$selected_language,
|
||||
$terms_translations,
|
||||
$element_id,
|
||||
$icl_element_type
|
||||
);
|
||||
|
||||
$setup_complete = $sitepress->get_setting( 'setup_complete' );
|
||||
|
||||
if ( $setup_complete ) {
|
||||
require WPML_PLUGIN_PATH . '/menu/wpml-translation-selector.class.php';
|
||||
$selector = new WPML_Translation_Selector( $sitepress, $default_language, $source_language, $element_id );
|
||||
$selector->add_translation_of_selector_to_page(
|
||||
$trid,
|
||||
$sitepress->get_current_language(),
|
||||
$selected_language,
|
||||
$untranslated_ids
|
||||
);
|
||||
|
||||
$sitepress->add_translate_options( $trid, $active_languages, $selected_language, $terms_translations, $icl_element_type );
|
||||
|
||||
echo '</div></div></div></div></div>';
|
||||
|
||||
if ( $trid && $sitepress->get_wp_api()->is_term_edit_page() ) {
|
||||
/**
|
||||
* Extends the translation options for terms
|
||||
*
|
||||
* Called after rendering the translation options for terms, after the closing the main container tag
|
||||
*
|
||||
* @since 3.8.2
|
||||
*
|
||||
* @param array $args {
|
||||
* Information about the current term and its translations
|
||||
*
|
||||
* @type int $trid The translation cluster ID.
|
||||
* @type array $active_languages All active languages data.
|
||||
* @type string $selected_language The language of the current term being edited.
|
||||
* @type array $translations All the available translations (including the current one).
|
||||
* @type string $type The translation element type (e.g. `tax_category`, `tax_{taxonomy}`.
|
||||
* }
|
||||
*/
|
||||
do_action(
|
||||
'wpml_translate_options_terms_after',
|
||||
array(
|
||||
'trid' => $trid,
|
||||
'active_languages' => $active_languages,
|
||||
'selected_language' => $selected_language,
|
||||
'translations' => $terms_translations,
|
||||
'type' => $icl_element_type,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
|
||||
new WPML_Taxonomy_Translation_Sync_Display();
|
||||
|
||||
class WPML_Taxonomy_Translation_Table_Display {
|
||||
|
||||
private static function get_strings_translation_array() {
|
||||
$st_plugin = '<a href="' . get_admin_url( null, 'plugins.php' ) . '" target="_blank" class="wpml-external-link">WPML String Translation</a>';
|
||||
|
||||
$term_results_cap = defined( 'WPML_TAXONOMY_TRANSLATION_MAX_TERMS_RESULTS_SET' ) ?
|
||||
WPML_TAXONOMY_TRANSLATION_MAX_TERMS_RESULTS_SET :
|
||||
WPML_Taxonomy_Translation_Screen_Data::WPML_TAXONOMY_TRANSLATION_MAX_TERMS_RESULTS_SET;
|
||||
|
||||
$labels = array(
|
||||
'Show' => __( 'Show', 'sitepress' ),
|
||||
'untranslated' => __( 'untranslated', 'sitepress' ),
|
||||
'all' => __( 'all', 'sitepress' ),
|
||||
'in' => __( 'in', 'sitepress' ),
|
||||
'to' => __( 'to', 'sitepress' ),
|
||||
'of' => __( 'of', 'sitepress' ),
|
||||
'taxonomy' => __( 'Taxonomy', 'sitepress' ),
|
||||
'anyLang' => __( 'any language', 'sitepress' ),
|
||||
'apply' => __( 'Refresh', 'sitepress' ),
|
||||
'synchronizeBtn' => __( 'Update Taxonomy Hierarchy', 'sitepress' ),
|
||||
'searchPlaceHolder' => __( 'Search', 'sitepress' ),
|
||||
'selectParent' => __( 'select parent', 'sitepress' ),
|
||||
'taxToTranslate' => __( 'Select the taxonomy to translate: ', 'sitepress' ),
|
||||
'translate' => sprintf( __( '%1$s Translation', 'sitepress' ), '%taxonomy%' ),
|
||||
'Synchronize' => __( 'Hierarchy Synchronization', 'sitepress' ),
|
||||
'lowercaseTranslate' => __( 'translate', 'sitepress' ),
|
||||
'copyToAllLanguages' => __( 'Copy to all languages', 'sitepress' ),
|
||||
'copyToAllMessage' => sprintf( __( 'Copy this term from original: %1$s to all other languages?' ), '%language%' ),
|
||||
'copyAllOverwrite' => __( 'Overwrite existing translations', 'sitepress' ),
|
||||
'willBeRemoved' => __( 'Will be removed', 'sitepress' ),
|
||||
'willBeAdded' => __( 'Will be added', 'sitepress' ),
|
||||
'legend' => __( 'Legend:', 'sitepress' ),
|
||||
'refLang' => sprintf( __( 'Synchronize taxonomy hierarchy according to: %1$s language.', 'sitepress' ), '%language%' ),
|
||||
'targetLang' => __( 'Target Language', 'sitepress' ),
|
||||
'termPopupDialogTitle' => __( 'Term translation', 'sitepress' ),
|
||||
'originalTermPopupDialogTitle' => __( 'Original term', 'sitepress' ),
|
||||
'labelPopupDialogTitle' => __( 'Label translation', 'sitepress' ),
|
||||
'copyFromOriginal' => __( 'Copy from original', 'sitepress' ),
|
||||
'original' => __( 'Original:', 'sitepress' ),
|
||||
'translationTo' => __( 'Translation to:', 'sitepress' ),
|
||||
'Name' => __( 'Name', 'sitepress' ),
|
||||
'Slug' => __( 'Slug', 'sitepress' ),
|
||||
'Description' => __( 'Description', 'sitepress' ),
|
||||
'Ok' => __( 'OK', 'sitepress' ),
|
||||
'save' => __( 'Save', 'sitepress' ),
|
||||
'Singular' => __( 'Singular', 'sitepress' ),
|
||||
'Plural' => __( 'Plural', 'sitepress' ),
|
||||
'changeLanguage' => __( 'Change language', 'sitepress' ),
|
||||
'cancel' => __( 'Cancel', 'sitepress' ),
|
||||
'loading' => __( 'loading', 'sitepress' ),
|
||||
'Save' => __( 'Save', 'sitepress' ),
|
||||
'currentPage' => __( 'Current page', 'sitepress' ),
|
||||
'goToPreviousPage' => __( 'Go to previous page', 'sitepress' ),
|
||||
'goToNextPage' => __( 'Go to the next page', 'sitepress' ),
|
||||
'goToFirstPage' => __( 'Go to the first page', 'sitepress' ),
|
||||
'goToLastPage' => __( 'Go to the last page', 'sitepress' ),
|
||||
'hieraSynced' => __( 'The taxonomy hierarchy is now synchronized.', 'sitepress' ),
|
||||
'hieraAlreadySynced' => __( 'The taxonomy hierarchy is already synchronized.', 'sitepress' ),
|
||||
'noTermsFound' => sprintf( __( 'No %1$s found.', 'sitepress' ), '%taxonomy%' ),
|
||||
'items' => __( 'items', 'sitepress' ),
|
||||
'item' => __( 'item', 'sitepress' ),
|
||||
'summaryTerms' => sprintf( __( 'Translation of %1$s', 'sitepress' ), '%taxonomy%' ),
|
||||
'summaryLabels' => sprintf( __( 'Translations of taxonomy %1$s labels and slug', 'sitepress' ), '%taxonomy%' ),
|
||||
'activateStringTranslation' => sprintf( __( 'To translate taxonomy labels and slug you need %s plugin.', 'sitepress' ), $st_plugin ),
|
||||
'preparingTermsData' => __( 'Loading ...', 'sitepress' ),
|
||||
'firstColumnHeading' => sprintf( __( '%1$s terms (in original language)', 'sitepress' ), '%taxonomy%' ),
|
||||
'resultsTruncated' => sprintf( __( 'Because too many %1$s were found, only the first %2$s results are listed. You can refine the results using the Search field below.', 'sitepress' ), '%taxonomy%', '<strong>' . $term_results_cap . '</strong>' ),
|
||||
'wpml_save_term_nonce' => wp_create_nonce( 'wpml_save_term_nonce' ),
|
||||
'wpml_tt_sync_hierarchy_nonce' => wp_create_nonce( 'wpml_tt_sync_hierarchy_nonce' ),
|
||||
'wpml_generate_unique_slug_nonce' => wp_create_nonce( 'wpml_generate_unique_slug_nonce' ),
|
||||
'wpml_taxonomy_translation_nonce' => wp_create_nonce( 'wpml_taxonomy_translation_nonce' ),
|
||||
|
||||
'addTranslation' => __( 'Add translation', 'sitepress' ),
|
||||
'editTranslation' => __( 'Edit translation', 'sitepress' ),
|
||||
'originalLanguage' => __( 'Original language', 'sitepress' ),
|
||||
'termMetaLabel' => __( 'This term has additional meta fields:', 'sitepress' ),
|
||||
);
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
public static function enqueue_taxonomy_table_resources( $sitepress ) {
|
||||
|
||||
WPML_Simple_Language_Selector::enqueue_scripts();
|
||||
|
||||
wp_enqueue_style( 'translate-taxonomy', ICL_PLUGIN_URL . '/res/css/taxonomy-translation.css', array(), ICL_SITEPRESS_VERSION );
|
||||
|
||||
$core_dependencies = array( 'jquery', 'jquery-ui-dialog', 'backbone', 'wpml-underscore-template-compiler' );
|
||||
wp_register_script(
|
||||
'templates-compiled',
|
||||
ICL_PLUGIN_URL . '/res/js/taxonomy-translation/templates-compiled.js',
|
||||
$core_dependencies,
|
||||
'1.2.4'
|
||||
);
|
||||
$core_dependencies[] = 'templates-compiled';
|
||||
wp_register_script( 'main-util', ICL_PLUGIN_URL . '/res/js/taxonomy-translation/util.js', $core_dependencies );
|
||||
|
||||
wp_register_script( 'main-model', ICL_PLUGIN_URL . '/res/js/taxonomy-translation/main.js', $core_dependencies );
|
||||
$core_dependencies[] = 'main-model';
|
||||
|
||||
$dependencies = $core_dependencies;
|
||||
wp_register_script(
|
||||
'term-rows-collection',
|
||||
ICL_PLUGIN_URL . '/res/js/taxonomy-translation/collections/term-rows.js',
|
||||
array_merge( $core_dependencies, array( 'term-row-model' ) )
|
||||
);
|
||||
$dependencies[] = 'term-rows-collection';
|
||||
wp_register_script(
|
||||
'term-model',
|
||||
ICL_PLUGIN_URL . '/res/js/taxonomy-translation/models/term.js',
|
||||
$core_dependencies
|
||||
);
|
||||
$dependencies[] = 'term-model';
|
||||
wp_register_script(
|
||||
'taxonomy-model',
|
||||
ICL_PLUGIN_URL . '/res/js/taxonomy-translation/models/taxonomy.js',
|
||||
$core_dependencies
|
||||
);
|
||||
$dependencies[] = 'taxonomy-model';
|
||||
wp_register_script(
|
||||
'term-row-model',
|
||||
ICL_PLUGIN_URL . '/res/js/taxonomy-translation/models/term-row.js',
|
||||
$core_dependencies
|
||||
);
|
||||
$dependencies[] = 'term-row-model';
|
||||
|
||||
foreach ( array(
|
||||
'filter-view',
|
||||
'nav-view',
|
||||
'table-view',
|
||||
'taxonomy-view',
|
||||
'term-popup-view',
|
||||
'original-term-popup-view',
|
||||
'label-popup-view',
|
||||
'term-row-view',
|
||||
'label-row-view',
|
||||
'term-rows-view',
|
||||
'term-view',
|
||||
'term-original-view',
|
||||
'copy-all-popup-view',
|
||||
) as $script ) {
|
||||
|
||||
wp_register_script(
|
||||
$script,
|
||||
ICL_PLUGIN_URL . '/res/js/taxonomy-translation/views/' . $script . '.js',
|
||||
$core_dependencies,
|
||||
'1.2.4'
|
||||
);
|
||||
$dependencies[] = $script;
|
||||
}
|
||||
|
||||
wp_localize_script( 'main-model', 'labels', self::get_strings_translation_array() );
|
||||
wp_localize_script( 'main-model', 'wpml_taxonomies', self::wpml_get_table_taxonomies( $sitepress ) );
|
||||
|
||||
$need_enqueue = $dependencies;
|
||||
$need_enqueue[] = 'main-model';
|
||||
$need_enqueue[] = 'main-util';
|
||||
$need_enqueue[] = 'templates';
|
||||
|
||||
foreach ( $need_enqueue as $handle ) {
|
||||
wp_enqueue_script( $handle );
|
||||
}
|
||||
|
||||
wp_register_script( 'taxonomy-hierarchy-sync-message', ICL_PLUGIN_URL . '/res/js/taxonomy-hierarchy-sync-message.js', array( 'jquery' ) );
|
||||
wp_enqueue_script( 'taxonomy-hierarchy-sync-message' );
|
||||
|
||||
}
|
||||
|
||||
public static function wpml_get_table_taxonomies( SitePress $sitepress ) {
|
||||
$taxonomies = $sitepress->get_wp_api()->get_taxonomies( array(), 'objects' );
|
||||
|
||||
$result = array(
|
||||
'taxonomies' => array(),
|
||||
'activeLanguages' => array(),
|
||||
'allLanguages' => array(),
|
||||
);
|
||||
$sitepress->set_admin_language();
|
||||
$active_langs = $sitepress->get_active_languages();
|
||||
$default_lang = $sitepress->get_default_language();
|
||||
|
||||
$result['activeLanguages'][ $default_lang ] = array(
|
||||
'label' => esc_js( $active_langs[ $default_lang ]['display_name'] ),
|
||||
'flag' => esc_url( $sitepress->get_flag_url( $default_lang ) ),
|
||||
);
|
||||
foreach ( $active_langs as $code => $lang ) {
|
||||
if ( $code !== $default_lang ) {
|
||||
$result['activeLanguages'][ $code ] = array(
|
||||
'label' => esc_js( $lang['display_name'] ),
|
||||
'flag' => esc_url( $sitepress->get_flag_url( $code ) ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$all_languages = $sitepress->get_languages();
|
||||
foreach ( $all_languages as $code => $lang ) {
|
||||
$result['allLanguages'][ $code ] = array(
|
||||
'label' => esc_js( $lang['display_name'] ),
|
||||
'flag' => esc_url( $sitepress->get_flag_url( $code ) ),
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $taxonomies as $key => $tax ) {
|
||||
if ( $sitepress->is_translated_taxonomy( $key ) ) {
|
||||
$result['taxonomies'][ $key ] = array(
|
||||
'label' => $tax->label,
|
||||
'singularLabel' => $tax->labels->singular_name,
|
||||
'hierarchical' => $tax->hierarchical,
|
||||
'name' => $key,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function wpml_get_terms_and_labels_for_taxonomy_table() {
|
||||
global $sitepress;
|
||||
|
||||
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'wpml_taxonomy_translation_nonce' ) ) {
|
||||
wp_send_json_error( __( 'Wrong nonce', 'sitepress' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
$taxonomy = false;
|
||||
|
||||
$request_post_taxonomy = filter_input(
|
||||
INPUT_POST,
|
||||
'taxonomy',
|
||||
FILTER_SANITIZE_FULL_SPECIAL_CHARS,
|
||||
FILTER_NULL_ON_FAILURE
|
||||
);
|
||||
if ( $request_post_taxonomy ) {
|
||||
$taxonomy = html_entity_decode( $request_post_taxonomy );
|
||||
}
|
||||
|
||||
if ( $taxonomy ) {
|
||||
$terms_data = new WPML_Taxonomy_Translation_Screen_Data( $sitepress, $taxonomy );
|
||||
$term_results = $terms_data->terms();
|
||||
$labels = apply_filters( 'wpml_label_translation_data', false, $taxonomy );
|
||||
$def_lang = $sitepress->get_default_language();
|
||||
$bottom_content = apply_filters( 'wpml_taxonomy_translation_bottom', $html = '', $taxonomy, get_taxonomy( $taxonomy ) );
|
||||
wp_send_json(
|
||||
array(
|
||||
'terms' => $term_results['terms'],
|
||||
'resultsTruncated' => $term_results['truncated'],
|
||||
'taxLabelTranslations' => $labels,
|
||||
'defaultLanguage' => $def_lang,
|
||||
'bottomContent' => $bottom_content,
|
||||
'taxLangSelector' => self::render_tax_language_selector( $labels, $taxonomy ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
wp_send_json_error();
|
||||
}
|
||||
}
|
||||
|
||||
private static function render_tax_language_selector( $labels, $taxonomy ) {
|
||||
global $sitepress;
|
||||
|
||||
if ( ! isset( $labels['st_default_lang'] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'selected' => $labels['st_default_lang'],
|
||||
'name' => 'string_lang[' . $taxonomy . ']',
|
||||
'show_please_select' => false,
|
||||
'echo' => false,
|
||||
'class' => 'js-tax-lang-selector',
|
||||
);
|
||||
|
||||
$lang_selector = new WPML_Simple_Language_Selector( $sitepress );
|
||||
return $lang_selector->render( $args );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
class WPML_Tax_Menu_Loader {
|
||||
|
||||
/** @var SitePress $sitepress */
|
||||
private $sitepress;
|
||||
/** @var wpdb $wpdb */
|
||||
public $wpdb;
|
||||
/** @var string $taxonomy */
|
||||
private $taxonomy;
|
||||
|
||||
/**
|
||||
* @param wpdb $wpdb
|
||||
* @param SitePress $sitepress
|
||||
* @param string $taxonomy
|
||||
*/
|
||||
public function __construct( $wpdb, $sitepress, $taxonomy ) {
|
||||
$this->sitepress = $sitepress;
|
||||
$this->wpdb = $wpdb;
|
||||
$this->taxonomy = $taxonomy;
|
||||
|
||||
add_action( 'init', [ $this, 'init' ] );
|
||||
add_action( 'after-category-table', [ $this, 'category_display_action' ], 1, 0 );
|
||||
add_filter( 'wp_redirect', [ $this, 'preserve_lang_param' ] );
|
||||
}
|
||||
|
||||
public function get_wpdb() {
|
||||
return $this->wpdb;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
$tax_get = filter_input( INPUT_GET, 'taxonomy' );
|
||||
$trid = filter_input( INPUT_GET, 'trid' );
|
||||
if ( $trid
|
||||
&& ( $source_lang = filter_input( INPUT_GET, 'source_lang' ) )
|
||||
&& get_taxonomy( $tax_get ) !== false
|
||||
) {
|
||||
$translations = $this->sitepress->get_element_translations( $trid, 'tax_' . $this->taxonomy );
|
||||
if ( isset( $translations[ $_GET['lang'] ] ) && ! empty( $translations[ $_GET['lang'] ]->term_id ) ) {
|
||||
wp_redirect( get_edit_term_link( $translations[ $_GET['lang'] ]->term_id, $tax_get ) );
|
||||
exit;
|
||||
} else {
|
||||
add_action( 'admin_notices', [ $this, '_tax_adding' ] );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( $this->taxonomy . '_edit_form', [ $this, 'wpml_edit_term_form' ] );
|
||||
add_action( $this->taxonomy . '_add_form', [ $this, 'wpml_edit_term_form' ] );
|
||||
|
||||
add_action( 'admin_print_scripts-edit-tags.php', [ $this, 'js_scripts_tags' ] );
|
||||
add_action( 'admin_print_scripts-term.php', [ $this, 'js_scripts_tags' ] );
|
||||
add_filter( 'wp_dropdown_cats', [ $this, 'wp_dropdown_cats_select_parent' ], 10, 2 );
|
||||
if ( ! $this->sitepress->get_wp_api()->is_term_edit_page() ) {
|
||||
$term_lang_filter = new WPML_Term_Language_Filter( $this->wpdb, $this->sitepress );
|
||||
add_action( 'admin_footer', [ $term_lang_filter, 'terms_language_filter' ], 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the display of the categories list in order to prevent the default category from being delete-able.
|
||||
* This is done by printing a hidden div containing a JSON encoded array with all category id's, the checkboxes of which are to be removed.
|
||||
*/
|
||||
public function category_display_action() {
|
||||
/** @var WPML_Term_Translation $wpml_term_translations */
|
||||
global $wpml_term_translations;
|
||||
|
||||
if ( ( $default_category_id = get_option( 'default_category' ) ) ) {
|
||||
$default_cat_ids = array();
|
||||
|
||||
$translations = $wpml_term_translations->get_element_translations( $default_category_id );
|
||||
foreach ( $translations as $lang => $translation ) {
|
||||
$default_cat_ids [] = $wpml_term_translations->term_id_in( $default_category_id, $lang );
|
||||
}
|
||||
echo '<div id="icl-default-category-ids" style="display: none;">'
|
||||
. wp_json_encode( $default_cat_ids ) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function js_scripts_tags() {
|
||||
wp_enqueue_script( 'sitepress-tags', ICL_PLUGIN_URL . '/res/js/tags.js', array(), ICL_SITEPRESS_VERSION );
|
||||
}
|
||||
|
||||
function wp_dropdown_cats_select_parent( $html, $args ) {
|
||||
if ( ( $trid = filter_input( INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT ) ) ) {
|
||||
$element_type = $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : 'post_tag';
|
||||
$icl_element_type = 'tax_' . $element_type;
|
||||
$source_lang = isset( $_GET['source_lang'] )
|
||||
? filter_input( INPUT_GET, 'source_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS )
|
||||
: $this->sitepress->get_default_language();
|
||||
$parent = $this->wpdb->get_var(
|
||||
$this->wpdb->prepare(
|
||||
"
|
||||
SELECT parent
|
||||
FROM {$this->wpdb->term_taxonomy} tt
|
||||
JOIN {$this->wpdb->prefix}icl_translations tr ON tr.element_id=tt.term_taxonomy_id
|
||||
AND tr.element_type=%s AND tt.taxonomy=%s
|
||||
WHERE trid=%d AND tr.language_code=%s
|
||||
",
|
||||
$icl_element_type,
|
||||
$taxonomy,
|
||||
$trid,
|
||||
$source_lang
|
||||
)
|
||||
);
|
||||
if ( $parent ) {
|
||||
$parent = (int) icl_object_id( $parent, $element_type );
|
||||
$html = str_replace( 'value="' . $parent . '"', 'value="' . $parent . '" selected="selected"', $html );
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Object $term
|
||||
*/
|
||||
public function wpml_edit_term_form( $term ) {
|
||||
include WPML_PLUGIN_PATH . '/menu/term-taxonomy-menus/taxonomy-menu.php';
|
||||
}
|
||||
|
||||
function _tax_adding() {
|
||||
$trid = filter_input( INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT );
|
||||
$taxonomy = filter_input( INPUT_GET, 'taxonomy' );
|
||||
$translations = $trid && $taxonomy ?
|
||||
$this->sitepress->get_element_translations( $trid, 'tax_' . $taxonomy ) : array();
|
||||
$name = isset( $translations[ $_GET['source_lang'] ] ) ? $translations[ filter_input( INPUT_GET, 'source_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ]
|
||||
: false;
|
||||
$name = isset( $name->name ) ? $name->name : false;
|
||||
if ( $name !== false ) {
|
||||
$tax_name = apply_filters( 'the_category', $name );
|
||||
// translators: %s is replaced by the name of the taxonomy.
|
||||
echo '<div id="icl_tax_adding_notice" class="updated fade"><p>'
|
||||
. sprintf( esc_html__( 'Adding translation for: %s.', 'sitepress' ), $tax_name )
|
||||
. '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If user perform bulk taxonomy deletion when displaying non-default
|
||||
* language taxonomies, after deletion should stay with same language
|
||||
*
|
||||
* @param string $location Url where browser will redirect.
|
||||
* @return string Url where browser will redirect.
|
||||
*/
|
||||
public function preserve_lang_param( $location ) {
|
||||
global $wpml_url_converter;
|
||||
|
||||
$get_lang = $wpml_url_converter->get_language_from_url(
|
||||
(string) filter_input( INPUT_POST, '_wp_http_referer' )
|
||||
);
|
||||
$location = $get_lang ? add_query_arg( 'lang', $get_lang, $location ) : $location;
|
||||
|
||||
return $location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class WPML_Taxonomy_Element_Language_Dropdown {
|
||||
|
||||
function add_language_selector_to_page( $active_languages, $selected_language, $translations, $element_id, $type ) {
|
||||
?>
|
||||
<div id="icl_tax_menu" style="display:none">
|
||||
|
||||
<div id="dashboard-widgets" class="metabox-holder">
|
||||
<div class="postbox-container" style="width: 99%;line-height:normal;">
|
||||
|
||||
<div id="icl_<?php echo esc_attr( $type ); ?>_lang" class="postbox" style="line-height:normal;">
|
||||
<h3 class="hndle">
|
||||
<span><?php echo esc_html__( 'Language', 'sitepress' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside" style="padding: 10px;">
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
$active_languages = $this->filter_allowed_languages( $active_languages, $selected_language );
|
||||
$disabled = count( $active_languages ) === 1 ? ' disabled="disabled" ' : '';
|
||||
?>
|
||||
|
||||
<select name="icl_<?php echo esc_attr( $type ); ?>_language" <?php echo $disabled; ?>>
|
||||
|
||||
<?php
|
||||
echo $this->add_options( $active_languages, $selected_language );
|
||||
?>
|
||||
|
||||
<?php foreach ( $active_languages as $lang ) : ?>
|
||||
<?php
|
||||
if ( $lang['code'] === $selected_language || ( isset( $translations[ $lang['code'] ]->element_id ) && $translations[ $lang['code'] ]->element_id != $element_id ) ) {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
<option
|
||||
value="<?php echo esc_attr( $lang['code'] ); ?>"
|
||||
<?php
|
||||
if ( $selected_language === $lang['code'] ) :
|
||||
?>
|
||||
selected="selected"<?php endif; ?>><?php echo esc_html( $lang['display_name'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ( $disabled ) { ?>
|
||||
<input type="hidden" name="icl_<?php echo esc_attr( $type ); ?>_language"
|
||||
value="<?php echo esc_attr( $selected_language ); ?>"/>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private function filter_allowed_languages( $active_languages, $selected_language ) {
|
||||
global $sitepress;
|
||||
|
||||
$wp_api = new WPML_WP_API();
|
||||
$show_all = $wp_api->is_term_edit_page() || $sitepress->get_current_language() === 'all';
|
||||
return $show_all ? $active_languages : array( $active_languages[ $selected_language ] );
|
||||
}
|
||||
|
||||
private function add_options( $active_languages, $selected_language ) {
|
||||
$html = '';
|
||||
|
||||
foreach ( $active_languages as $lang ) {
|
||||
if ( $lang['code'] === $selected_language ) {
|
||||
$html .= '<option value="' . esc_attr( $selected_language ) . '" selected="selected">' . esc_html( $lang['display_name'] ) . '</option>';
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
class WPML_Taxonomy_Translation_Sync_Display {
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_wpml_tt_sync_hierarchy_preview', array( $this, 'ajax_sync_preview' ) );
|
||||
add_action( 'wp_ajax_wpml_tt_sync_hierarchy_save', array( $this, 'ajax_sync_save' ) );
|
||||
}
|
||||
|
||||
private function get_req_data() {
|
||||
$taxonomy = isset( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : false;
|
||||
$ref_lang = isset( $_POST['ref_lang'] ) ? $_POST['ref_lang'] : false;
|
||||
|
||||
return array( $taxonomy, $ref_lang );
|
||||
}
|
||||
|
||||
public function ajax_sync_preview() {
|
||||
global $wpml_language_resolution, $sitepress;
|
||||
|
||||
if ( ! wpml_is_action_authenticated( 'wpml_tt_sync_hierarchy' ) ) {
|
||||
wp_send_json_error( 'Wrong Nonce' );
|
||||
}
|
||||
$sync_helper = wpml_get_hierarchy_sync_helper( 'term' );
|
||||
list( $taxonomy, $ref_lang ) = $this->get_req_data();
|
||||
if ( $taxonomy ) {
|
||||
$ref_lang = $wpml_language_resolution->is_language_active( $ref_lang ) || $wpml_language_resolution->is_language_hidden( $ref_lang )
|
||||
? $ref_lang : $sitepress->get_default_language();
|
||||
$corrections = $sync_helper->get_unsynced_elements( $taxonomy, $ref_lang );
|
||||
wp_send_json_success( $corrections );
|
||||
} else {
|
||||
wp_send_json_error( 'No taxonomy in request!' );
|
||||
}
|
||||
}
|
||||
|
||||
public function ajax_sync_save() {
|
||||
if ( ! wpml_is_action_authenticated( 'wpml_tt_sync_hierarchy' ) ) {
|
||||
wp_send_json_error( 'Wrong Nonce' );
|
||||
}
|
||||
$sync_helper = wpml_get_hierarchy_sync_helper( 'term' );
|
||||
list( $taxonomy, $ref_lang ) = $this->get_req_data();
|
||||
if ( $taxonomy ) {
|
||||
$sync_helper->sync_element_hierarchy( $taxonomy, $ref_lang );
|
||||
wp_send_json_success( 1 );
|
||||
} else {
|
||||
wp_send_json_error( 'No taxonomy in request!' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
class WPML_Term_Language_Filter extends WPML_Language_Filter_Bar {
|
||||
|
||||
function terms_language_filter( $echo = true ) {
|
||||
$this->init();
|
||||
$requested_data = $this->sanitize_request();
|
||||
$taxonomy = $requested_data['req_tax'] !== '' ? $requested_data['req_tax'] : 'post_tag';
|
||||
$post_type = $requested_data['req_ptype'] !== '' ? $requested_data['req_ptype'] : '';
|
||||
$languages = $this->get_counts( $taxonomy );
|
||||
$languages_links = array();
|
||||
foreach ( $this->active_languages as $code => $lang ) {
|
||||
$languages_links[] = $this->lang_element( $languages, $code, $taxonomy, $post_type );
|
||||
}
|
||||
$all_languages_links = join( ' | ', $languages_links );
|
||||
|
||||
$html = '<span id="icl_subsubsub" class="icl_subsubsub" style="display: none;">' . $all_languages_links . '</span>';
|
||||
if ( $echo !== false ) {
|
||||
echo $html;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function lang_element( $languages, $code, $taxonomy, $post_type ) {
|
||||
$count = isset( $languages[ $code ] ) ? $languages[ $code ] : 0;
|
||||
if ( $code === $this->current_language ) {
|
||||
list($px, $sx) = $this->strong_lang_span_cover( $code, $count );
|
||||
} else {
|
||||
$px = '<a href="?taxonomy=' . esc_attr( $taxonomy ) . '&lang=' . esc_attr( $code );
|
||||
$px .= $post_type !== '' ? '&post_type=' . esc_attr( $post_type ) : '';
|
||||
$px .= '">';
|
||||
$sx = '</a>' . $this->lang_span( $code, $count );
|
||||
}
|
||||
|
||||
return $px . esc_html( $this->active_languages[ $code ]['display_name'] ) . $sx;
|
||||
}
|
||||
|
||||
protected function get_count_data( $taxonomy ) {
|
||||
$res_query = " SELECT language_code, COUNT(tm.term_id) AS c
|
||||
FROM {$this->wpdb->prefix}icl_translations t
|
||||
JOIN {$this->wpdb->term_taxonomy} tt
|
||||
ON t.element_id = tt.term_taxonomy_id
|
||||
AND t.element_type = CONCAT('tax_', tt.taxonomy)
|
||||
JOIN {$this->wpdb->terms} tm
|
||||
ON tt.term_id = tm.term_id
|
||||
WHERE tt.taxonomy = %s
|
||||
" . $this->extra_conditions_snippet();
|
||||
|
||||
return $this->wpdb->get_results( $this->wpdb->prepare( $res_query, $taxonomy ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user