PluginProbe
Polylang / 2.5
Polylang v2.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
← All changes | include/api.php +25 -69 2.9.12.5 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
@@ -147,15 +122,14 @@
147 122 * @param string $string the string to translate
148 123 * @return string the string translation in the current language
149 124 */
150 125 function pll__( $string ) {
151 - return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; // PHPCS:ignore WordPress.WP.I18n
126 + return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; // PHPCS:ignore WordPress.WP.I18n.NonSingularStringLiteralText
152 127 }
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
@@ -178,47 +151,42 @@
178 151 }
179 152
180 153 /**
181 154 * Echoes a translated string ( previously registered with pll_register_string )
182 - * It is an equivalent of _e() and is not escaped.
183 155 *
184 - * @api
185 156 * @since 0.6
186 157 *
187 158 * @param string $string The string to translate
188 159 */
189 160 function pll_e( $string ) {
190 - echo pll__( $string ); // phpcs:ignore
161 + echo pll__( $string );
191 162 }
192 163
193 164 /**
194 165 * Echoes a translated string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output.
195 166 *
196 - * @api
197 167 * @since 2.1
198 168 *
199 169 * @param string $string The string to translate
200 170 */
201 171 function pll_esc_html_e( $string ) {
202 - echo pll_esc_html__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput
172 + echo pll_esc_html__( $string );
203 173 }
204 174
205 175 /**
206 176 * Echoes a translated a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes.
207 177 *
208 - * @api
209 178 * @since 2.1
210 179 *
211 180 * @param string $string The string to translate
212 181 */
213 182 function pll_esc_attr_e( $string ) {
214 - echo pll_esc_attr__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput
183 + echo pll_esc_attr__( $string );
215 184 }
216 185
217 186 /**
218 187 * Translates a string ( previously registered with pll_register_string )
219 188 *
220 - * @api
221 189 * @since 1.5.4
222 190 *
223 191 * @param string $string the string to translate
224 192 * @param string $lang language code
@@ -250,9 +218,8 @@
250 218
251 219 /**
252 220 * Returns true if Polylang manages languages and translations for this post type
253 221 *
254 - * @api
255 222 * @since 1.0.1
256 223 *
257 224 * @param string $post_type Post type name
258 225 * @return bool
@@ -263,9 +230,8 @@
263 230
264 231 /**
265 232 * Returns true if Polylang manages languages and translations for this taxonomy
266 233 *
267 - * @api
268 234 * @since 1.0.1
269 235 *
270 236 * @param string $tax Taxonomy name
271 237 * @return bool
@@ -281,9 +247,8 @@
281 247 *
282 248 * hide_empty => hides languages with no posts if set to true ( defaults to false )
283 249 * fields => return only that field if set ( see PLL_Language for a list of fields )
284 250 *
285 - * @api
286 251 * @since 1.5
287 252 *
288 253 * @param array $args list of parameters
289 254 * @return array
@@ -295,9 +260,8 @@
295 260
296 261 /**
297 262 * Set the post language
298 263 *
299 - * @api
300 264 * @since 1.5
301 265 *
302 266 * @param int $id post id
303 267 * @param string $lang language code
@@ -308,9 +272,8 @@
308 272
309 273 /**
310 274 * Set the term language
311 275 *
312 - * @api
313 276 * @since 1.5
314 277 *
315 278 * @param int $id term id
316 279 * @param string $lang language code
@@ -321,9 +284,8 @@
321 284
322 285 /**
323 286 * Save posts translations
324 287 *
325 - * @api
326 288 * @since 1.5
327 289 *
328 290 * @param array $arr an associative array of translations with language code as key and post id as value
329 291 */
@@ -333,9 +295,8 @@
333 295
334 296 /**
335 297 * Save terms translations
336 298 *
337 - * @api
338 299 * @since 1.5
339 300 *
340 301 * @param array $arr an associative array of translations with language code as key and term id as value
341 302 */
@@ -345,9 +306,8 @@
345 306
346 307 /**
347 308 * Returns the post language
348 309 *
349 - * @api
350 310 * @since 1.5.4
351 311 *
352 312 * @param int $post_id
353 313 * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
@@ -359,9 +319,8 @@
359 319
360 320 /**
361 321 * Returns the term language
362 322 *
363 - * @api
364 323 * @since 1.5.4
365 324 *
366 325 * @param int $term_id
367 326 * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
@@ -373,9 +332,8 @@
373 332
374 333 /**
375 334 * Returns an array of translations of a post
376 335 *
377 - * @api
378 336 * @since 1.8
379 337 *
380 338 * @param int $post_id
381 339 * @return array an associative array of translations with language code as key and translation post_id as value
@@ -386,9 +344,8 @@
386 344
387 345 /**
388 346 * Returns an array of translations of a term
389 347 *
390 - * @api
391 348 * @since 1.8
392 349 *
393 350 * @param int $term_id
394 351 * @return array an associative array of translations with language code as key and translation term_id as value
@@ -399,14 +356,13 @@
399 356
400 357 /**
401 358 * Count posts in a language
402 359 *
403 - * @api
404 360 * @since 1.5
405 361 *
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.
362 + * @param string $lang language code
363 + * @param array $args ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format )
364 + * @return int posts count
409 365 */
410 366 function pll_count_posts( $lang, $args = array() ) {
411 367 return PLL()->model->count_posts( PLL()->model->get_language( $lang ), $args );
412 368 }