Plugin Directory

Changeset 841660


Ignore:
Timestamp:
01/20/2014 09:07:55 AM (12 years ago)
Author:
s-andy
Message:

Added translations, fixed category list and author link

Location:
language-mix/trunk
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • language-mix/trunk/language-mix.php

    r837421 r841660  
    3535require_once(ABSPATH . 'wp-admin/includes/plugin.php');
    3636
     37$author_rules_backup = array();
     38
    3739/**
    3840 * Iterrupt plugin activation if Polylang is not activated/installed
     
    124126            } else if (is_category() || is_tag() || is_tax()) {
    125127                $term         = get_queried_object();
    126                 $translations = pllx_get_translations_with_children($term->term_id, $term->taxonomy);
     128                $translations = pllx_get_translations_with_children($term->term_id, $term->taxonomy, $slugs);
    127129
    128130                if (count($translations) > 0) {
     
    274276
    275277/**
     278 * Make a copy of author rules
     279 */
     280function pllx_backup_author_rules($rules) {
     281    global $author_rules_backup;
     282    $author_rules_backup = $rules;
     283    return $rules;
     284}
     285add_filter('author_rewrite_rules', 'pllx_backup_author_rules');
     286
     287/**
     288 * Restore author rules
     289 */
     290function pllx_rewrite_rules($rules) {
     291    global $author_rules_backup;
     292    return $author_rules_backup + $rules;
     293}
     294add_filter('rewrite_rules_array', 'pllx_rewrite_rules');
     295
     296# TODO same for date and search? etc?
     297
     298/**
     299 * Remove link from author URL
     300 */
     301function pllx_author_link($link) {
     302    global $polylang;
     303    return $polylang->links_model->remove_language_from_link($link);
     304}
     305add_filter('author_link', 'pllx_author_link', 30);
     306
     307/**
    276308 * Get all translations of the term (including children)
    277309 */
    278 function pllx_get_translations_with_children($term_id, $taxonomy) {
     310function pllx_get_translations_with_children($term_id, $taxonomy, $languages) {
    279311    global $polylang;
    280312
     
    283315
    284316    foreach ($term_translations as $language => $term_id) {
    285         $term = get_term($term_id, $taxonomy);
    286         if ($term) {
    287             $translations[] = $term->term_taxonomy_id;
    288 
    289             $term_children  = get_term_children($term_id, $taxonomy);
    290 
    291             foreach ($term_children as $term_child) {
    292                 $term = get_term($term_child, $taxonomy);
    293                 if ($term) {
    294                     $translations[] = $term->term_taxonomy_id;
     317        if (in_array($language, $languages)) {
     318            $term = get_term($term_id, $taxonomy);
     319            if ($term) {
     320                $translations[] = $term->term_taxonomy_id;
     321
     322                $term_children  = get_term_children($term_id, $taxonomy);
     323
     324                foreach ($term_children as $term_child) {
     325                    $term = get_term($term_child, $taxonomy);
     326                    if ($term) {
     327                        $translations[] = $term->term_taxonomy_id;
     328                    }
    295329                }
    296330            }
  • language-mix/trunk/readme.txt

    r837690 r841660  
    5353
    54541. The Languages widget, which allows to configure shown languages (uses theme)
    55 2. The Translations widgets, which lets switching between translations (uses theme)
     552. The Translations widget, which lets switching between translations (uses theme)
    5656
    5757== Changelog ==
     
    7979*(English and Russian)* can be found [here](http://blog.andriylesyuk.com/the-nature-of-euromaidan/).
    8080
    81 == Credits ==
    82 
    83 Thanks to:
     81== Thanks to ==
    8482
    8583* [Francesco De Comite](http://www.flickr.com/photos/fdecomite/) for
Note: See TracChangeset for help on using the changeset viewer.