function addCustomField($label, $type = 'text', $default = '') { $customFields = tribe_get_option('custom-fields'); $fieldExists = false; // Check in case the "new" custom field is already present foreach ($customFields as $field) { if ($field['label'] === $label) $fieldExists = true; } // If it is not, add it if ($fieldExists === false) { $index = count($customFields) + 1; $customFields[] = array( 'name' => "_ecp_custom_$index", 'label' => $label, 'type' => $type, 'values' => $default ); tribe_update_option('custom-fields', $customFields); } } addCustomField('Past and present members of Star Trek in attendance');