Tribe__View_Helpers::constructCountries( string $postId = '', bool $useDefault = true )
Get the countries being used and available for the plugin.
Contents
Parameters
- $postId
-
(string) (Optional) The post ID.
Default value: ''
- $useDefault
-
(bool) (Optional) Should we use the defaults?
Default value: true
Return
(array) The countries array.
Source
File: src/Tribe/View_Helpers.php
public static function constructCountries( $postId = '', $useDefault = true ) { $eventCountries = tribe_get_option( 'tribeEventsCountries' ); if ( $eventCountries != '' ) { $countries = array(); $country_rows = explode( "\n", $eventCountries ); foreach ( $country_rows as $crow ) { $country = explode( ',', $crow ); if ( isset( $country[0] ) && isset( $country[1] ) ) { $country[0] = trim( $country[0] ); $country[1] = trim( $country[1] ); if ( $country[0] && $country[1] ) { $countries[ $country[0] ] = $country[1]; } } } } if ( ! isset( $countries ) || ! is_array( $countries ) || count( $countries ) < 1 ) { $countries = tribe( 'languages.locations' )->get_countries(); } // Perform a natural sort: this maintains the key -> index associations but ensures the countries // are in the expected order, even once translated natsort( $countries ); // Placeholder option ('Select a Country') first by default $select_country = array( '' => esc_html__( 'Select a Country:', 'tribe-common' ) ); $countries = $select_country + $countries; if ( ( $postId || $useDefault ) ) { $countryValue = get_post_meta( $postId, '_EventCountry', true ); if ( $countryValue ) { $defaultCountry = array( array_search( $countryValue, $countries ), $countryValue ); } else { $defaultCountry = tribe_get_default_value( 'country' ); } if ( $defaultCountry && $defaultCountry[0] != '' ) { $selectCountry = array_shift( $countries ); asort( $countries ); $countries = array( $defaultCountry[0] => $defaultCountry[1] ) + $countries; $countries = array( '' => $selectCountry ) + $countries; array_unique( $countries ); } return $countries; } else { return $countries; } }