links_model = &$links_model; $this->model = &$links_model->model; $this->options = &$this->model->options; // low priority on links filters to come after any other modifications if ($this->options['force_lang']) { foreach (array('post_link', '_get_page_link', 'post_type_link') as $filter) add_filter($filter, array(&$this, 'post_link'), 20, 2); add_filter('term_link', array(&$this, 'term_link'), 20, 3); } } /* * modifies post & page links * * @since 0.7 * * @param string $link post link * @param object|int $post post object or post ID * @return string modified post link */ public function post_link($link, $post) { static $links = array(); if (isset($links[$link])) return $links[$link]; if ('post_type_link' == current_filter() && !$this->model->is_translated_post_type($post->post_type)) return $links[$link] = $link; if ('_get_page_link' == current_filter()) // this filter uses the ID instead of the post object $post = get_post($post); // /!\ when post_status in not "publish", WP does not use pretty permalinks return $links[$link] = $post->post_status != 'publish' ? $link : $this->links_model->add_language_to_link($link, $this->model->get_post_language($post->ID)); } /* * modifies term link * * @since 0.7 * * @param string $link term link * @param object $post term object * @param string $tax taxonomy name * @return string modified term link */ public function term_link($link, $term, $tax) { static $links = array(); if (isset($links[$link])) return $links[$link]; return $links[$link] = $this->model->is_translated_taxonomy($tax) ? $this->links_model->add_language_to_link($link, $this->model->get_term_language($term->term_id)) : $link; } /* * returns the home url in the requested language * * @since 1.3 * * @param object|string $language * @param bool $is_search optional wether we need the home url for a search form, defaults to false */ public function get_home_url($language, $is_search = false) { $language = is_object($language) ? $language : $this->model->get_language($language); return $is_search ? $language->search_url : $language->home_url; } }