PluginProbe
Polylang / 1.2.2
Polylang v1.2.2
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.2.2, at include/links-default.php

77 lines 1.7 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 {
11 public $model;
12
13 /*
14 * constructor
15 *
16 * @since 1.2
17 *
18 * @param object $model PLL_Model instance
19 */
20 public function __construct(&$model) {
21 $this->model = &$model;
22 }
23
24 /*
25 * adds language information to an url
26 * links_model interface
27 *
28 * @since 1.2
29 *
30 * @param string $url url to modify
31 * @param object $lang language
32 * @return string modified url
33 */
34 public function add_language_to_link($url, $lang) {
35 return !empty($lang) && '_get_page_link' != current_filter() ? add_query_arg( 'lang', $lang->slug, $url ) : $url;
36 }
37
38 /*
39 * removes the language information from an url
40 * links_model interface
41 *
42 * @since 1.2
43 *
44 * @param string $url url to modify
45 * @return string modified url
46 */
47 public function remove_language_from_link($url) {
48 return remove_query_arg('lang', $url);
49 }
50
51 /*
52 * returns the link to the first page
53 * links_model interface
54 *
55 * @since 1.2
56 *
57 * @param string $url url to modify
58 * @return string modified url
59 */
60 function remove_paged_from_link($url) {
61 return remove_query_arg('paged', $url);
62 }
63
64 /*
65 * gets the language slug from the url if present
66 * links_model interface
67 *
68 * @since 1.2
69 *
70 * @return string language slug
71 */
72 public function get_language_from_url() {
73 $pattern = '#lang=('.implode('|', $this->model->get_languages_list(array('fields' => 'slug'))).')#';
74 return preg_match($pattern, trailingslashit($_SERVER['REQUEST_URI']), $matches) ? $matches[1] : ''; // $matches[1] is the slug of the requested language
75 }
76 }
77