Advertisement
BakerMan

Adding Additional Fields (Events Calendar PRO)

Aug 30th, 2012
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. function addCustomField($label, $type = 'text', $default = '') {
  2.     $customFields = tribe_get_option('custom-fields');
  3.     $fieldExists = false;
  4.  
  5.     // Check in case the "new" custom field is already present
  6.     foreach ($customFields as $field) {
  7.         if ($field['label'] === $label)
  8.             $fieldExists = true;
  9.     }
  10.  
  11.     // If it is not, add it
  12.     if ($fieldExists === false) {
  13.         $index = count($customFields) + 1;
  14.  
  15.         $customFields[] = array(
  16.             'name' => "_ecp_custom_$index",
  17.             'label' => $label,
  18.             'type' => $type,
  19.             'values' => $default
  20.         );
  21.  
  22.         tribe_update_option('custom-fields', $customFields);
  23.     }
  24. }
  25.  
  26.  
  27. addCustomField('Past and present members of Star Trek in attendance');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement