Tribe__Events__Importer__File_Importer_Venues::set_defaults( array $venue,  $record )

Set default venue values.

Note this will only set a value if it has been mapped, and it is empty. If you are using the importer to erase values, you should NOT be triggering this!


Parameters #

$venue

(array) (Required) The array of venue data we're modifying.

(array) (Required) <string,string> $record The event record from the import file. Only contains mapped values. Useful if value and key above don't appear to match what's expected. In the format [ mapped_key => value ].


Top ↑

Return #

(array) The modified venue data.


Top ↑

Source #

File: src/Tribe/Importer/File_Importer_Venues.php

	public function set_defaults( $venue, $record ) {
		$columns = [
			'Address'  => 'address',
			'City'     => 'city',
			'Country'  => 'country',
			'Phone'    => 'phone',
			'Province' => 'state',
			'State'    => 'state',
			'URL'      => 'url',
			'Zip'      => 'zip',
		];

		foreach ( $columns as $name => $key ) {
			// Only fill in empty columns that we're importing.
			if ( ! isset( $venue[ $name ] ) || ! empty( $venue[ $name ] ) ) {
				continue;
			}

			/**
			 * Allows filtering of default value before setting.
			 * Also allows setting a value (specifically for imports) by filter
			 * that is not set in the admin for manually-created venues.
			 *
			 * @since5.1.6
			 *
			 * @param string                $value  The default value as set in the admin "defaults" settings.
			 * @param string                $key    The mapped key for the value we'll be importing.
			 *                                      From the $columns array above,
			 *                                      this would be 'state' (the array "value"), for example.
			 * @param string                $name   The name for the value.
			 *                                      From the $columns array above,
			 *                                      this would be 'Province' (the array "key"), for example.
			 * @param array                 $venue  The entire array of venue data we're modifying.
			 *                                      In the format [ $key => $value ].
			 * @param array <string,string> $record The event record from the import file. Only contains mapped values.
			 *                                      Useful if value and key above don't appear to match what's expected.
			 *                                      In the format [ mapped_key => value ].
			 */
			$default_value = apply_filters(
				"tribe_events_importer_venue_default_{$key}_value",
				tribe_get_default_value( $key ),
				$key,
				$name,
				$venue,
				$record
			);

			/*
			 * Country comes through as an array: [ 'US', 'United States' ]
			 * We could handle this with a filter elsewhere, but let's deal with it here
			 * so we don't break Geolocation functions.
			 */
			if (
				'country' === $key
				&& is_array( $default_value )
			) {
				$default_value = array_pop( $default_value );
			}

			// Let's not set values that haven't been set in the admin!
			if ( empty( $default_value ) ) {
				continue;
			}

			$venue[ $name ] = $default_value;
		}

		return $venue;
	}