WordPress.org

Plugin Directory

Changeset 629406


Ignore:
Timestamp:
11/24/12 13:49:23 (17 months ago)
Author:
Chouby
Message:

rework canonical redirection introduced in 0.9.5

Location:
polylang/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • polylang/trunk/include/core.php

    r628789 r629406  
    7575        // prevents redirection of the homepage 
    7676        add_filter('redirect_canonical', array(&$this, 'stop_redirect_canonical'), 10, 2); 
    77  
    78         // redirects incoming links to the proper URL when adding the language code to all urls 
    79 // FIXME causes a lot of issues 
    80 //      if ($this->options['force_lang'] && get_option('permalink_structure') && PLL_LANG_EARLY) 
    81 //          add_action('template_redirect',  array(&$this, 'redirect_canonical'), 20); // after Wordpress redirect_canonical 
    8277 
    8378        // adds javascript at the end of the document 
     
    258253        elseif (false === strpos($_SERVER['SCRIPT_NAME'], 'index.php')) // wp-login, wp-signup, wp-activate 
    259254            $this->curlang = $this->get_preferred_language(); 
    260         else 
     255        else { 
    261256            $this->curlang = $this->get_language($this->options['default_lang']); 
     257            add_action('wp', array(&$this, 'check_language_code_in_url')); // before Wordpress redirect_canonical 
     258        } 
    262259 
    263260        $GLOBALS['l10n']['pll_string'] = $this->mo_import($this->curlang); 
     
    565562    } 
    566563 
    567     // prevents redirection of the homepage when using page on front 
    568     function stop_redirect_canonical($redirect_url, $requested_url) { 
    569         return $requested_url == home_url('/') || strpos($requested_url, $this->page_link('', get_option('page_on_front'))) !== false ? false : $redirect_url; 
    570     } 
    571  
    572564    // redirects incoming links to the proper URL when adding the language code to all urls 
    573     function redirect_canonical($requested_url = false, $do_redirect = true) { 
    574         if (!$requested_url) 
    575             $requested_url  = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
    576  
     565    function check_language_code_in_url() { 
    577566        if (is_single() || is_page()) { 
    578567            global $post; 
    579568            if (isset($post->ID) && in_array($post->post_type, $this->post_types)) 
    580                 $redirect_url = get_permalink((int)$post->ID); 
     569                $language = $this->get_post_language((int)$post->ID); 
    581570        } 
    582571        elseif (is_category() || is_tag() || is_tax()) { 
    583572            $obj = $GLOBALS['wp_query']->get_queried_object(); 
    584573            if (in_array($obj->taxonomy, $this->taxonomies)) 
    585                 $redirect_url = get_term_link((int)$obj->term_id, $obj->taxonomy); 
    586         } 
    587  
    588         if (!isset($redirect_url) || is_wp_error($redirect_url) || $redirect_url == $requested_url) 
    589             return false; 
    590  
    591         if ($do_redirect) { 
    592             // protect against chained redirects 
    593             if (!$this->redirect_canonical($redirect_url, false) ) { 
    594                 wp_redirect($redirect_url, 301); 
    595                 exit; 
    596             }  
    597             else 
    598                 return false; 
    599         } 
    600  
    601         return $redirect_url; 
     574                $language = $this->get_term_language((int)$obj->term_id); 
     575        } 
     576         
     577        // the language is not correctly set so let's redirect to the correct url for this object 
     578        if (isset($language) && $language->slug != $this->curlang->slug) { 
     579            $requested_url  = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
     580            $redirect_url = $this->add_language_to_link($requested_url, $language); 
     581            wp_redirect($redirect_url, 301); 
     582            exit; 
     583        } 
     584    } 
     585 
     586    // prevents redirection of the homepage when using page on front 
     587    function stop_redirect_canonical($redirect_url, $requested_url) { 
     588        $home_url = home_url('/'); 
     589        $page_link = $this->page_link('', get_option('page_on_front')); 
     590        return $requested_url == $home_url || ($page_link != $home_url && strpos($requested_url, $page_link ) !== false) ? false : $redirect_url; 
    602591    } 
    603592 
  • polylang/trunk/polylang.php

    r628789 r629406  
    33Plugin Name: Polylang 
    44Plugin URI: http://wordpress.org/extend/plugins/polylang/ 
    5 Version: 0.9.5.4 
     5Version: 0.9.5.5 
    66Author: F. Demarle 
    77Description: Adds multilingual capability to Wordpress 
     
    2727*/ 
    2828 
    29 define('POLYLANG_VERSION', '0.9.5.4'); 
     29define('POLYLANG_VERSION', '0.9.5.5'); 
    3030define('PLL_MIN_WP_VERSION', '3.1'); 
    3131 
  • polylang/trunk/readme.txt

    r628789 r629406  
    9898* It is now possible to query the terms by language using the WordPress function 'get_terms' 
    9999* Bug correction: search for empty string in default language displays posts in all languages when hiding the URL language information for default language  
    100 * Bug correction: removed the canonical redirection introduced in 0.9.5 which creates more problems than it solves 
     100* Bug correction: completely reworked the canonical redirection introduced in 0.9.5 which created more problems than it solved 
    101101* Tests done with WordPress 3.5 beta RC1 
    102102 
Note: See TracChangeset for help on using the changeset viewer.