PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
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 +36 -81 2.7.22.0.3 View file →
@@ -5,19 +5,18 @@
5 5 *
6 6 * List of parameters accepted in $args:
7 7 *
8 8 * dropdown => displays a dropdown if set to 1, defaults to 0
9 - * echo => echoes the switcher if set to 1 ( default )
9 + * echo => echoes the the switcher if set to 1 ( default )
10 10 * hide_if_empty => hides languages with no posts ( or pages ) if set to 1 ( default )
11 11 * show_flags => shows flags if set to 1, defaults to 0
12 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
13 + * display_names_as => whether to display the language name or code. valid options are 'slug' and 'name'
14 14 * force_home => forces linking to the home page is set to 1, defaults to 0
15 15 * hide_if_no_translation => hides the link if there is no translation if set to 1, defaults to 0
16 16 * hide_current => hides the current language if set to 1, defaults to 0
17 17 * post_id => if not null, link to translations of post defined by post_id, defaults to null
18 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
20 19 *
21 20 * @since 0.5
22 21 *
23 22 * @param array $args optional
@@ -24,9 +23,9 @@
24 23 * @return null|string|array null if displaying, array if raw is requested, string otherwise
25 24 */
26 25 function pll_the_languages( $args = '' ) {
27 26 if ( PLL() instanceof PLL_Frontend ) {
28 - $switcher = new PLL_Switcher();
27 + $switcher = new PLL_Switcher;
29 28 return $switcher->the_languages( PLL()->links, $args );
30 29 }
31 30 return '';
32 31 }
@@ -36,15 +35,12 @@
36 35 * Returns the language set in admin language filter on backend ( false if set to all languages )
37 36 *
38 37 * @since 0.8.1
39 38 *
40 - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug', pass OBJECT constant to get the language object.
41 - * @return string|PLL_Language|bool The requested field for the current language
39 + * @param string $field optional the language field to return 'name', 'locale', defaults to 'slug'
40 + * @return string|bool the requested field for the current language
42 41 */
43 42 function pll_current_language( $field = 'slug' ) {
44 - if ( OBJECT === $field ) {
45 - return PLL()->curlang;
46 - }
47 43 return isset( PLL()->curlang->$field ) ? PLL()->curlang->$field : false;
48 44 }
49 45
50 46 /**
@@ -51,22 +47,13 @@
51 47 * Returns the default language
52 48 *
53 49 * @since 1.0
54 50 *
55 - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug', pass OBJECT constant to get the language object.
56 - * @return string|PLL_Language|bool The requested field for the default language
51 + * @param string $field optional the language field to return 'name', 'locale', defaults to 'slug'
52 + * @return string the requested field for the default language
57 53 */
58 54 function pll_default_language( $field = 'slug' ) {
59 - if ( isset( PLL()->options['default_lang'] ) ) {
60 - $lang = PLL()->model->get_language( PLL()->options['default_lang'] );
61 - if ( $lang ) {
62 - if ( OBJECT === $field ) {
63 - return $lang;
64 - }
65 - return isset( $lang->$field ) ? $lang->$field : false;
66 - }
67 - }
68 - return false;
55 + return isset( PLL()->options['default_lang'] ) && ( $lang = PLL()->model->get_language( PLL()->options['default_lang'] ) ) && isset( $lang->$field ) ? $lang->$field : false;
69 56 }
70 57
71 58 /**
72 59 * Among the post and its translations, returns the id of the post which is in the language represented by $slug
@@ -117,9 +104,9 @@
117 104 *
118 105 * @param string $name a unique name for the string
119 106 * @param string $string the string to register
120 107 * @param string $context optional the group in which the string is registered, defaults to 'polylang'
121 - * @param bool $multiline optional whether the string table should display a multiline textarea or a single line input, defaults to single line
108 + * @param bool $multiline optional wether the string table should display a multiline textarea or a single line input, defaults to single line
122 109 */
123 110 function pll_register_string( $name, $string, $context = 'polylang', $multiline = false ) {
124 111 if ( PLL() instanceof PLL_Admin_Base ) {
125 112 PLL_Admin_Strings::register_string( $name, $string, $context, $multiline );
@@ -134,70 +121,38 @@
134 121 * @param string $string the string to translate
135 122 * @return string the string translation in the current language
136 123 */
137 124 function pll__( $string ) {
138 - return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; // PHPCS:ignore WordPress.WP.I18n
139 -}
125 + static $cache; // Cache object to avoid translating the same string several times
140 126
141 -/**
142 - * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output.
143 - *
144 - * @since 2.1
145 - *
146 - * @param string $string the string to translate
147 - * @return string translation in the current language
148 - */
149 -function pll_esc_html__( $string ) {
150 - return esc_html( pll__( $string ) );
151 -}
127 + if ( ! did_action( 'pll_language_defined' ) || ! is_scalar( $string ) ) { // No need for translation
128 + return $string;
129 + }
152 130
153 -/**
154 - * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes.
155 - *
156 - * @since 2.1
157 - *
158 - * @param string $string The string to translate
159 - * @return string
160 - */
161 -function pll_esc_attr__( $string ) {
162 - return esc_attr( pll__( $string ) );
131 + if ( empty( $cache ) ) {
132 + $cache = new PLL_Cache();
133 + }
134 +
135 + if ( false === $str = $cache->get( $string ) ) {
136 + $str = __( $string, 'pll_string' );
137 + $cache->set( $string, $str );
138 + }
139 +
140 + return $str;
163 141 }
164 142
165 143 /**
166 144 * Echoes a translated string ( previously registered with pll_register_string )
167 - * It is an equivalent of _e() and is not escaped.
168 145 *
169 146 * @since 0.6
170 147 *
171 - * @param string $string The string to translate
148 + * @param string $string the string to translate
172 149 */
173 150 function pll_e( $string ) {
174 - echo pll__( $string ); // phpcs:ignore
151 + echo pll__( $string );
175 152 }
176 153
177 154 /**
178 - * Echoes a translated string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output.
179 - *
180 - * @since 2.1
181 - *
182 - * @param string $string The string to translate
183 - */
184 -function pll_esc_html_e( $string ) {
185 - echo pll_esc_html__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput
186 -}
187 -
188 -/**
189 - * Echoes a translated a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes.
190 - *
191 - * @since 2.1
192 - *
193 - * @param string $string The string to translate
194 - */
195 -function pll_esc_attr_e( $string ) {
196 - echo pll_esc_attr__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput
197 -}
198 -
199 -/**
200 155 * Translates a string ( previously registered with pll_register_string )
201 156 *
202 157 * @since 1.5.4
203 158 *
@@ -205,9 +160,9 @@
205 160 * @param string $lang language code
206 161 * @return string the string translation in the requested language
207 162 */
208 163 function pll_translate_string( $string, $lang ) {
209 - if ( PLL() instanceof PLL_Frontend && pll_current_language() == $lang ) {
164 + if ( pll_current_language() == $lang ) {
210 165 return pll__( $string );
211 166 }
212 167
213 168 if ( ! is_scalar( $string ) ) {
@@ -233,9 +188,9 @@
233 188 * Returns true if Polylang manages languages and translations for this post type
234 189 *
235 190 * @since 1.0.1
236 191 *
237 - * @param string $post_type Post type name
192 + * @param string post type name
238 193 * @return bool
239 194 */
240 195 function pll_is_translated_post_type( $post_type ) {
241 196 return PLL()->model->is_translated_post_type( $post_type );
@@ -245,9 +200,9 @@
245 200 * Returns true if Polylang manages languages and translations for this taxonomy
246 201 *
247 202 * @since 1.0.1
248 203 *
249 - * @param string $tax Taxonomy name
204 + * @param string taxonomy name
250 205 * @return bool
251 206 */
252 207 function pll_is_translated_taxonomy( $tax ) {
253 208 return PLL()->model->is_translated_taxonomy( $tax );
@@ -322,10 +277,10 @@
322 277 *
323 278 * @since 1.5.4
324 279 *
325 280 * @param int $post_id
326 - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
327 - * @return bool|string The requested field for the post language, false if no language is associated to that post
281 + * @param string $field optional the language field to return 'name', 'locale', defaults to 'slug'
282 + * @return bool|string the requested field for the post language, false if no language is associated to that post
328 283 */
329 284 function pll_get_post_language( $post_id, $field = 'slug' ) {
330 285 return ( $lang = PLL()->model->post->get_language( $post_id ) ) ? $lang->$field : false;
331 286 }
@@ -335,10 +290,10 @@
335 290 *
336 291 * @since 1.5.4
337 292 *
338 293 * @param int $term_id
339 - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug'
340 - * @return bool|string The requested field for the term language, false if no language is associated to that term
294 + * @param string $field optional the language field to return 'name', 'locale', defaults to 'slug'
295 + * @return bool|string the requested field for the term language, false if no language is associated to that term
341 296 */
342 297 function pll_get_term_language( $term_id, $field = 'slug' ) {
343 298 return ( $lang = PLL()->model->term->get_language( $term_id ) ) ? $lang->$field : false;
344 299 }
@@ -371,11 +326,11 @@
371 326 * Count posts in a language
372 327 *
373 328 * @since 1.5
374 329 *
375 - * @param string $lang Language code.
376 - * @param array $args WP_Query arguments ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format, post_status ).
377 - * @return int Posts count.
330 + * @param string $lang language code
331 + * @param array $args ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format )
332 + * @return int posts count
378 333 */
379 334 function pll_count_posts( $lang, $args = array() ) {
380 335 return PLL()->model->count_posts( PLL()->model->get_language( $lang ), $args );
381 336 }
@@ -386,7 +341,7 @@
386 341 * Internal methods may be changed without prior notice
387 342 *
388 343 * @since 1.8
389 344 */
390 -function PLL() { // PHPCS:ignore WordPress.NamingConventions.ValidFunctionName
345 +function PLL() {
391 346 return $GLOBALS['polylang'];
392 347 }