/** Save the Event data meta box. **/ function eventon_save_meta_data($post_id, $post) { if ($post->post_type != 'ajde_events') { return; } // Stop WP from clearing custom fields on autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Prevent quick edit from clearing custom fields if (defined('DOING_AJAX') && DOING_AJAX) { return; } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['evo_noncename'])) { if (!wp_verify_nonce($_POST['evo_noncename'], plugin_basename(__FILE__))) { return; } } // Check permissions if (!current_user_can('edit_post', $post_id)) { return; } global $pagenow; $_allowed = array('post-new.php', 'post.php'); if (!in_array($pagenow, $_allowed)) { return; } // $_POST FIELDS array $fields_ar = apply_filters('eventon_event_metafields', array('evcal_allday', 'evcal_event_color', 'evcal_event_color_n', 'evcal_location', 'evcal_location_name', 'evo_location_tax', 'evo_loc_img', 'evo_org_img', 'evcal_name_over_img', 'evcal_organizer', 'evcal_org_contact', 'evcal_org_img', 'evcal_org_exlink', 'evcal_exlink', 'evcal_lmlink', 'evcal_subtitle', 'evcal_gmap_gen', 'evcal_mu_id', 'evcal_paypal_item_price', 'evcal_paypal_text', 'evcal_paypal_email', 'evcal_repeat', 'evcal_rep_freq', 'evcal_rep_gap', 'evcal_rep_num', 'evp_repeat_rb', 'evo_repeat_wom', 'evo_rep_WK', 'evcal_lmlink_target', '_evcal_exlink_target', '_evcal_exlink_option', 'evo_hide_endtime', 'evo_span_hidden_end', 'evo_year_long', 'event_year', 'evo_evcrd_field_org', 'evo_event_timezone', 'evo_exclude_ev', '_featured', '_cancel', '_cancel_reason', '_onlyloggedin', 'evcal_lat', 'evcal_lon')); // append custom fields based on activated number $evcal_opt1 = get_option('evcal_options_evcal_1'); $num = evo_calculate_cmd_count($evcal_opt1); for ($x = 1; $x <= $num; $x++) { if (eventon_is_custom_meta_field_good($x)) { $fields_ar[] = '_evcal_ec_f' . $x . 'a1_cus'; $fields_ar[] = '_evcal_ec_f' . $x . 'a1_cusL'; $fields_ar[] = '_evcal_ec_f' . $x . '_onw'; } } // field names that pertains only to event date information $fields_sub_ar = apply_filters('eventon_event_date_metafields', array('evcal_start_date', 'evcal_end_date', 'evcal_start_time_hour', 'evcal_start_time_min', 'evcal_st_ampm', 'evcal_end_time_hour', 'evcal_end_time_min', 'evcal_et_ampm', 'evcal_allday')); // DATE and TIME data $date_POST_values = ''; foreach ($fields_sub_ar as $ff) { // end date value fix for -- hide end date if ($ff == 'evcal_end_date' && !empty($_POST['evo_hide_endtime']) && $_POST['evo_hide_endtime'] == 'yes') { if ($_POST['evo_span_hidden_end'] && $_POST['evo_span_hidden_end'] == 'yes') { $date_POST_values['evcal_end_date'] = $_POST['evcal_end_date']; } else { $date_POST_values['evcal_end_date'] = $_POST['evcal_start_date']; } //$date_POST_values['evcal_end_date']=$_POST['evcal_end_date']; } else { if (!empty($_POST[$ff])) { $date_POST_values[$ff] = $_POST[$ff]; } } // remove these values from previously saved delete_post_meta($post_id, $ff); } // convert the post times into proper unix time stamps if (!empty($_POST['_evo_date_format']) && !empty($_POST['_evo_time_format'])) { $proper_time = eventon_get_unix_time($date_POST_values, $_POST['_evo_date_format'], $_POST['_evo_time_format']); } // if Repeating event save repeating intervals if (eventon_is_good_repeat_data() && !empty($proper_time['unix_start'])) { $unix_E = !empty($proper_time['unix_end']) ? $proper_time['unix_end'] : $proper_time['unix_start']; $repeat_intervals = eventon_get_repeat_intervals($proper_time['unix_start'], $unix_E); // save repeat interval array as post meta if (!empty($repeat_intervals)) { asort($repeat_intervals); update_post_meta($post_id, 'repeat_intervals', $repeat_intervals); } } //update_post_meta($post_id, 'aaa', $_POST['repeat_intervals']); // run through all the custom meta fields foreach ($fields_ar as $f_val) { if (!empty($_POST[$f_val])) { $post_value = $_POST[$f_val]; update_post_meta($post_id, $f_val, $post_value); // ux val for single events linking to event page if ($f_val == 'evcal_exlink' && $_POST['_evcal_exlink_option'] == '4') { update_post_meta($post_id, 'evcal_exlink', get_permalink($post_id)); } } else { if (defined('DOING_AUTOSAVE') && !DOING_AUTOSAVE) { // if the meta value is set to empty, then delete that meta value delete_post_meta($post_id, $f_val); } delete_post_meta($post_id, $f_val); } } // full time converted to unix time stamp if (!empty($proper_time['unix_start'])) { update_post_meta($post_id, 'evcal_srow', $proper_time['unix_start']); } if (!empty($proper_time['unix_end'])) { update_post_meta($post_id, 'evcal_erow', $proper_time['unix_end']); } // save event year if not set if (empty($_POST['event_year']) && !empty($proper_time['unix_start']) || !empty($_POST['event_year']) && $_POST['event_year'] == 'yes') { $year = date('Y', $proper_time['unix_start']); update_post_meta($post_id, 'event_year', $year); } //set event color code to 1 for none select colors if (!isset($_POST['evcal_event_color_n'])) { update_post_meta($post_id, 'evcal_event_color_n', 1); } // save featured event data default value no $_featured = get_post_meta($post_id, '_featured', true); if (empty($_featured)) { update_post_meta($post_id, '_featured', 'no'); } // LOCATION as taxonomy // if location name is choosen from the list if (isset($_POST['evcal_location_name_select'], $_POST['evcal_location_name']) && $_POST['evcal_location_name_select'] == $_POST['evcal_location_name']) { // if (!empty($_POST['evo_location_tax_id'])) { $term_name = esc_attr($_POST['evcal_location_name']); $term_meta = array(); $term_meta['location_lon'] = isset($_POST['evcal_lon']) ? $_POST['evcal_lon'] : null; $term_meta['location_lat'] = isset($_POST['evcal_lat']) ? $_POST['evcal_lat'] : null; $term_meta['location_address'] = isset($_POST['evcal_location']) ? $_POST['evcal_location'] : null; $term_meta['evo_loc_img'] = isset($_POST['evo_loc_img']) ? $_POST['evo_loc_img'] : null; update_option("taxonomy_" . $_POST['evo_location_tax_id'], $term_meta); wp_set_post_terms($post_id, $term_name, 'event_location'); } } elseif (isset($_POST['evcal_location_name'])) { // create new taxonomy from new values $term_name = esc_attr($_POST['evcal_location_name']); $term_slug = str_replace(" ", "-", $term_name); // create wp term $new_term_ = wp_insert_term($term_name, 'event_location', array('slug' => $term_slug)); if (!is_wp_error($new_term_)) { $term_meta = array(); $term_meta['location_lon'] = isset($_POST['evcal_lon']) ? $_POST['evcal_lon'] : null; $term_meta['location_lat'] = isset($_POST['evcal_lat']) ? $_POST['evcal_lat'] : null; $term_meta['location_address'] = isset($_POST['evcal_location']) ? $_POST['evcal_location'] : null; $term_meta['evo_loc_img'] = isset($_POST['evo_loc_img']) ? $_POST['evo_loc_img'] : null; update_option("taxonomy_" . $new_term_['term_id'], $term_meta); wp_set_post_terms($post_id, $term_name, 'event_location'); } } // ORGANIZER as taxonomy // Selected value from list - update other values if (isset($_POST['evcal_organizer_name_select'], $_POST['evcal_organizer']) && $_POST['evcal_organizer_name_select'] == $_POST['evcal_organizer']) { if (!empty($_POST['evo_organizer_tax_id'])) { $term_name = esc_attr($_POST['evcal_organizer']); $term_meta = array(); $term_meta['evcal_org_contact'] = isset($_POST['evcal_org_contact']) ? str_replace('"', "'", $_POST['evcal_org_contact']) : null; $term_meta['evo_org_img'] = isset($_POST['evo_org_img']) ? $_POST['evo_org_img'] : null; $term_meta['evcal_org_exlink'] = isset($_POST['evcal_org_exlink']) ? $_POST['evcal_org_exlink'] : null; update_option("taxonomy_" . $_POST['evo_organizer_tax_id'], $term_meta); wp_set_post_terms($post_id, $term_name, 'event_organizer'); } } elseif (isset($_POST['evcal_organizer'])) { // create new taxonomy from new values $term_name = esc_attr($_POST['evcal_organizer']); $term_slug = str_replace(" ", "-", $term_name); // create wp term $new_term_ = wp_insert_term($term_name, 'event_organizer', array('slug' => $term_slug)); if (!is_wp_error($new_term_)) { $term_meta = array(); $term_meta['evcal_org_contact'] = isset($_POST['evcal_org_contact']) ? str_replace('"', "'", $_POST['evcal_org_contact']) : null; $term_meta['evo_org_img'] = isset($_POST['evo_org_img']) ? $_POST['evo_org_img'] : null; $term_meta['evcal_org_exlink'] = isset($_POST['evcal_org_exlink']) ? $_POST['evcal_org_exlink'] : null; update_option("taxonomy_" . $new_term_['term_id'], $term_meta); wp_set_post_terms($post_id, $term_name, 'event_organizer'); } } // (---) hook for addons do_action('eventon_save_meta', $fields_ar, $post_id); // save user closed meta field boxes if (!empty($_POST['evo_collapse_meta_boxes'])) { eventon_save_collapse_metaboxes($post_id, $_POST['evo_collapse_meta_boxes'], true); } }
public function au_form_fields($var = '') { $evcal_opt = $this->options; /* structure = 0=>name, 1=> var, 2=> field type, 3=>placeholder, 4=>lang var, 5=> required or not, 6=>special name for settings */ $event_fields = array('event_name' => array('Event Name', 'event_name', 'title', '', 'evoAUL_evn'), 'event_subtitle' => array('Event Sub Title', 'evcal_subtitle', 'text', '', 'evoAUL_est'), 'event_description' => array('Event Details', 'event_description', 'textarea', '', 'evcal_evcard_details_au'), 'event_start_date' => array('Event Start Date/Time', 'evcal_start_date', 'startdate', '', 'evoAUL_esdt'), 'event_end_date' => array('Event End Date/Time', 'event_end_date', 'enddate', '', 'evoAUL_eedt'), 'event_allday' => array('All Day', 'event_allday', 'allday', '', ''), 'event_location_name' => array('Event Location Name', 'evcal_location_name', 'text', '', 'evoAUL_lca'), 'event_location' => array('Event Location Address', 'evcal_location', 'text', '', 'evoAUL_ln'), 'event_location_cord' => array('Event Location Coordinates (lat,lon Seperated by comma)', 'event_location_cord', 'text', '', 'evoAUL_lcor'), 'event_color' => array('Event Color', 'evcal_event_color', 'color', '', 'evoAUL_ec'), 'event_organizer' => array('Event Organizer', 'evcal_organizer', 'text', '', 'evoAUL_eo'), 'event_org_contact' => array('Event Organizer Contact Information', 'evcal_org_contact', 'text', '', 'evoAUL_eoc'), 'learnmorelink' => array('Learn More Link', 'evcal_lmlink', 'text', '', 'evoAUL_lml')); // event type categories $ett_verify = $this->tax_count; $_tax_names_array = $this->tax_names; for ($x = 1; $x < $ett_verify + 1; $x++) { $ab = $x == 1 ? '' : '_' . $x; $__tax_name = $_tax_names_array[$x]; $event_fields['event_type' . $ab] = array('Select the ' . $__tax_name . ' Category', 'event_type' . $ab, 'tax', '', 'evoAUL_stet' . $x); } $event_fields_1 = array('event_image' => array('Event Image', 'event_image', 'image', '', 'evoAUL_ei'), 'yourname' => array('Your Full Name', 'yourname', 'text', '', 'evoAUL_fn', 'req'), 'youremail' => array('Your Email Address', 'youremail', 'text', '', 'evoAUL_ea', 'req'), 'user_interaction' => array('User Interaction', 'uinter', 'uiselect', '', 'evoAUL_ui'), 'event_captcha' => array('Form Human Submission Validation', 'evcal_captcha', 'captcha', '', 'evoAUL_cap'), 'event_additional' => array('Additonal Private Notes', 'evcalau_notes', 'textarea', '', 'evoAU_add', '', 'Additional private notes for admin'), 'event_html' => array('** Additonal HTML Field', 'evoau_html', 'html')); $event_fields = array_merge($event_fields, $event_fields_1); // get custom meta fields for $custom_field_count = evo_calculate_cmd_count($evcal_opt); // get activated custom field count for ($x = 1; $x <= $custom_field_count; $x++) { $new_additions = ''; if (eventon_is_custom_meta_field_good($x, $evcal_opt)) { $index = 'evo_customfield_' . $x; $_variable_name = '_evcal_ec_f' . $x . 'a1_cus'; $_field_name = $evcal_opt['evcal_ec_f' . $x . 'a1']; $content_type = $evcal_opt['evcal_ec_f' . $x . 'a2']; $new_additions[$index] = array($_field_name, $_variable_name, $content_type); $event_fields = array_merge($event_fields, $new_additions); } } // Filter for other additions $event_fields = apply_filters('evoau_form_fields', $event_fields); // return certain fields from above list if ($var == 'savefields') { unset($event_fields['event_name']); unset($event_fields['event_start_date']); unset($event_fields['event_end_date']); unset($event_fields['event_allday']); unset($event_fields['event_description']); unset($event_fields['yourname']); unset($event_fields['youremail']); unset($event_fields['event_captcha']); unset($event_fields['user_interaction']); unset($event_fields['event_location_cord']); unset($event_fields['event_color']); } if ($var == 'default') { $event_fields = array('event_name' => $event_fields['event_name'], 'event_start_date' => $event_fields['event_start_date'], 'event_end_date' => $event_fields['event_end_date'], 'event_allday' => $event_fields['event_allday']); } if ($var == 'additional') { unset($event_fields['event_name']); unset($event_fields['event_start_date']); unset($event_fields['event_end_date']); unset($event_fields['event_allday']); } if ($var == 'defaults_ar') { $event_fields = array('event_name', 'event_start_date', 'event_end_date', 'event_allday'); } return $event_fields; }