PluginProbe
Polylang / 1.2.1
Polylang v1.2.1
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.2.1, at include/links.php

78 lines 2.0 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
11 /*
12 * constructor
13 *
14 * @since 1.2
15 *
16 * @param object $links_model
17 */
18 public function __construct(&$links_model) {
19 $this->links_model = &$links_model;
20 $this->model = &$links_model->model;
21 $this->options = &$this->model->options;
22
23 // low priority on links filters to come after any other modifications
24 if ($this->options['force_lang']) {
25 foreach (array('post_link', '_get_page_link', 'post_type_link') as $filter)
26 add_filter($filter, array(&$this, 'post_link'), 20, 2);
27
28 add_filter('term_link', array(&$this, 'term_link'), 20, 3);
29 }
30 }
31
32 /*
33 * modifies post & page links
34 *
35 * @since 0.7
36 *
37 * @param string $link post link
38 * @param object|int $post post object or post ID
39 * @return string modified post link
40 */
41 public function post_link($link, $post) {
42 static $links = array();
43
44 if (isset($links[$link]))
45 return $links[$link];
46
47 if ('post_type_link' == current_filter() && !in_array($post->post_type, $this->model->post_types))
48 return $links[$link] = $link;
49
50 if ('_get_page_link' == current_filter()) // this filter uses the ID instead of the post object
51 $post = get_post($post);
52
53 // /!\ when post_status in not "publish", WP does not use pretty permalinks
54 return $links[$link] = $post->post_status != 'publish' ? $link : $this->links_model->add_language_to_link($link, $this->model->get_post_language($post->ID));
55 }
56
57 /*
58 * modifies term link
59 *
60 * @since 0.7
61 *
62 * @param string $link term link
63 * @param object $post term object
64 * @param string $tax taxonomy name
65 * @return string modified term link
66 */
67 public function term_link($link, $term, $tax) {
68 static $links = array();
69
70 if (isset($links[$link]))
71 return $links[$link];
72
73 return $links[$link] = in_array($tax, $this->model->taxonomies) ?
74 $this->links_model->add_language_to_link($link, $this->model->get_term_language($term->term_id)) : $link;
75 }
76 }
77
78