PluginProbe
Polylang / 2.6.2
Polylang v2.6.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
← All changes | include/api.php +21 -64 2.9.22.6.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Template tag: displays the language switcher
8 5 *
@@ -7,24 +4,21 @@
7 4 * Template tag: displays the language switcher
8 5 *
9 6 * List of parameters accepted in $args:
10 7 *
11 - * - dropdown => displays a dropdown if set to 1, defaults to 0
12 - * - echo => echoes the switcher if set to 1 ( default )
13 - * - hide_if_empty => hides languages with no posts ( or pages ) if set to 1 ( default )
14 - * - show_flags => shows flags if set to 1, defaults to 0
15 - * - show_names => shows languages names if set to 1 ( default )
16 - * - display_names_as => whether to display the language name or its slug, valid options are 'slug' and 'name',
17 - * defaults to name
18 - * - force_home => forces linking to the home page is set to 1, defaults to 0
19 - * - hide_if_no_translation => hides the link if there is no translation if set to 1, defaults to 0
20 - * - hide_current => hides the current language if set to 1, defaults to 0
21 - * - post_id => if not null, link to translations of post defined by post_id, defaults to null
22 - * - raw => set this to true to build your own custom language switcher, defaults to 0
23 - * - item_spacing => whether to preserve or discard whitespace between list items, valid options are
24 - * 'preserve' and 'discard', defaults to preserve
8 + * dropdown => displays a dropdown if set to 1, defaults to 0
9 + * echo => echoes the switcher if set to 1 ( default )
10 + * hide_if_empty => hides languages with no posts ( or pages ) if set to 1 ( default )
11 + * show_flags => shows flags if set to 1, defaults to 0
12 + * show_names => shows languages names if set to 1 ( default )
13 + * display_names_as => whether to display the language name or its slug, valid options are 'slug' and 'name', defaults to name
14 + * force_home => forces linking to the home page is set to 1, defaults to 0
15 + * hide_if_no_translation => hides the link if there is no translation if set to 1, defaults to 0
16 + * hide_current => hides the current language if set to 1, defaults to 0
17 + * post_id => if not null, link to translations of post defined by post_id, defaults to null
18 + * raw => set this to true to build your own custom language switcher, defaults to 0
19 + * item_spacing => whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to preserve
25 20 *
26 - * @api
27 21 * @since 0.5
28 22 *
29 23 * @param array $args optional
30 24 * @return null|string|array null if displaying, array if raw is requested, string otherwise
@@ -40,18 +34,14 @@
40 34 /**
41 35 * Returns the current language on frontend
42 36 * Returns the language set in admin language filter on backend ( false if set to all languages )
43 37 *
44 - * @api
45 38 * @since 0.8.1
46 39 *
47 - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug', pass OBJECT constant to get the language object.
48 - * @return string|PLL_Language|bool The requested field for the current language
40 + * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
41 + * @return string|bool The requested field for the current language
49 42 */
50 43 function pll_current_language( $field = 'slug' ) {
51 - if ( OBJECT === $field ) {
52 - return PLL()->curlang;
53 - }
54 44 return isset( PLL()->curlang->$field ) ? PLL()->curlang->$field : false;
55 45 }
56 46
57 47 /**
@@ -56,31 +46,20 @@
56 46
57 47 /**
58 48 * Returns the default language
59 49 *
60 - * @api
61 50 * @since 1.0
62 51 *
63 - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug', pass OBJECT constant to get the language object.
64 - * @return string|PLL_Language|bool The requested field for the default language
52 + * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
53 + * @return string The requested field for the default language
65 54 */
66 55 function pll_default_language( $field = 'slug' ) {
67 - if ( isset( PLL()->options['default_lang'] ) ) {
68 - $lang = PLL()->model->get_language( PLL()->options['default_lang'] );
69 - if ( $lang ) {
70 - if ( OBJECT === $field ) {
71 - return $lang;
72 - }
73 - return isset( $lang->$field ) ? $lang->$field : false;
74 - }
75 - }
76 - return false;
56 + return isset( PLL()->options['default_lang'] ) && ( $lang = PLL()->model->get_language( PLL()->options['default_lang'] ) ) && isset( $lang->$field ) ? $lang->$field : false;
77 57 }
78 58
79 59 /**
80 60 * Among the post and its translations, returns the id of the post which is in the language represented by $slug
81 61 *
82 - * @api
83 62 * @since 0.5
84 63 *
85 64 * @param int $post_id post id
86 65 * @param string $slug optional language code, defaults to current language
@@ -92,9 +71,8 @@
92 71
93 72 /**
94 73 * Among the term and its translations, returns the id of the term which is in the language represented by $slug
95 74 *
96 - * @api
97 75 * @since 0.5
98 76 *
99 77 * @param int $term_id term id
100 78 * @param string $slug optional language code, defaults to current language
@@ -106,9 +84,8 @@
106 84
107 85 /**
108 86 * Returns the home url in the current language
109 87 *
110 - * @api
111 88 * @since 0.8
112 89 *
113 90 * @param string $lang language code ( optional on frontend )
114 91 * @return string
@@ -123,9 +100,8 @@
123 100
124 101 /**
125 102 * Registers a string for translation in the "strings translation" panel
126 103 *
127 - * @api
128 104 * @since 0.6
129 105 *
130 106 * @param string $name a unique name for the string
131 107 * @param string $string the string to register
@@ -131,9 +107,9 @@
131 107 * @param string $string the string to register
132 108 * @param string $context optional the group in which the string is registered, defaults to 'polylang'
133 109 * @param bool $multiline optional whether the string table should display a multiline textarea or a single line input, defaults to single line
134 110 */
135 -function pll_register_string( $name, $string, $context = 'Polylang', $multiline = false ) {
111 +function pll_register_string( $name, $string, $context = 'polylang', $multiline = false ) {
136 112 if ( PLL() instanceof PLL_Admin_Base ) {
137 113 PLL_Admin_Strings::register_string( $name, $string, $context, $multiline );
138 114 }
139 115 }
@@ -140,9 +116,8 @@
140 116
141 117 /**
142 118 * Translates a string ( previously registered with pll_register_string )
143 119 *
144 - * @api
145 120 * @since 0.6
146 121 *
147 122 * @param string $string the string to translate
148 123 * @return string the string translation in the current language
@@ -153,9 +128,8 @@
153 128
154 129 /**
155 130 * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output.
156 131 *
157 - * @api
158 132 * @since 2.1
159 133 *
160 134 * @param string $string the string to translate
161 135 * @return string translation in the current language
@@ -166,9 +140,8 @@
166 140
167 141 /**
168 142 * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes.
169 143 *
170 - * @api
171 144 * @since 2.1
172 145 *
173 146 * @param string $string The string to translate
174 147 * @return string
@@ -180,9 +153,8 @@
180 153 /**
181 154 * Echoes a translated string ( previously registered with pll_register_string )
182 155 * It is an equivalent of _e() and is not escaped.
183 156 *
184 - * @api
185 157 * @since 0.6
186 158 *
187 159 * @param string $string The string to translate
188 160 */
@@ -192,9 +164,8 @@
192 164
193 165 /**
194 166 * Echoes a translated string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output.
195 167 *
196 - * @api
197 168 * @since 2.1
198 169 *
199 170 * @param string $string The string to translate
200 171 */
@@ -204,9 +175,8 @@
204 175
205 176 /**
206 177 * Echoes a translated a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes.
207 178 *
208 - * @api
209 179 * @since 2.1
210 180 *
211 181 * @param string $string The string to translate
212 182 */
@@ -216,9 +186,8 @@
216 186
217 187 /**
218 188 * Translates a string ( previously registered with pll_register_string )
219 189 *
220 - * @api
221 190 * @since 1.5.4
222 191 *
223 192 * @param string $string the string to translate
224 193 * @param string $lang language code
@@ -250,9 +219,8 @@
250 219
251 220 /**
252 221 * Returns true if Polylang manages languages and translations for this post type
253 222 *
254 - * @api
255 223 * @since 1.0.1
256 224 *
257 225 * @param string $post_type Post type name
258 226 * @return bool
@@ -263,9 +231,8 @@
263 231
264 232 /**
265 233 * Returns true if Polylang manages languages and translations for this taxonomy
266 234 *
267 - * @api
268 235 * @since 1.0.1
269 236 *
270 237 * @param string $tax Taxonomy name
271 238 * @return bool
@@ -281,9 +248,8 @@
281 248 *
282 249 * hide_empty => hides languages with no posts if set to true ( defaults to false )
283 250 * fields => return only that field if set ( see PLL_Language for a list of fields )
284 251 *
285 - * @api
286 252 * @since 1.5
287 253 *
288 254 * @param array $args list of parameters
289 255 * @return array
@@ -295,9 +261,8 @@
295 261
296 262 /**
297 263 * Set the post language
298 264 *
299 - * @api
300 265 * @since 1.5
301 266 *
302 267 * @param int $id post id
303 268 * @param string $lang language code
@@ -308,9 +273,8 @@
308 273
309 274 /**
310 275 * Set the term language
311 276 *
312 - * @api
313 277 * @since 1.5
314 278 *
315 279 * @param int $id term id
316 280 * @param string $lang language code
@@ -321,9 +285,8 @@
321 285
322 286 /**
323 287 * Save posts translations
324 288 *
325 - * @api
326 289 * @since 1.5
327 290 *
328 291 * @param array $arr an associative array of translations with language code as key and post id as value
329 292 */
@@ -333,9 +296,8 @@
333 296
334 297 /**
335 298 * Save terms translations
336 299 *
337 - * @api
338 300 * @since 1.5
339 301 *
340 302 * @param array $arr an associative array of translations with language code as key and term id as value
341 303 */
@@ -345,9 +307,8 @@
345 307
346 308 /**
347 309 * Returns the post language
348 310 *
349 - * @api
350 311 * @since 1.5.4
351 312 *
352 313 * @param int $post_id
353 314 * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
@@ -359,9 +320,8 @@
359 320
360 321 /**
361 322 * Returns the term language
362 323 *
363 - * @api
364 324 * @since 1.5.4
365 325 *
366 326 * @param int $term_id
367 327 * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
@@ -373,9 +333,8 @@
373 333
374 334 /**
375 335 * Returns an array of translations of a post
376 336 *
377 - * @api
378 337 * @since 1.8
379 338 *
380 339 * @param int $post_id
381 340 * @return array an associative array of translations with language code as key and translation post_id as value
@@ -386,9 +345,8 @@
386 345
387 346 /**
388 347 * Returns an array of translations of a term
389 348 *
390 - * @api
391 349 * @since 1.8
392 350 *
393 351 * @param int $term_id
394 352 * @return array an associative array of translations with language code as key and translation term_id as value
@@ -399,14 +357,13 @@
399 357
400 358 /**
401 359 * Count posts in a language
402 360 *
403 - * @api
404 361 * @since 1.5
405 362 *
406 - * @param string $lang Language code.
407 - * @param array $args WP_Query arguments ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format, post_status ).
408 - * @return int Posts count.
363 + * @param string $lang language code
364 + * @param array $args ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format )
365 + * @return int posts count
409 366 */
410 367 function pll_count_posts( $lang, $args = array() ) {
411 368 return PLL()->model->count_posts( PLL()->model->get_language( $lang ), $args );
412 369 }