Plugin Directory

Changeset 2641517


Ignore:
Timestamp:
12/08/2021 10:31:48 PM (4 years ago)
Author:
elevio
Message:

Improving multi-lingual sync for categories

Location:
elevio/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • elevio/trunk/elevio.php

    r2481895 r2641517  
    66Author: Elevio
    77Author URI: https://elev.io
    8 Version: 4.2.0
     8Version: 4.3.0
    99*/
    1010
  • elevio/trunk/plugin_files/ElevioSync.class.php

    r2481895 r2641517  
    33class ElevioSync
    44{
     5    private $languages = [];
     6
    57    public function __construct()
    68    {
     
    3335        }
    3436
    35         if ( $this->is_multilanguage_allowed() ) {
    36             // Integrate with WPML
    37             $categories = apply_filters( 'elevio_retrieve_categories_in_all_languages', $categories, $args );
    38         }
     37        if ($this->is_multilanguage_allowed()) {
     38            // Integrate with WPML
     39            $categories = apply_filters('elevio_retrieve_categories_in_all_languages', $categories, $args);
     40        }
    3941
    40         if ( $this->is_aggregate_translated_articles_enabled() ) {
    41             $categories = apply_filters( 'elevio_aggregate_translated_categories', $categories, $args['taxonomy'] );
    42         }
     42        if ($this->is_aggregate_translated_articles_enabled()) {
     43            $categories = apply_filters('elevio_aggregate_translated_categories', $categories, $args['taxonomy']);
     44        }
    4345
    4446        return $categories;
     
    7274        $tax_query = apply_filters('elevio_posts_tax_query', $tax_query);
    7375        $_GET['tax_query'] = $tax_query;
    74         $filters = $_GET;
     76        $filters = $_GET;
    7577
    76         if ( $this->is_multilanguage_allowed() ) {
    77             $filters = apply_filters( 'elevio_add_article_filters', $filters);
    78         }
     78        if ($this->is_multilanguage_allowed()) {
     79            $filters = apply_filters('elevio_add_article_filters', $filters);
     80        }
    7981
    8082        query_posts(http_build_query($filters));
    8183
     84        $langs = $this->getAvailableLanguages();
    8285        $output = [];
    8386        while (have_posts()) {
     
    8992            }
    9093
    91             if ( $this->is_multilanguage_allowed() ) {
    92                 $new_post = apply_filters( 'elevio_append_language_id_to_article', $new_post, $post->ID );
    93             }
     94            if ($this->is_multilanguage_allowed()) {
     95                $new_post = apply_filters('elevio_append_language_id_to_article', $new_post, $post->ID);
     96                // Getting other content languages
     97                foreach ($langs as $lang) {
     98                    $post_id = wpml_object_id_filter($new_post->id, $new_post->type, false, $lang);
     99                    if (!$post_id) {
     100                        continue;
     101                    }
     102                    $post = new Elevio_Sync_Post(get_post($post_id));
     103                    $post->language_id = $lang;
     104                    $output[] = $post;
     105                }
     106            }
    94107
    95             $output[] = $new_post;
     108            $output[] = $new_post;
    96109        }
    97110
    98         if ( $this->is_aggregate_translated_articles_enabled() ) {
    99             $output = apply_filters( 'elevio_aggregate_translated_articles', $output );
    100         }
     111        if ($this->is_aggregate_translated_articles_enabled()) {
     112            $output = apply_filters('elevio_aggregate_translated_articles', $output);
     113        }
    101114
    102115        return array_values($output);
     116    }
     117
     118    protected function getAvailableLanguages()
     119    {
     120        if (!$this->is_multilanguage_allowed()) {
     121            return [];
     122        }
     123
     124        if ($this->languages) {
     125            return $this->languages;
     126        }
     127
     128        global $sitepress;
     129        return $this->languages = array_keys($sitepress->get_active_languages());
    103130    }
    104131
     
    132159    }
    133160
    134     private function is_multilanguage_allowed() {
    135         return Elevio::get_instance()->multi_language_is_enabled();
    136     }
     161    private function is_multilanguage_allowed()
     162    {
     163        return Elevio::get_instance()->multi_language_is_enabled();
     164    }
    137165
    138166
    139     private function is_aggregate_translated_articles_enabled() {
    140         return boolval($this->is_multilanguage_allowed() && Elevio::get_instance()->aggregate_translated_articles());
    141     }
     167    private function is_aggregate_translated_articles_enabled()
     168    {
     169        return boolval($this->is_multilanguage_allowed() && Elevio::get_instance()->aggregate_translated_articles());
     170    }
    142171}
  • elevio/trunk/readme.txt

    r2481895 r2641517  
    44Stable tag: 4.9.8
    55Requires at least: 2.8
    6 Tested up to: 5.6.2
     6Tested up to: 5.6.6
    77
    88Elevio for WordPress plugin that integrates with your existing knowledge base, chat client, support system and more
     
    3838
    3939== Changelog ==
     40
     41= 4.3.0 =
     42* Improved support for multi-lingual content when WPML is used.
    4043
    4144= 4.2.0 =
Note: See TracChangeset for help on using the changeset viewer.