Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('gform_post_submission', 'my_gf_to_pods', 10, 2);
- function my_gf_to_pods ($entry, $form) {
- $pod = false;
- $mapping = array();
- $id = null;
- $related = false;
- if (1 == $form['id']) {
- $pod = 'my_pod';
- $mapping = array('1' => 'my_field',
- '2.1' => 'first_name',
- '2.2' => 'last_name',
- '10' => 'other_field');
- pods_gf_map($pod, $mapping);
- }
- }
- function pods_gf_map ($pod = false, $mapping = array(), $id = null, $related = false) {
- if (false !== $pod && !empty($mapping)) {
- $fields = array();
- foreach ($mapping as $field_id => $map) {
- if (!isset($entry[$field_id]))
- continue;
- $value = $entry[$field_id];
- $etc = $map;
- if (is_array($etc) && !isset($etc['field']))
- continue;
- elseif (is_array($etc) && isset($etc['field']))
- $map = $etc['field'];
- $the_pod = $pod;
- if (isset($etc['pod']))
- $the_pod = $etc['pod'];
- $bool = false;
- if (isset($etc['bool']))
- $bool = $etc['bool'];
- if (false !== $bool) {
- if (is_bool($bool) && true === $bool) {
- if (0 < strlen($value))
- $value = 1;
- else
- $value = 0;
- }
- elseif ($value == $bool)
- $value = 1;
- else
- $value = 0;
- }
- if (!isset($fields[$the_pod]))
- $fields[$the_pod] = array();
- $fields[$the_pod][$map] = $value;
- }
- $ids = array();
- foreach ($fields as $the_pod => $columns) {
- $api = new PodAPI($the_pod);
- $params = array('datatype' => $the_pod, 'columns' => $columns);
- if (false === $related && !empty($id))
- $params['tbl_row_id'] = $id;
- if (!isset($ids[$the_pod]))
- $ids[$the_pod] = array();
- $save_id = $api->save_pod_item($params);
- if (0 < $save_id)
- $ids[$the_pod] = $save_id;
- }
- if (false !== $related && is_array($related)) {
- $api = new PodAPI($pod);
- $params = array('datatype' => $pod, 'columns' => array());
- if (!empty($id))
- $params['tbl_row_id'] = $id;
- foreach ($ids as $the_pod => $the_id) {
- if (!isset($related[$the_pod]))
- continue;
- $related_field = $related[$the_pod];
- $params['columns'][$related_field] = $the_id;
- }
- $id = $api->save_pod_item($params);
- }
- return $id;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement