cliffordp
5/2/2017 - 7:16 PM

MT - TEC PRO - Assign a default value for specific Additional Fields

MT - TEC PRO - Assign a default value for specific Additional Fields

<?php
/**
 * MT - TEC PRO - Display a default value for an Additional Field
 *
 * from https://gist.github.com/cliffordp/447bc4c3a3e8c9f4c3c5c3fbc1a1a9c6/
 * for https://theeventscalendar.com/support/forums/topic/making-extra-field-predefined/#post-1275732
 *
 * @return array
 */
function cliff_tec_pro_default_additional_field_values( $data ) {
	// NOTE: if an array key from $defaults does not exist in $data, it will still be inserted and therefore could give the appearance of creating a brand new Additional Field even if it doesn't exist at wp-admin > Events > Settings > Additional Fields tab.
	$defaults = array(
		'Additional Field Name'      => 'Custom default value here',
		'New Text Field for Testing' => 'APERTURA LOCALE (GIO-VEN-SAB ORE 19.30 / DOM ORE 18.00)INIZIO LIVE 22.00',
	);

	// avoid potential for odd error -- shouldn't happen
	if ( ! is_array( $data ) ) {
		return $data;
	}

	$new_data = array_merge( $defaults, $data );

	// Put the Additional Fields in alpha-order by their keys, not their values
	ksort( $new_data, SORT_NATURAL );

	return $new_data;
}

add_filter( 'tribe_get_custom_fields', 'cliff_tec_pro_default_additional_field_values' );