/** * @since 2.0.11 */ public static function update_single_field($atts) { if (empty($atts['entry_id'])) { return; } $field = $atts['field_id']; FrmField::maybe_get_field($field); if (!$field) { return; } if (isset($field->field_options['post_field']) && !empty($field->field_options['post_field'])) { $post_id = FrmDb::get_var('frm_items', array('id' => $atts['entry_id']), 'post_id'); } else { $post_id = false; } global $wpdb; if (!$post_id) { $updated = FrmEntryMeta::update_entry_meta($atts['entry_id'], $field->id, null, $atts['value']); if (!$updated) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE item_id = %d and field_id = %d", $atts['entry_id'], $field->id)); $updated = FrmEntryMeta::add_entry_meta($atts['entry_id'], $field->id, '', $atts['value']); } wp_cache_delete($atts['entry_id'], 'frm_entry'); } else { switch ($field->field_options['post_field']) { case 'post_custom': $updated = update_post_meta($post_id, $field->field_options['custom_field'], maybe_serialize($atts['value'])); break; case 'post_category': $taxonomy = !FrmField::is_option_empty($field, 'taxonomy') ? $field->field_options['taxonomy'] : 'category'; $updated = wp_set_post_terms($post_id, $atts['value'], $taxonomy); break; default: $post = get_post($post_id, ARRAY_A); $post[$field->field_options['post_field']] = maybe_serialize($atts['value']); $updated = wp_insert_post($post); break; } } if ($updated) { // set updated_at time $wpdb->update($wpdb->prefix . 'frm_items', array('updated_at' => current_time('mysql', 1), 'updated_by' => get_current_user_id()), array('id' => $atts['entry_id'])); } $atts['field_id'] = $field->id; $atts['field'] = $field; do_action('frm_after_update_field', $atts); return $updated; }
/** * Move entries from parent form to child form * * @since 2.0.09 */ private static function move_entries_to_child_form($args) { global $wpdb; // get the ids of the entries saved in these fields $item_ids = FrmDb::get_col('frm_item_metas', array('field_id' => $args['children']), 'item_id', array('group_by' => 'item_id')); foreach ($item_ids as $old_id) { // Create a new entry in the child form $new_id = FrmEntry::create(array('form_id' => $args['form_id'], 'parent_item_id' => $old_id)); // Move the parent item_metas to the child form $where = array('item_id' => $old_id, 'field_id' => $args['children']); FrmDb::get_where_clause_and_values($where); array_unshift($where['values'], $new_id); $c = $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_item_metas SET item_id = %d ' . $where['where'], $where['values'])); if ($c) { // update the section field meta with the new entry ID $u = FrmEntryMeta::update_entry_meta($old_id, $args['field_id'], null, $new_id); if (!$u) { // add the row if it wasn't there to update FrmEntryMeta::add_entry_meta($old_id, $args['field_id'], null, $new_id); } } } }
function update_field_ajax($entry_id, $field_id, $value) { global $frmdb, $wpdb, $frm_field; $entry_id = (int) $entry_id; if (!$entry_id) { return false; } $where = ''; if (is_numeric($field_id)) { $where .= "fi.id={$field_id}"; } else { $where .= "field_key='{$field_id}'"; } $field = $frm_field->getAll($where, '', ' LIMIT 1'); if (!$field or !FrmProEntry::user_can_edit($entry_id, $field->form_id)) { return false; } $post_id = false; $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['post_field']) and !empty($field->field_options['post_field'])) { $post_id = $frmdb->get_var($frmdb->entries, array('id' => $entry_id), 'post_id'); } if (!$post_id) { $updated = $wpdb->update($frmdb->entry_metas, array('meta_value' => $value), array('item_id' => $entry_id, 'field_id' => $field_id)); if (!$updated) { $wpdb->query($wpdb->prepare("DELETE FROM {$frmdb->entry_metas} WHERE item_id = %d and field_id = %d", $entry_id, $field_id)); $updated = FrmEntryMeta::add_entry_meta($entry_id, $field_id, '', $value); } wp_cache_delete($entry_id, 'frm_entry'); } else { switch ($field->field_options['post_field']) { case 'post_custom': $updated = update_post_meta($post_id, $field->field_options['post_custom'], maybe_serialize($value)); break; case 'post_category': $taxonomy = (isset($field->field_options['taxonomy']) and !empty($field->field_options['taxonomy'])) ? $field->field_options['taxonomy'] : 'category'; $updated = wp_set_post_terms($post_id, $value, $taxonomy); break; default: $post = get_post($post_id, ARRAY_A); $post[$field->field_options['post_field']] = maybe_serialize($value); $updated = wp_insert_post($post); } } do_action('frm_after_update_field', compact('entry_id', 'field_id', 'value')); return $updated; }
public static function show_comments($entry) { $id = $entry->id; $user_ID = get_current_user_id(); if ($_POST && isset($_POST['frm_comment']) && !empty($_POST['frm_comment'])) { FrmEntryMeta::add_entry_meta($_POST['item_id'], 0, '', array('comment' => $_POST['frm_comment'], 'user_id' => $user_ID)); //send email notifications } $comments = FrmEntryMeta::getAll(array('item_id' => $id, 'field_id' => 0), ' ORDER BY it.created_at ASC', '', true); $date_format = get_option('date_format'); $time_format = get_option('time_format'); include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-entries/show.php'; }
function save_frm_agreement($entry_id, $form_id) { if (!isset($_POST['terms'])) { return; } global $tou_settings, $frm_version, $user_ID; $value = ($tou_settings->initials and isset($_POST['initials'])) ? $_POST['tou_initials'] : 'agree'; $v = explode('.', $frm_version); if ((int) $v[1] > 5 or (int) $v[1] == 5 and (int) $v[2] > 2) { FrmEntryMeta::add_entry_meta($entry_id, 0, '', serialize(array('initials' => $value))); } TouAppHelper::save_meta($user_ID, $value); }