예제 #1
1
 /**
  * @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;
 }
예제 #2
0
 public static function maybe_get_field(&$field)
 {
     _deprecated_function(__FUNCTION__, '2.0.9', 'FrmField::maybe_get_field');
     FrmField::maybe_get_field($field);
 }
 public static function update_field_ajax()
 {
     //check_ajax_referer( 'frm_ajax', 'nonce' );
     $entry_id = FrmAppHelper::get_param('entry_id', 0, 'post', 'absint');
     $field_id = FrmAppHelper::get_param('field_id', 0, 'post', 'sanitize_title');
     $value = FrmAppHelper::get_param('value');
     FrmField::maybe_get_field($field_id);
     if ($field_id && FrmProEntriesHelper::user_can_edit($entry_id, $field_id->form_id)) {
         $updated = FrmProEntryMeta::update_single_field(compact('entry_id', 'field_id', 'value'));
         echo $updated;
     }
     wp_die();
 }