| @@ -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 | * |
| @@ -20,9 +17,8 @@ | ||
| 20 | 17 | * post_id => if not null, link to translations of post defined by post_id, defaults to null |
| 21 | 18 | * raw => set this to true to build your own custom language switcher, defaults to 0 |
| 22 | 19 | * item_spacing => whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to preserve |
| 23 | 20 | * |
| 24 | - * @api | |
| 25 | 21 | * @since 0.5 |
| 26 | 22 | * |
| 27 | 23 | * @param array $args optional |
| 28 | 24 | * @return null|string|array null if displaying, array if raw is requested, string otherwise |
| @@ -28,9 +24,9 @@ | ||
| 28 | 24 | * @return null|string|array null if displaying, array if raw is requested, string otherwise |
| 29 | 25 | */ |
| 30 | 26 | function pll_the_languages( $args = '' ) { |
| 31 | 27 | if ( PLL() instanceof PLL_Frontend ) { |
| 32 | - $switcher = new PLL_Switcher(); | |
| 28 | + $switcher = new PLL_Switcher; | |
| 33 | 29 | return $switcher->the_languages( PLL()->links, $args ); |
| 34 | 30 | } |
| 35 | 31 | return ''; |
| 36 | 32 | } |
| @@ -38,18 +34,14 @@ | ||
| 38 | 34 | /** |
| 39 | 35 | * Returns the current language on frontend |
| 40 | 36 | * Returns the language set in admin language filter on backend ( false if set to all languages ) |
| 41 | 37 | * |
| 42 | - * @api | |
| 43 | 38 | * @since 0.8.1 |
| 44 | 39 | * |
| 45 | - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug', pass OBJECT constant to get the language object. | |
| 46 | - * @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 | |
| 47 | 42 | */ |
| 48 | 43 | function pll_current_language( $field = 'slug' ) { |
| 49 | - if ( OBJECT === $field ) { | |
| 50 | - return PLL()->curlang; | |
| 51 | - } | |
| 52 | 44 | return isset( PLL()->curlang->$field ) ? PLL()->curlang->$field : false; |
| 53 | 45 | } |
| 54 | 46 | |
| 55 | 47 | /** |
| @@ -54,31 +46,20 @@ | ||
| 54 | 46 | |
| 55 | 47 | /** |
| 56 | 48 | * Returns the default language |
| 57 | 49 | * |
| 58 | - * @api | |
| 59 | 50 | * @since 1.0 |
| 60 | 51 | * |
| 61 | - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug', pass OBJECT constant to get the language object. | |
| 62 | - * @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 | |
| 63 | 54 | */ |
| 64 | 55 | function pll_default_language( $field = 'slug' ) { |
| 65 | - if ( isset( PLL()->options['default_lang'] ) ) { | |
| 66 | - $lang = PLL()->model->get_language( PLL()->options['default_lang'] ); | |
| 67 | - if ( $lang ) { | |
| 68 | - if ( OBJECT === $field ) { | |
| 69 | - return $lang; | |
| 70 | - } | |
| 71 | - return isset( $lang->$field ) ? $lang->$field : false; | |
| 72 | - } | |
| 73 | - } | |
| 74 | - return false; | |
| 56 | + return isset( PLL()->options['default_lang'] ) && ( $lang = PLL()->model->get_language( PLL()->options['default_lang'] ) ) && isset( $lang->$field ) ? $lang->$field : false; | |
| 75 | 57 | } |
| 76 | 58 | |
| 77 | 59 | /** |
| 78 | 60 | * Among the post and its translations, returns the id of the post which is in the language represented by $slug |
| 79 | 61 | * |
| 80 | - * @api | |
| 81 | 62 | * @since 0.5 |
| 82 | 63 | * |
| 83 | 64 | * @param int $post_id post id |
| 84 | 65 | * @param string $slug optional language code, defaults to current language |
| @@ -90,9 +71,8 @@ | ||
| 90 | 71 | |
| 91 | 72 | /** |
| 92 | 73 | * Among the term and its translations, returns the id of the term which is in the language represented by $slug |
| 93 | 74 | * |
| 94 | - * @api | |
| 95 | 75 | * @since 0.5 |
| 96 | 76 | * |
| 97 | 77 | * @param int $term_id term id |
| 98 | 78 | * @param string $slug optional language code, defaults to current language |
| @@ -104,9 +84,8 @@ | ||
| 104 | 84 | |
| 105 | 85 | /** |
| 106 | 86 | * Returns the home url in the current language |
| 107 | 87 | * |
| 108 | - * @api | |
| 109 | 88 | * @since 0.8 |
| 110 | 89 | * |
| 111 | 90 | * @param string $lang language code ( optional on frontend ) |
| 112 | 91 | * @return string |
| @@ -121,15 +100,14 @@ | ||
| 121 | 100 | |
| 122 | 101 | /** |
| 123 | 102 | * Registers a string for translation in the "strings translation" panel |
| 124 | 103 | * |
| 125 | - * @api | |
| 126 | 104 | * @since 0.6 |
| 127 | 105 | * |
| 128 | 106 | * @param string $name a unique name for the string |
| 129 | 107 | * @param string $string the string to register |
| 130 | 108 | * @param string $context optional the group in which the string is registered, defaults to 'polylang' |
| 131 | - * @param bool $multiline optional whether the string table should display a multiline textarea or a single line input, defaults to single line | |
| 109 | + * @param bool $multiline optional wether the string table should display a multiline textarea or a single line input, defaults to single line | |
| 132 | 110 | */ |
| 133 | 111 | function pll_register_string( $name, $string, $context = 'polylang', $multiline = false ) { |
| 134 | 112 | if ( PLL() instanceof PLL_Admin_Base ) { |
| 135 | 113 | PLL_Admin_Strings::register_string( $name, $string, $context, $multiline ); |
| @@ -138,9 +116,8 @@ | ||
| 138 | 116 | |
| 139 | 117 | /** |
| 140 | 118 | * Translates a string ( previously registered with pll_register_string ) |
| 141 | 119 | * |
| 142 | - * @api | |
| 143 | 120 | * @since 0.6 |
| 144 | 121 | * |
| 145 | 122 | * @param string $string the string to translate |
| 146 | 123 | * @return string the string translation in the current language |
| @@ -145,15 +122,14 @@ | ||
| 145 | 122 | * @param string $string the string to translate |
| 146 | 123 | * @return string the string translation in the current language |
| 147 | 124 | */ |
| 148 | 125 | function pll__( $string ) { |
| 149 | - return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; // PHPCS:ignore WordPress.WP.I18n | |
| 126 | + return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; | |
| 150 | 127 | } |
| 151 | 128 | |
| 152 | 129 | /** |
| 153 | 130 | * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output. |
| 154 | 131 | * |
| 155 | - * @api | |
| 156 | 132 | * @since 2.1 |
| 157 | 133 | * |
| 158 | 134 | * @param string $string the string to translate |
| 159 | 135 | * @return string translation in the current language |
| @@ -164,9 +140,8 @@ | ||
| 164 | 140 | |
| 165 | 141 | /** |
| 166 | 142 | * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes. |
| 167 | 143 | * |
| 168 | - * @api | |
| 169 | 144 | * @since 2.1 |
| 170 | 145 | * |
| 171 | 146 | * @param string $string The string to translate |
| 172 | 147 | * @return string |
| @@ -176,47 +151,42 @@ | ||
| 176 | 151 | } |
| 177 | 152 | |
| 178 | 153 | /** |
| 179 | 154 | * Echoes a translated string ( previously registered with pll_register_string ) |
| 180 | - * It is an equivalent of _e() and is not escaped. | |
| 181 | 155 | * |
| 182 | - * @api | |
| 183 | 156 | * @since 0.6 |
| 184 | 157 | * |
| 185 | 158 | * @param string $string The string to translate |
| 186 | 159 | */ |
| 187 | 160 | function pll_e( $string ) { |
| 188 | - echo pll__( $string ); // phpcs:ignore | |
| 161 | + echo pll__( $string ); | |
| 189 | 162 | } |
| 190 | 163 | |
| 191 | 164 | /** |
| 192 | 165 | * Echoes a translated string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output. |
| 193 | 166 | * |
| 194 | - * @api | |
| 195 | 167 | * @since 2.1 |
| 196 | 168 | * |
| 197 | 169 | * @param string $string The string to translate |
| 198 | 170 | */ |
| 199 | 171 | function pll_esc_html_e( $string ) { |
| 200 | - echo pll_esc_html__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 172 | + echo pll_esc_html__( $string ); | |
| 201 | 173 | } |
| 202 | 174 | |
| 203 | 175 | /** |
| 204 | 176 | * Echoes a translated a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes. |
| 205 | 177 | * |
| 206 | - * @api | |
| 207 | 178 | * @since 2.1 |
| 208 | 179 | * |
| 209 | 180 | * @param string $string The string to translate |
| 210 | 181 | */ |
| 211 | 182 | function pll_esc_attr_e( $string ) { |
| 212 | - echo pll_esc_attr__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 183 | + echo pll_esc_attr__( $string ); | |
| 213 | 184 | } |
| 214 | 185 | |
| 215 | 186 | /** |
| 216 | 187 | * Translates a string ( previously registered with pll_register_string ) |
| 217 | 188 | * |
| 218 | - * @api | |
| 219 | 189 | * @since 1.5.4 |
| 220 | 190 | * |
| 221 | 191 | * @param string $string the string to translate |
| 222 | 192 | * @param string $lang language code |
| @@ -222,9 +192,9 @@ | ||
| 222 | 192 | * @param string $lang language code |
| 223 | 193 | * @return string the string translation in the requested language |
| 224 | 194 | */ |
| 225 | 195 | function pll_translate_string( $string, $lang ) { |
| 226 | - if ( PLL() instanceof PLL_Frontend && pll_current_language() == $lang ) { | |
| 196 | + if ( pll_current_language() == $lang ) { | |
| 227 | 197 | return pll__( $string ); |
| 228 | 198 | } |
| 229 | 199 | |
| 230 | 200 | if ( ! is_scalar( $string ) ) { |
| @@ -248,9 +218,8 @@ | ||
| 248 | 218 | |
| 249 | 219 | /** |
| 250 | 220 | * Returns true if Polylang manages languages and translations for this post type |
| 251 | 221 | * |
| 252 | - * @api | |
| 253 | 222 | * @since 1.0.1 |
| 254 | 223 | * |
| 255 | 224 | * @param string $post_type Post type name |
| 256 | 225 | * @return bool |
| @@ -261,9 +230,8 @@ | ||
| 261 | 230 | |
| 262 | 231 | /** |
| 263 | 232 | * Returns true if Polylang manages languages and translations for this taxonomy |
| 264 | 233 | * |
| 265 | - * @api | |
| 266 | 234 | * @since 1.0.1 |
| 267 | 235 | * |
| 268 | 236 | * @param string $tax Taxonomy name |
| 269 | 237 | * @return bool |
| @@ -279,9 +247,8 @@ | ||
| 279 | 247 | * |
| 280 | 248 | * hide_empty => hides languages with no posts if set to true ( defaults to false ) |
| 281 | 249 | * fields => return only that field if set ( see PLL_Language for a list of fields ) |
| 282 | 250 | * |
| 283 | - * @api | |
| 284 | 251 | * @since 1.5 |
| 285 | 252 | * |
| 286 | 253 | * @param array $args list of parameters |
| 287 | 254 | * @return array |
| @@ -293,9 +260,8 @@ | ||
| 293 | 260 | |
| 294 | 261 | /** |
| 295 | 262 | * Set the post language |
| 296 | 263 | * |
| 297 | - * @api | |
| 298 | 264 | * @since 1.5 |
| 299 | 265 | * |
| 300 | 266 | * @param int $id post id |
| 301 | 267 | * @param string $lang language code |
| @@ -306,9 +272,8 @@ | ||
| 306 | 272 | |
| 307 | 273 | /** |
| 308 | 274 | * Set the term language |
| 309 | 275 | * |
| 310 | - * @api | |
| 311 | 276 | * @since 1.5 |
| 312 | 277 | * |
| 313 | 278 | * @param int $id term id |
| 314 | 279 | * @param string $lang language code |
| @@ -319,9 +284,8 @@ | ||
| 319 | 284 | |
| 320 | 285 | /** |
| 321 | 286 | * Save posts translations |
| 322 | 287 | * |
| 323 | - * @api | |
| 324 | 288 | * @since 1.5 |
| 325 | 289 | * |
| 326 | 290 | * @param array $arr an associative array of translations with language code as key and post id as value |
| 327 | 291 | */ |
| @@ -331,9 +295,8 @@ | ||
| 331 | 295 | |
| 332 | 296 | /** |
| 333 | 297 | * Save terms translations |
| 334 | 298 | * |
| 335 | - * @api | |
| 336 | 299 | * @since 1.5 |
| 337 | 300 | * |
| 338 | 301 | * @param array $arr an associative array of translations with language code as key and term id as value |
| 339 | 302 | */ |
| @@ -343,9 +306,8 @@ | ||
| 343 | 306 | |
| 344 | 307 | /** |
| 345 | 308 | * Returns the post language |
| 346 | 309 | * |
| 347 | - * @api | |
| 348 | 310 | * @since 1.5.4 |
| 349 | 311 | * |
| 350 | 312 | * @param int $post_id |
| 351 | 313 | * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug' |
| @@ -357,9 +319,8 @@ | ||
| 357 | 319 | |
| 358 | 320 | /** |
| 359 | 321 | * Returns the term language |
| 360 | 322 | * |
| 361 | - * @api | |
| 362 | 323 | * @since 1.5.4 |
| 363 | 324 | * |
| 364 | 325 | * @param int $term_id |
| 365 | 326 | * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug' |
| @@ -371,9 +332,8 @@ | ||
| 371 | 332 | |
| 372 | 333 | /** |
| 373 | 334 | * Returns an array of translations of a post |
| 374 | 335 | * |
| 375 | - * @api | |
| 376 | 336 | * @since 1.8 |
| 377 | 337 | * |
| 378 | 338 | * @param int $post_id |
| 379 | 339 | * @return array an associative array of translations with language code as key and translation post_id as value |
| @@ -384,9 +344,8 @@ | ||
| 384 | 344 | |
| 385 | 345 | /** |
| 386 | 346 | * Returns an array of translations of a term |
| 387 | 347 | * |
| 388 | - * @api | |
| 389 | 348 | * @since 1.8 |
| 390 | 349 | * |
| 391 | 350 | * @param int $term_id |
| 392 | 351 | * @return array an associative array of translations with language code as key and translation term_id as value |
| @@ -397,14 +356,13 @@ | ||
| 397 | 356 | |
| 398 | 357 | /** |
| 399 | 358 | * Count posts in a language |
| 400 | 359 | * |
| 401 | - * @api | |
| 402 | 360 | * @since 1.5 |
| 403 | 361 | * |
| 404 | - * @param string $lang Language code. | |
| 405 | - * @param array $args WP_Query arguments ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format, post_status ). | |
| 406 | - * @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 | |
| 407 | 365 | */ |
| 408 | 366 | function pll_count_posts( $lang, $args = array() ) { |
| 409 | 367 | return PLL()->model->count_posts( PLL()->model->get_language( $lang ), $args ); |
| 410 | 368 | } |
| @@ -415,7 +373,7 @@ | ||
| 415 | 373 | * Internal methods may be changed without prior notice |
| 416 | 374 | * |
| 417 | 375 | * @since 1.8 |
| 418 | 376 | */ |
| 419 | -function PLL() { // PHPCS:ignore WordPress.NamingConventions.ValidFunctionName | |
| 377 | +function PLL() { | |
| 420 | 378 | return $GLOBALS['polylang']; |
| 421 | 379 | } |