PluginProbe
Polylang / 1.5
Polylang v1.5
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-default.php

links-default.php in Polylang 1.5, at include/links-default.php

93 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * links model for default permalinks
5 * for example mysite.com/?somevar=something&lang=en
6 * implements the "links_model interface"
7 *
8 * @since 1.2
9 */
10 class PLL_Links_Default extends PLL_Links_Model {
11
12 /*
13 * adds language information to an url
14 * links_model interface
15 *
16 * @since 1.2
17 *
18 * @param string $url url to modify
19 * @param object $lang language
20 * @return string modified url
21 */
22 public function add_language_to_link($url, $lang) {
23 return !empty($lang) && '_get_page_link' != current_filter() ? add_query_arg( 'lang', $lang->slug, $url ) : $url;
24 }
25
26 /*
27 * removes the language information from an url
28 * links_model interface
29 *
30 * @since 1.2
31 *
32 * @param string $url url to modify
33 * @return string modified url
34 */
35 public function remove_language_from_link($url) {
36 return remove_query_arg('lang', $url);
37 }
38
39 /*
40 * returns the link to the first page
41 * links_model interface
42 *
43 * @since 1.2
44 *
45 * @param string $url url to modify
46 * @return string modified url
47 */
48 function remove_paged_from_link($url) {
49 return remove_query_arg('paged', $url);
50 }
51
52
53 /*
54 * returns the link to the paged page when using pretty permalinks
55 *
56 * @since 1.5
57 *
58 * @param string $url url to modify
59 * @param int $page
60 * @return string modified url
61 */
62 public function add_paged_to_link($url, $page) {
63 return add_query_arg(array('paged' => $page), $url);
64 }
65
66
67 /*
68 * gets the language slug from the url if present
69 * links_model interface
70 *
71 * @since 1.2
72 *
73 * @return string language slug
74 */
75 public function get_language_from_url() {
76 $pattern = '#lang=('.implode('|', $this->model->get_languages_list(array('fields' => 'slug'))).')#';
77 return preg_match($pattern, trailingslashit($_SERVER['REQUEST_URI']), $matches) ? $matches[1] : ''; // $matches[1] is the slug of the requested language
78 }
79
80 /*
81 * returns the home url
82 * links_model interface
83 *
84 * @since 1.3.1
85 *
86 * @param object $lang PLL_Language object
87 * @return string
88 */
89 public function home_url($lang) {
90 return $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ? $this->home : get_term_link($lang, 'language');
91 }
92 }
93