PluginProbe
Polylang / 1.4.4
Polylang v1.4.4
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / links.php

links.php in Polylang 1.4.4, at include/links.php

88 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * manages links filters needed on both frontend and admin
5 *
6 * @since 1.2
7 */
8 class PLL_Links {
9 public $links_model, $model, $options;
10 public $links;
11
12 /*
13 * constructor
14 *
15 * @since 1.2
16 *
17 * @param object $links_model
18 */
19 public function __construct(&$links_model) {
20 $this->links_model = &$links_model;
21 $this->model = &$links_model->model;
22 $this->options = &$this->model->options;
23
24 // low priority on links filters to come after any other modifications
25 if ($this->options['force_lang']) {
26 foreach (array('post_link', '_get_page_link', 'post_type_link') as $filter)
27 add_filter($filter, array(&$this, 'post_link'), 20, 2);
28
29 add_filter('term_link', array(&$this, 'term_link'), 20, 3);
30 }
31 }
32
33 /*
34 * modifies post & page links
35 *
36 * @since 0.7
37 *
38 * @param string $link post link
39 * @param object|int $post post object or post ID
40 * @return string modified post link
41 */
42 public function post_link($link, $post) {
43 if (isset($this->links[$link]))
44 return $this->links[$link];
45
46 if ('post_type_link' == current_filter() && !$this->model->is_translated_post_type($post->post_type))
47 return $this->links[$link] = $link;
48
49 if ('_get_page_link' == current_filter()) // this filter uses the ID instead of the post object
50 $post = get_post($post);
51
52 // /!\ when post_status in not "publish", WP does not use pretty permalinks
53 return $this->links[$link] = $post->post_status != 'publish' ? $link : $this->links_model->add_language_to_link($link, $this->model->get_post_language($post->ID));
54 }
55
56 /*
57 * modifies term link
58 *
59 * @since 0.7
60 *
61 * @param string $link term link
62 * @param object $post term object
63 * @param string $tax taxonomy name
64 * @return string modified term link
65 */
66 public function term_link($link, $term, $tax) {
67 if (isset($this->links[$link]))
68 return $this->links[$link];
69
70 return $this->links[$link] = $this->model->is_translated_taxonomy($tax) ?
71 $this->links_model->add_language_to_link($link, $this->model->get_term_language($term->term_id)) : $link;
72 }
73
74 /*
75 * returns the home url in the requested language
76 *
77 * @since 1.3
78 *
79 * @param object|string $language
80 * @param bool $is_search optional wether we need the home url for a search form, defaults to false
81 */
82 public function get_home_url($language, $is_search = false) {
83 $language = is_object($language) ? $language : $this->model->get_language($language);
84 return $is_search ? $language->search_url : $language->home_url;
85 }
86 }
87
88