Changeset 5478
- Timestamp:
- 05/04/2017 05:11:49 PM (9 years ago)
- Location:
- sites/trunk/api.wordpress.org/public_html/events/1.0
- Files:
-
- 2 edited
-
index.php (modified) (2 diffs)
-
tests/test-index.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r5462 r5478 398 398 } 399 399 400 $country_code = null; 401 if ( ! $location && ( isset( $args['locale'] ) && preg_match( '/^[a-z]+[-_]([a-z]+)$/i', $args['locale'], $match ) ) ) { 402 $country_code = $match[1]; 403 } 400 $country_code = get_country_code_from_locale( $args['locale'] ?? '' ); 404 401 405 402 // Coordinates provided … … 492 489 wp_cache_set( $cache_key, $location, $cache_group, $cache_life ); 493 490 return $location; 491 } 492 493 /** 494 * Extract the country code from the given locale 495 * 496 * @param string $locale 497 * 498 * @return string|null 499 */ 500 function get_country_code_from_locale( $locale ) { 501 /* 502 * `en_US` is ignored, because it's the default locale in Core, and many users never set it. That 503 * leads to a lot of false-positives; e.g., Hampton-Sydney, Virginia, USA instead of Sydney, Australia. 504 */ 505 if ( empty( $locale ) || 'en_US' === $locale ) { 506 return null; 507 } 508 509 preg_match( '/^[a-z]+[-_]([a-z]+)$/i', $locale, $match ); 510 511 $country_code = $match[1] ?? null; 512 513 return $country_code; 494 514 } 495 515 -
sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php
r5462 r5478 256 256 ), 257 257 258 // Many users never change the default `en_US` locale in Core 259 'city-oceania-with-en_US' => array( 260 'input' => array( 261 'location_name' => 'Sydney', 262 'locale' => 'en_US', 263 'timezone' => 'Australia/Sydney', 264 ), 265 'expected' => array( 266 'description' => 'sydney', 267 'latitude' => '-33.868', 268 'longitude' => '151.207', 269 'country' => 'AU', 270 ), 271 ), 272 258 273 'city-south-america' => array( 259 274 'input' => array(
Note: See TracChangeset
for help on using the changeset viewer.