/** * * Only for attachments, only default checkboxes! * * @internal breakpoint * @param type $post_ID * @param type $post */ function wpcf_admin_post_add_attachment_hook($post_ID, $post) { global $wpcf; /** * Basic check: only attachment */ if ('attachment' != $post->post_type) { return false; } /** * Get all groups connected to this $post */ $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($groups)) { return false; } $all_fields = array(); $_not_valid = array(); $_error = false; /** * Loop over each group * * TODO Document this * Connect 'wpcf-invalid-fields' with all fields */ foreach ($groups as $group) { if (isset($group['fields'])) { // Process fields $fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation'); // Validate fields $form = wpcf_form_simple_validate($fields); $all_fields = $all_fields + $fields; // Collect all not valid fields if ($form->isError()) { $_error = true; // Set error only to true $_not_valid = array_merge($_not_valid, (array) $form->get_not_valid()); } } } // Set fields foreach ($all_fields as $k => $v) { // only Types field if (empty($v['wpcf-id'])) { continue; } $_temp = new WPCF_Field(); $_temp->set($wpcf->post, $v['wpcf-id']); $all_fields[$k]['_field'] = $_temp; } foreach ($_not_valid as $k => $v) { // only Types field if (empty($v['wpcf-id'])) { continue; } $_temp = new WPCF_Field(); $_temp->set($wpcf->post, $v['wpcf-id']); $_not_valid[$k]['_field'] = $_temp; } /** * Process all checkbox fields */ foreach ($all_fields as $field) { /** * only checkbox */ if (!isset($field['#type']) || 'checkbox' != $field['#type']) { continue; } $field_data = wpcf_admin_fields_get_field($field['wpcf-id']); /** * check is checked for new! */ $checked = array_key_exists('checked', $field_data['data']) && $field_data['data']['checked']; /** * do not save empty and not checked? fine, go away... */ if ('no' == $field_data['data']['save_empty'] && !$checked) { continue; } /** * all other just save... */ $update_data = 0; if ($checked) { $update_data = $field_data['data']['set_value']; } add_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data); } do_action('wpcf_attachement_add', $post_ID); }
function wpcf_admin_userprofilesave_init($user_id) { if (defined('WPTOOLSET_FORMS_VERSION')) { global $wpcf; $errors = false; /** * check checkbox type fields to delete or save empty if needed */ $groups = wpcf_admin_usermeta_get_groups_fields(); foreach ($groups as $group) { if (!array_key_exists('fields', $group) || empty($group['fields'])) { continue; } foreach ($group['fields'] as $field) { switch ($field['type']) { case 'checkboxes': if (!array_key_exists('wpcf', $_POST) || !array_key_exists($field['slug'], $_POST['wpcf'])) { delete_user_meta($user_id, $field['meta_key']); } break; case 'checkbox': if (!array_key_exists('wpcf', $_POST) || !array_key_exists($field['slug'], $_POST['wpcf'])) { if ('yes' == $field['data']['save_empty']) { $_POST['wpcf'][$field['slug']] = 0; } else { delete_user_meta($user_id, $field['meta_key']); } } break; } } } // Save meta fields if (!empty($_POST['wpcf'])) { foreach ($_POST['wpcf'] as $field_slug => $field_value) { // Get field by slug $field = wpcf_fields_get_field_by_slug($field_slug, 'wpcf-usermeta'); if (empty($field)) { continue; } // Skip copied fields if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) { continue; } $_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value; // Set config $config = wptoolset_form_filter_types_field($field, $user_id); foreach ($_field_value as $_k => $_val) { // Check if valid $valid = wptoolset_form_validate_field('your-profile', $config, $_val); if (is_wp_error($valid)) { $errors = true; $_errors = $valid->get_error_data(); $_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']); wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error'); if (types_is_repetitive($field)) { unset($field_value[$_k]); } else { break; } } } // Save field if (types_is_repetitive($field)) { $wpcf->usermeta_repeater->set($user_id, $field); $wpcf->usermeta_repeater->save($field_value); } else { $wpcf->usermeta_field->set($user_id, $field); $wpcf->usermeta_field->usermeta_save($field_value); } do_action('wpcf_user_field_saved', $user_id, $field); // TODO Move to checkboxes if ($field['type'] == 'checkboxes') { $field_data = wpcf_admin_fields_get_field($field['id'], false, false, false, 'wpcf-usermeta'); if (!empty($field_data['data']['options'])) { $update_data = array(); foreach ($field_data['data']['options'] as $option_id => $option_data) { if (!isset($_POST['wpcf'][$field['id']][$option_id])) { if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') { $update_data[$option_id] = 0; } } else { $update_data[$option_id] = $_POST['wpcf'][$field['id']][$option_id]; } } update_user_meta($user_id, $field['meta_key'], $update_data); } } } } if ($errors) { update_post_meta($user_id, '__wpcf-invalid-fields', true); } do_action('wpcf_user_saved', $user_id); return; } global $wpcf; $all_fields = array(); $_not_valid = array(); $_error = false; $error = ''; $groups = $groups = wpcf_admin_usermeta_get_groups_fields(); if (empty($groups)) { return false; } foreach ($groups as $group) { // Process fields $fields = wpcf_admin_usermeta_process_fields($user_id, $group['fields'], true, false, 'validation'); // Validate fields $form = wpcf_form_simple_validate($fields); $all_fields = $all_fields + $fields; // Collect all not valid fields if ($form->isError()) { $_error = true; // Set error only to true $_not_valid = array_merge($_not_valid, (array) $form->get_not_valid()); } } // Set fields foreach ($all_fields as $k => $v) { // only Types field if (empty($v['wpcf-id'])) { continue; } $_temp = new WPCF_Usermeta_Field(); $_temp->set($user_id, $v['wpcf-id']); $all_fields[$k]['_field'] = $_temp; } foreach ($_not_valid as $k => $v) { // only Types field if (empty($v['wpcf-id'])) { continue; } $_temp = new WPCF_Usermeta_Field(); $_temp->set($user_id, $v['wpcf-id']); $_not_valid[$k]['_field'] = $_temp; } $not_valid = apply_filters('wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields); // Notify user about error if ($error) { wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error'); } /* * Save invalid elements so user can be informed after redirect. */ if (!empty($not_valid)) { update_user_meta($user_id, 'wpcf-invalid-fields', $not_valid); } if (!empty($_POST['wpcf'])) { foreach ($_POST['wpcf'] as $field_slug => $field_value) { $field = wpcf_fields_get_field_by_slug($field_slug, 'wpcf-usermeta'); if (empty($field)) { continue; } $wpcf->usermeta_field->set($user_id, $field); if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) { continue; } if (isset($_POST['__wpcf_repetitive'][$wpcf->usermeta_field->slug])) { $wpcf->usermeta_repeater->set($user_id, $field); $wpcf->usermeta_repeater->save(); } else { $wpcf->usermeta_field->usermeta_save(); } do_action('wpcf_post_field_saved', '', $field); } //end foreach } //end if foreach ($all_fields as $field) { if (!isset($field['#type'])) { continue; } if ($field['#type'] == 'checkbox') { $field_data = wpcf_admin_fields_get_field($field['wpcf-id'], false, false, false, 'wpcf-usermeta'); if (!isset($_POST['wpcf'][$field['wpcf-slug']])) { if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') { update_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], 0); } else { delete_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug']); } } } if ($field['#type'] == 'checkboxes') { $field_data = wpcf_admin_fields_get_field($field['wpcf-id'], false, false, false, 'wpcf-usermeta'); if (!empty($field_data['data']['options'])) { $update_data = array(); foreach ($field_data['data']['options'] as $option_id => $option_data) { if (!isset($_POST['wpcf'][$field['wpcf-slug']][$option_id])) { if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') { $update_data[$option_id] = 0; } } else { $update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id]; } } update_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data); } } } }
/** * Important save_post hook. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @internal breakpoint * @param type $post_ID * @param type $post */ function wpcf_admin_post_save_post_hook($post_ID, $post) { global $wpcf; // Basic cheks /* * Allow this hook to be triggered only if Types form is submitted */ if (!isset($_POST['_wpcf_post_wpnonce']) || !wp_verify_nonce($_POST['_wpcf_post_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) { return false; } /* * Do not save post if is type of: * revision * attachment * wp-types-group * view * view-template * cred-form */ if (in_array($post->post_type, $wpcf->excluded_post_types)) { return false; } /* * * * Get all groups connected to this $post */ $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($groups)) { return false; } $all_fields = array(); $_not_valid = array(); $_error = false; /* * * * Loop over each group * * TODO Document this * Connect 'wpcf-invalid-fields' with all fields */ foreach ($groups as $group) { // Process fields $fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation'); // Validate fields $form = wpcf_form_simple_validate($fields); $all_fields = $all_fields + $fields; // Collect all not valid fields if ($form->isError()) { $_error = true; // Set error only to true $_not_valid = array_merge($_not_valid, (array) $form->get_not_valid()); } } // Set fields foreach ($all_fields as $k => $v) { // only Types field if (empty($v['wpcf-id'])) { continue; } $_temp = new WPCF_Field(); $_temp->set($wpcf->post, $v['wpcf-id']); $all_fields[$k]['_field'] = $_temp; } foreach ($_not_valid as $k => $v) { // only Types field if (empty($v['wpcf-id'])) { continue; } $_temp = new WPCF_Field(); $_temp->set($wpcf->post, $v['wpcf-id']); $_not_valid[$k]['_field'] = $_temp; } /* * * Allow interaction here. * Conditional will set $error to false if field is conditional * and not submitted. */ $error = apply_filters('wpcf_post_form_error', $_error, $_not_valid, $all_fields); $not_valid = apply_filters('wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields); // Notify user about error if ($error) { wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error'); } /* * Save invalid elements so user can be informed after redirect. */ if (!empty($not_valid)) { update_post_meta($post_ID, 'wpcf-invalid-fields', $not_valid); } /* * * * * * Save meta fields */ if (!empty($_POST['wpcf'])) { foreach ($_POST['wpcf'] as $field_slug => $field_value) { // Get field by slug $field = wpcf_fields_get_field_by_slug($field_slug); if (empty($field)) { continue; } // Set field $wpcf->field->set($post_ID, $field); // Skip copied fields // CHECKPOINT if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) { continue; } // Don't save invalid // CHECKPOINT if (isset($not_valid[$field['slug']])) { continue; } /* * * * Saving fields * @since 1.2 * * We changed way repetitive fields are saved. * On each save fields are rewritten and order is saved in * '_$slug-sort-order' meta field. */ /* * * We marked fields as repetitive in POST['__wpcf_repetitive'] * Without this check we won't save any. * @see WPCF_Repeater::get_fields_form() */ if (isset($_POST['__wpcf_repetitive'][$wpcf->field->slug])) { /* * Use here WPCF_Repeater class. * WPCF_Repeater::set() - switches to current post * WPCF_Repeater::save() - saves repetitive field */ $wpcf->repeater->set($post_ID, $field); $wpcf->repeater->save(); } else { /* * Use WPCF_Field::save() */ $wpcf->field->save(); } do_action('wpcf_post_field_saved', $post_ID, $field); } } /* * Process checkboxes * * TODO Revise and remove * Since Types 1.1.5 we moved this check to embedded/includes/checkbox.php * checkbox.php added permanently to bootstrap. */ foreach ($all_fields as $field) { if (!isset($field['#type'])) { continue; } // if ( $field['#type'] == 'checkbox' // && !isset( $_POST['wpcf'][$field['wpcf-slug']] ) ) { // $field_data = wpcf_admin_fields_get_field( $field['wpcf-id'] ); // if ( isset( $field_data['data']['save_empty'] ) // && $field_data['data']['save_empty'] == 'yes' ) { // update_post_meta( $post_ID, // wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'], // 0 ); // } else { // delete_post_meta( $post_ID, // wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'] ); // } // } if ($field['#type'] == 'checkboxes') { $field_data = wpcf_admin_fields_get_field($field['wpcf-id']); if (!empty($field_data['data']['options'])) { $update_data = array(); foreach ($field_data['data']['options'] as $option_id => $option_data) { if (!isset($_POST['wpcf'][$field['wpcf-slug']][$option_id])) { if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') { $update_data[$option_id] = 0; } } else { $update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id]; } } update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data); } } } do_action('wpcf_post_saved', $post_ID); }
/** * save_post hook. * * @param type $post_ID * @param type $post */ function wpcf_admin_post_save_post_hook($post_ID, $post) { // TODO Check if this prevents saving from outside of post form if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) { return false; } if (!in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) { // Get groups $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($groups)) { return false; } $all_fields = array(); foreach ($groups as $group) { // Process fields $fields = wpcf_admin_post_process_fields($post, $group['fields'], true); // Validate fields $form = wpcf_form_simple_validate($fields); $all_fields = $all_fields + $fields; $error = $form->isError(); // Trigger form error if ($error) { wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error'); } } // Save invalid elements so user can be informed after redirect if (!empty($all_fields)) { update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields); } // Save meta fields if (!empty($_POST['wpcf'])) { foreach ($_POST['wpcf'] as $field_slug => $field_value) { // Don't save invalid if (isset($all_fields[wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_slug)) . $field_slug]) && isset($all_fields[wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_slug)) . $field_slug]['#error'])) { continue; } // Get field by slug $field = wpcf_fields_get_field_by_slug($field_slug); if (!empty($field)) { // Apply filters $field_value = apply_filters('wpcf_fields_value_save', $field_value, $field['type'], $field_slug); $field_value = apply_filters('wpcf_fields_slug_' . $field_slug . '_value_save', $field_value); $field_value = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_save', $field_value); // Save field update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field_slug, $field_value); do_action('wpcf_fields_slug_' . $field_slug . '_save', $field_value); do_action('wpcf_fields_type_' . $field['type'] . '_save', $field_value); } } } // Process checkboxes foreach ($all_fields as $field) { if ($field['#type'] == 'checkbox' && !isset($_POST['wpcf'][$field['wpcf-slug']])) { delete_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug']); } } } }
/** * save_post hook. * * @param type $post_ID * @param type $post */ function wpcf_admin_post_save_post_hook($post_ID, $post) { if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) { return false; } if (!in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) { // Get groups $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($groups)) { return false; } $all_fields = array(); foreach ($groups as $group) { // Process fields // Fix duplicates for repetitive fields foreach ($group['fields'] as $temp_field_id => $temp_field_data) { if (isset($temp_field_data['data']['repetitive']) && isset($_REQUEST['wpcf'][$temp_field_id])) { if (count($_POST['wpcf'][$temp_field_id]) < 2) { continue; } $temp_check_duplicates_old_value = array(); $temp_check_duplicates_new_value = array(); foreach ($_POST['wpcf'][$temp_field_id] as $posted_field_key => $posted_field_value) { $temp_old_value = base64_decode($posted_field_value['old_value']); $temp_new_value = isset($posted_field_value['new_value']) ? $posted_field_value['new_value'] : serialize($posted_field_value); $temp_field_key = wpcf_types_get_meta_prefix($temp_field_data) . $temp_field_id; // Check new values if (in_array(md5($temp_new_value), $temp_check_duplicates_new_value)) { unset($_POST['wpcf'][$temp_field_id][$posted_field_key]); if ($temp_old_value != '__wpcf_repetitive_new_field') { // Rebuild delete_post_meta($post_ID, $temp_field_key, $temp_old_value); update_post_meta($post_ID, $temp_field_key, $temp_old_value); } } else { if ($temp_old_value == '__wpcf_repetitive_new_field') { $_POST['wpcf'][$temp_field_id][intval($posted_field_key) * 1000] = $_POST['wpcf'][$temp_field_id][$posted_field_key]; unset($_POST['wpcf'][$temp_field_id][$posted_field_key]); continue; } $temp_check_duplicates_new_value[] = md5($temp_new_value); } // Check old values // if ($temp_old_value != '__wpcf_repetitive_new_field') { // if (in_array(md5($temp_old_value), // $temp_check_duplicates_old_value)) { // unset($_POST['wpcf'][$temp_field_id][$posted_field_key]); // if ($temp_old_value != '__wpcf_repetitive_new_field') { // // Rebuild // delete_post_meta($post_ID, $temp_field_key, // $temp_old_value); // update_post_meta($post_ID, $temp_field_key, // $temp_old_value); // } // } else { // if ($temp_old_value == '__wpcf_repetitive_new_field') { // $_POST['wpcf'][$temp_field_id][intval($posted_field_key) * 1000] = $_POST['wpcf'][$temp_field_id][$posted_field_key]; // unset($_POST['wpcf'][$temp_field_id][$posted_field_key]); // continue; // } // $temp_check_duplicates_old_value[] = md5($temp_old_value); // } // } } } } $_REQUEST['wpcf'] = $_POST['wpcf']; // Fix indexes for repetitive foreach ($group['fields'] as $temp_field_id => $temp_field_data) { if (isset($temp_field_data['data']['repetitive']) && isset($_REQUEST['wpcf'][$temp_field_id])) { $temp_count = 1; $temp_data = $_REQUEST['wpcf'][$temp_field_id]; unset($_REQUEST['wpcf'][$temp_field_id]); $_REQUEST['wpcf'][$temp_field_id] = array(); foreach ($temp_data as $temp_post_key => $temp_post_data) { $_REQUEST['wpcf'][$temp_field_id][$temp_count] = $temp_post_data; $temp_count += 1; } } } $_POST['wpcf'] = $_REQUEST['wpcf']; $fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation'); // Validate fields $form = wpcf_form_simple_validate($fields); $all_fields = $all_fields + $fields; $error = $form->isError(); // Trigger form error if ($error) { wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error'); } } // Save invalid elements so user can be informed after redirect if (!empty($all_fields)) { update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields); } // Save meta fields if (!empty($_POST['wpcf'])) { foreach ($_POST['wpcf'] as $field_slug => $field_value) { // Repetitive fields if (isset($_POST['wpcf_repetitive'][$field_slug])) { foreach ($field_value as $temp_id => $repetitive_data) { $field = wpcf_fields_get_field_by_slug($field_slug); // Skype specific if ($field['type'] == 'skype') { wpcf_admin_post_save_field($post_ID, $all_fields, $field_slug, $repetitive_data, base64_decode($repetitive_data['old_value'])); } else { wpcf_admin_post_save_field($post_ID, $all_fields, $field_slug, $repetitive_data['new_value'], base64_decode($repetitive_data['old_value'])); } } } else { wpcf_admin_post_save_field($post_ID, $all_fields, $field_slug, $field_value); } } } } }
/** * save_post hook. * * @param type $post_ID * @param type $post */ function wpcf_admin_post_save_post_hook($post_ID, $post) { if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) { return false; } if (in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) { return false; } // Get groups $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($groups)) { return false; } $all_fields = array(); foreach ($groups as $group) { // Process fields $fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation'); // Validate fields $form = wpcf_form_simple_validate($fields); $all_fields = $all_fields + $fields; $error = $form->isError(); // Trigger form error if ($error) { wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error'); } } // Save invalid elements so user can be informed after redirect if (!empty($all_fields)) { update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields); } // Save meta fields if (!empty($_POST['wpcf'])) { foreach ($_POST['wpcf'] as $field_slug => $field_value) { // Skip copied fields if (isset($_POST['wpcf_repetitive_copy'][$field_slug])) { continue; } $field = wpcf_fields_get_field_by_slug($field_slug); if (empty($field)) { continue; } $meta_key = wpcf_types_get_meta_prefix($field) . $field_slug; // Don't save invalid if (isset($all_fields[$meta_key]['#error'])) { continue; } // Repetitive fields if (isset($_POST['wpcf_repetitive'][$field_slug])) { delete_post_meta($post_ID, $meta_key); foreach ($field_value as $temp_id => $repetitive_data) { // Skype specific if ($field['type'] == 'skype') { unset($repetitive_data['old_value']); wpcf_admin_post_save_field($post_ID, $meta_key, $field, $repetitive_data, true); } else { wpcf_admin_post_save_field($post_ID, $meta_key, $field, $repetitive_data['new_value'], true); } } } else { wpcf_admin_post_save_field($post_ID, $meta_key, $field, $field_value); } } } // Process checkboxes foreach ($all_fields as $field) { if (!isset($field['#type'])) { continue; } if ($field['#type'] == 'checkbox' && !isset($_POST['wpcf'][$field['wpcf-slug']])) { $field_data = wpcf_admin_fields_get_field($field['wpcf-id']); if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') { update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], 0); } else { delete_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug']); } } if ($field['#type'] == 'checkboxes') { $field_data = wpcf_admin_fields_get_field($field['wpcf-id']); if (!empty($field_data['data']['options'])) { $update_data = array(); foreach ($field_data['data']['options'] as $option_id => $option_data) { if (!isset($_POST['wpcf'][$field['wpcf-slug']][$option_id])) { if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') { $update_data[$option_id] = 0; } } else { $update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id]; } } update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data); } } } }