function inkthemes_ajax_callback() { global $wpdb, $options_to_save; // this is how you get access to the database $options_to_save = array(); check_ajax_referer('colorwaytheme-update-option', 'option_nonce'); $save_type = $_POST['type']; //Uploads if ($save_type == 'upload') { $clickedID = $_POST['data']; // Acts as the name $filename = $_FILES[$clickedID]; $filename['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $filename['name']); $override['test_form'] = false; $override['action'] = 'wp_handle_upload'; $uploaded_file = wp_handle_upload($filename, $override); $response = array(); if (isset($uploaded_file) && ($uploaded_file['type'] == 'image/gif' || $uploaded_file['type'] == 'image/jpeg' || $uploaded_file['type'] == 'image/pjpeg' || $uploaded_file['type'] == 'image/png' || $uploaded_file['type'] == 'image/svg+xml')) { $upload_tracking[] = $clickedID; $options_to_save[$clickedID] = $uploaded_file['url']; if (!empty($uploaded_file['error'])) { $response['error'] = __('Upload Error: ', 'colorway') . $uploaded_file['error']; } else { $response['url'] = $uploaded_file['url']; } } else { $response['error'] = __('Unsupported filetype uploaded.', 'colorway'); } // Is the Response echo json_encode($response); die; } elseif ($save_type == 'image_reset') { $id = $_POST['data']; // Acts as the name inkthemes_delete_option($id); } elseif ($save_type == 'options' or $save_type == 'framework') { $data = $_POST['data']; parse_str($data, $output); //print_r($output); //Pull options $of_template = inkthemes_options(); $options = $of_template['of_template']; foreach ($options as $option_array) { $id = $option_array['id']; $old_value = inkthemes_get_option($id); $new_value = ''; if (isset($output[$id])) { $new_value = $output[$option_array['id']]; } if (isset($option_array['id'])) { // Non - Headings... $type = $option_array['type']; if (is_array($type)) { foreach ($type as $array) { if ($array['type'] == 'text') { $id = $array['id']; $std = $array['std']; $new_value = $output[$id]; if ($new_value == '') { $new_value = $std; } $new_value = sanitize_text_field($new_value); $options_to_save[$id] = stripslashes($new_value); } } } elseif ($new_value == '' && $type == 'checkbox') { // Checkbox Save $options_to_save[$id] = 'false'; } elseif ($new_value == 'true' && $type == 'checkbox') { // Checkbox Save $options_to_save[$id] = 'true'; } elseif ($type == 'multicheck') { // Multi Check Save $option_options = $option_array['options']; foreach ($option_options as $options_id => $options_value) { $multicheck_id = $id . "_" . $options_id; if (!isset($output[$multicheck_id])) { $options_to_save[$multicheck_id] = 'false'; } else { $options_to_save[$multicheck_id] = 'true'; } } } elseif ($type == 'typography') { $typography_array = array(); $typography_array['size'] = $output[$option_array['id'] . '_size']; $typography_array['face'] = stripslashes($output[$option_array['id'] . '_face']); $typography_array['style'] = $output[$option_array['id'] . '_style']; $typography_array['color'] = $output[$option_array['id'] . '_color']; $options_to_save[$id] = $typography_array; } elseif ($type == 'border') { $border_array = array(); $border_array['width'] = $output[$option_array['id'] . '_width']; $border_array['style'] = $output[$option_array['id'] . '_style']; $border_array['color'] = $output[$option_array['id'] . '_color']; $options_to_save[$id] = $border_array; } elseif ($type != 'upload_min') { $options_to_save[$id] = stripslashes($new_value); } } } } inkthemes_save_option($options_to_save); die; }
function inkthemes_ajax_callback() { global $wpdb; // this is how you get access to the database $save_type = $_POST['type']; //Uploads if ($save_type == 'upload') { $clickedID = $_POST['data']; // Acts as the name $filename = $_FILES[$clickedID]; $filename['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $filename['name']); $override['test_form'] = false; $override['action'] = 'wp_handle_upload'; $uploaded_file = wp_handle_upload($filename, $override); $upload_tracking[] = $clickedID; inkthemes_update_option($clickedID, $uploaded_file['url']); if (!empty($uploaded_file['error'])) { echo 'Upload Error: ' . $uploaded_file['error']; } else { echo $uploaded_file['url']; } // Is the Response } elseif ($save_type == 'image_reset') { $id = $_POST['data']; // Acts as the name inkthemes_delete_option($id); } elseif ($save_type == 'options' or $save_type == 'framework') { $data = $_POST['data']; parse_str($data, $output); //print_r($output); //Pull options $options = inkthemes_get_option('of_template'); foreach ($options as $option_array) { $id = $option_array['id']; $old_value = inkthemes_get_option($id); $new_value = ''; if (isset($output[$id])) { $new_value = $output[$option_array['id']]; } if (isset($option_array['id'])) { // Non - Headings... $type = $option_array['type']; if (is_array($type)) { foreach ($type as $array) { if ($array['type'] == 'text') { $id = $array['id']; $std = $array['std']; $new_value = $output[$id]; if ($new_value == '') { $new_value = $std; } inkthemes_update_option($id, stripslashes($new_value)); } } } elseif ($new_value == '' && $type == 'checkbox') { // Checkbox Save inkthemes_update_option($id, 'false'); } elseif ($new_value == 'true' && $type == 'checkbox') { // Checkbox Save inkthemes_update_option($id, 'true'); } elseif ($type == 'multicheck') { // Multi Check Save $option_options = $option_array['options']; foreach ($option_options as $options_id => $options_value) { $multicheck_id = $id . "_" . $options_id; if (!isset($output[$multicheck_id])) { inkthemes_update_option($multicheck_id, 'false'); } else { inkthemes_update_option($multicheck_id, 'true'); } } } elseif ($type == 'typography') { $typography_array = array(); $typography_array['size'] = $output[$option_array['id'] . '_size']; $typography_array['face'] = stripslashes($output[$option_array['id'] . '_face']); $typography_array['style'] = $output[$option_array['id'] . '_style']; $typography_array['color'] = $output[$option_array['id'] . '_color']; inkthemes_update_option($id, $typography_array); } elseif ($type == 'border') { $border_array = array(); $border_array['width'] = $output[$option_array['id'] . '_width']; $border_array['style'] = $output[$option_array['id'] . '_style']; $border_array['color'] = $output[$option_array['id'] . '_color']; inkthemes_update_option($id, $border_array); } elseif ($type != 'upload_min') { inkthemes_update_option($id, stripslashes($new_value)); } } } } die; }