PluginProbe
Polylang / 1.1
Polylang v1.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 / api.php

api.php in Polylang 1.1, at include/api.php

98 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * template tag: displays the language switcher
5 */
6 function pll_the_languages($args = '') {
7 global $polylang;
8 return class_exists('Polylang_Core') && $polylang instanceof Polylang_Core ? $polylang->the_languages($args) : '';
9 }
10
11 /*
12 * returns the current language
13 */
14 function pll_current_language($args = 'slug') {
15 global $polylang;
16 return !(class_exists('Polylang_Core') && $polylang instanceof Polylang_Core && isset($polylang->curlang)) ? false :
17 ($args == 'name' ? $polylang->curlang->name :
18 ($args == 'locale' ? $polylang->curlang->description :
19 $polylang->curlang->slug));
20 }
21
22 /*
23 * returns the default language
24 */
25 function pll_default_language($args = 'slug') {
26 global $polylang;
27 return !(isset($polylang) && ($options = get_option('polylang')) && isset($options['default_lang']) && $lang = $polylang->get_language($options['default_lang'])) ? false :
28 ($args == 'name' ? $lang->name :
29 ($args == 'locale' ? $lang->description :
30 $lang->slug));
31 }
32
33 /*
34 * among the post and its translations, returns the id of the post which is in the language represented by $slug
35 */
36 function pll_get_post($post_id, $slug = false) {
37 global $polylang;
38 return isset($polylang) && ($slug = $slug ? $slug : pll_current_language()) ? $polylang->get_post($post_id, $slug) : null;
39 }
40
41 /*
42 * among the term and its translations, returns the id of the term which is in the language represented by $slug
43 */
44 function pll_get_term($term_id, $slug = false) {
45 global $polylang;
46 return isset($polylang) && ($slug = $slug ? $slug : pll_current_language()) ? $polylang->get_term($term_id, $slug) : null;
47 }
48
49 /*
50 * returns the home url in the current language
51 */
52 function pll_home_url() {
53 global $polylang;
54 return class_exists('Polylang_Core') && $polylang instanceof Polylang_Core ? $polylang->get_home_url() : home_url('/');
55 }
56
57 /*
58 * registers a string for translation in the "strings translation" panel
59 */
60 function pll_register_string($name, $string, $multiline = false) {
61 global $polylang;
62 if (class_exists('Polylang_Admin_Base') && $polylang instanceof Polylang_Admin_Base)
63 $polylang->register_string($name, $string, $multiline);
64 }
65
66 /*
67 * translates a string (previously registered with pll_register_string)
68 */
69 function pll__($string) {
70 return __($string, 'pll_string');
71 }
72
73 /*
74 * echoes a translated string (previously registered with pll_register_string)
75 */
76 function pll_e($string) {
77 _e($string, 'pll_string');
78 }
79
80 /*
81 * returns true if Polylang manages languages and translation for this post type
82 * won't work before the action 'wp_loaded' has been fired
83 */
84 function pll_is_translated_post_type($post_type) {
85 global $polylang;
86 return isset($polylang) && is_array($polylang->post_types) && in_array($post_type, $polylang->post_types);
87 }
88
89 /*
90 * returns true if Polylang manages languages and translation for this taxonomy
91 * won't work before the action 'wp_loaded' has been fired
92 */
93 function pll_is_translated_taxonomy($tax) {
94 global $polylang;
95 return isset($polylang) && is_array($polylang->taxonomies) && in_array($tax, $polylang->taxonomies);
96 }
97
98