| @@ -11,15 +11,8 @@ | ||
| 11 | 11 | * @since 1.2 |
| 12 | 12 | */ |
| 13 | 13 | class PLL_Settings extends PLL_Admin_Base { |
| 14 | 14 | /** |
| 15 | - * Name of the active module. | |
| 16 | - * | |
| 17 | - * @var string|null | |
| 18 | - */ | |
| 19 | - protected $active_tab; | |
| 20 | - | |
| 21 | - /** | |
| 22 | 15 | * Array of modules classes. |
| 23 | 16 | * |
| 24 | 17 | * @var PLL_Settings_Module[]|null |
| 25 | 18 | */ |
| @@ -34,12 +27,8 @@ | ||
| 34 | 27 | */ |
| 35 | 28 | public function __construct( &$links_model ) { |
| 36 | 29 | parent::__construct( $links_model ); |
| 37 | 30 | |
| 38 | - if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 39 | - $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( sanitize_key( $_GET['page'] ), 6 ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 40 | - } | |
| 41 | - | |
| 42 | 31 | PLL_Admin_Strings::init(); |
| 43 | 32 | |
| 44 | 33 | add_action( 'admin_init', array( $this, 'register_settings_modules' ) ); |
| 45 | 34 | |
| @@ -275,9 +264,15 @@ | ||
| 275 | 264 | * |
| 276 | 265 | * @return void |
| 277 | 266 | */ |
| 278 | 267 | public function languages_page() { |
| 279 | - switch ( $this->active_tab ) { | |
| 268 | + if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 269 | + return; // Should not happen. | |
| 270 | + } | |
| 271 | + | |
| 272 | + $active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( sanitize_key( $_GET['page'] ), 6 ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 273 | + | |
| 274 | + switch ( $active_tab ) { | |
| 280 | 275 | case 'lang': |
| 281 | 276 | // Prepare the list table of languages |
| 282 | 277 | $list_table = new PLL_Table_Languages(); |
| 283 | 278 | $list_table->prepare_items( $this->model->get_languages_list() ); |
| @@ -297,11 +292,10 @@ | ||
| 297 | 292 | } elseif ( ! empty( $action ) ) { |
| 298 | 293 | $this->handle_actions( $action ); |
| 299 | 294 | } |
| 300 | 295 | |
| 301 | - // Displays the page | |
| 302 | - $modules = $this->modules; | |
| 303 | - $active_tab = $this->active_tab; | |
| 296 | + // Displays the page. | |
| 297 | + $modules = $this->modules; | |
| 304 | 298 | include __DIR__ . '/view-languages.php'; |
| 305 | 299 | } |
| 306 | 300 | |
| 307 | 301 | /** |
| @@ -361,9 +355,9 @@ | ||
| 361 | 355 | exit; |
| 362 | 356 | } |
| 363 | 357 | |
| 364 | 358 | /** |
| 365 | - * Get the list of predefined languages | |
| 359 | + * Get the list of predefined languages. | |
| 366 | 360 | * |
| 367 | 361 | * @since 2.3 |
| 368 | 362 | * |
| 369 | 363 | * @return string[][] { |
| @@ -385,12 +379,14 @@ | ||
| 385 | 379 | |
| 386 | 380 | $languages = include __DIR__ . '/languages.php'; |
| 387 | 381 | $translations = wp_get_available_translations(); |
| 388 | 382 | |
| 389 | - // Keep only languages with existing WP language pack | |
| 390 | - // Unless the transient has expired and we don't have an internet connection to refresh it | |
| 383 | + /* | |
| 384 | + * Keep only languages with existing WP language pack | |
| 385 | + * unless the transient has expired and we don't have an internet connection to refresh it. | |
| 386 | + */ | |
| 391 | 387 | if ( ! empty( $translations ) ) { |
| 392 | - $translations['en_US'] = ''; // Languages packs don't include en_US | |
| 388 | + $translations['en_US'] = ''; // Languages packs don't include en_US. | |
| 393 | 389 | $languages = array_intersect_key( $languages, $translations ); |
| 394 | 390 | } |
| 395 | 391 | |
| 396 | 392 | /** |
| @@ -404,9 +400,9 @@ | ||
| 404 | 400 | * @param array $languages |
| 405 | 401 | */ |
| 406 | 402 | $languages = apply_filters( 'pll_predefined_languages', $languages ); |
| 407 | 403 | |
| 408 | - // Keep only languages with all necessary information | |
| 404 | + // Keep only languages with all necessary information. | |
| 409 | 405 | foreach ( $languages as $k => $lang ) { |
| 410 | 406 | if ( ! isset( $lang['code'], $lang['locale'], $lang['name'], $lang['dir'], $lang['flag'] ) ) { |
| 411 | 407 | unset( $languages[ $k ] ); |
| 412 | 408 | } |
| @@ -412,6 +408,29 @@ | ||
| 412 | 408 | } |
| 413 | 409 | } |
| 414 | 410 | |
| 415 | 411 | return $languages; |
| 412 | + } | |
| 413 | + | |
| 414 | + /** | |
| 415 | + * Get the list of the default flags, sorted by alphabetical order. | |
| 416 | + * | |
| 417 | + * @since 3.9 | |
| 418 | + * | |
| 419 | + * @return string[] | |
| 420 | + */ | |
| 421 | + public static function get_default_flags() { | |
| 422 | + $flags = include __DIR__ . '/flags.php'; | |
| 423 | + | |
| 424 | + if ( ! class_exists( 'Collator' ) ) { | |
| 425 | + asort( $flags ); | |
| 426 | + return $flags; | |
| 427 | + } | |
| 428 | + | |
| 429 | + $co = Collator::create( get_user_locale() ); | |
| 430 | + if ( $co ) { | |
| 431 | + $co->asort( $flags ); | |
| 432 | + } | |
| 433 | + | |
| 434 | + return $flags; | |
| 416 | 435 | } |
| 417 | 436 | } |