function wpcampus_convert_entry_to_post($entry, $form) { // If ID, get the entry if (is_numeric($entry) && $entry > 0) { $entry = GFAPI::get_entry($entry); } // If ID, get the form if (is_numeric($form) && $form > 0) { $form = GFAPI::get_form($form); } // Make sure we have some info if (!$entry || !$form) { return false; } // Set the entry id $entry_id = $entry['id']; // First, check to see if the entry has already been processed $entry_post = wpcampus_get_entry_post($entry_id); // If this entry has already been processed, then skip if ($entry_post && isset($entry_post->ID)) { return false; } // Fields to store in post meta // Names will be used dynamically when processing fields below $fields_to_store = array('name', 'involvement', 'sessions', 'event_time', 'email', 'status', 'employer', 'attend_preference', 'traveling_city', 'traveling_state', 'traveling_country', 'traveling_latitude', 'traveling_longitude', 'slack_invite', 'slack_email'); // Process one field at a time foreach ($form['fields'] as $field) { // Set the admin label $admin_label = strtolower(preg_replace('/\\s/i', '_', $field['adminLabel'])); // Only process if one of our fields // We need to process traveling_from but not store it in post meta which is why it's not in the array if (!in_array($admin_label, array_merge($fields_to_store, array('traveling_from')))) { continue; } // Process fields according to admin label switch ($admin_label) { case 'name': // Get name parts $first_name = null; $last_name = null; // Process each name part foreach ($field->inputs as $input) { $name_label = strtolower($input['label']); switch ($name_label) { case 'first': case 'last': ${$name_label . '_name'} = rgar($entry, $input['id']); break; } } // Build name to use when creating post $name = trim("{$first_name} {$last_name}"); break; case 'involvement': case 'sessions': case 'event_time': // Get all the input data and place in array ${$admin_label} = array(); foreach ($field->inputs as $input) { if ($this_data = rgar($entry, $input['id'])) { ${$admin_label}[] = $this_data; } } break; case 'traveling_from': // Get all the input data and place in array ${$admin_label} = array(); foreach ($field->inputs as $input) { // Create the data index $input_label = strtolower(preg_replace('/\\s/i', '_', preg_replace('/\\s\\/\\s/i', '_', $input['label']))); // Change to simply state if ('state_province' == $input_label) { $input_label = 'state'; } // Store data if ($this_data = rgar($entry, $input['id'])) { ${"traveling_{$input_label}"} = $this_data; } // Store all traveling data in an array ${$admin_label}[$input_label] = $this_data; } // Create string of traveling data $traveling_string = preg_replace('/[\\s]{2,}/i', ' ', implode(' ', ${$admin_label})); // Get latitude and longitude if ($traveling_lat_long = wpcampus_get_lat_long($traveling_string)) { // Store data (will be stored in post meta later) $traveling_latitude = isset($traveling_lat_long->lat) ? $traveling_lat_long->lat : false; $traveling_longitude = isset($traveling_lat_long->lng) ? $traveling_lat_long->lng : false; } break; // Get everyone else // Get everyone else default: // Get field value ${$admin_label} = rgar($entry, $field->id); break; } } // Create entry post title $post_title = "Entry #{$entry_id}"; // Add name if (!empty($name)) { $post_title .= " - {$name}"; } // Create entry if ($new_entry_post_id = wp_insert_post(array('post_type' => 'wpcampus_interest', 'post_status' => 'publish', 'post_title' => $post_title, 'post_content' => ''))) { // Store entry ID in post update_post_meta($new_entry_post_id, 'gf_entry_id', $entry_id); // Store post ID in the entry GFAPI::update_entry_property($entry_id, 'post_id', $new_entry_post_id); // Store fields foreach ($fields_to_store as $field_name) { update_post_meta($new_entry_post_id, $field_name, ${$field_name}); } return true; } return false; }
global $saved_university_location; // Only for universities post type if ('universities' != get_post_type($post_id)) { return; } // Get updated location $updated_university_location = wpcampus_get_university_location_string($post_id); // If updated is not different than saved, then no point if ($updated_university_location == $saved_university_location) { return; } // Delete the existing post meta delete_post_meta($post_id, 'latitude'); delete_post_meta($post_id, 'longitude'); // Get latitude and longitude if ($location_lat_long = wpcampus_get_lat_long($updated_university_location)) { // Add latitude if ($latitude = isset($location_lat_long->lat) ? $location_lat_long->lat : false) { add_post_meta($post_id, 'latitude', $latitude, true); } // Add longitude if ($longitude = isset($location_lat_long->lng) ? $location_lat_long->lng : false) { add_post_meta($post_id, 'longitude', $longitude, true); } } }, 1000); // Get university location array function wpcampus_get_university_location($post_id) { // Get data $location = array();