Exemplo n.º 1
0
function inkthemes_option_setup()
{
    //Update EMPTY options
    $of_array = array();
    add_option('inkthemes_options', $of_array);
    $template = cc_get_option('of_template');
    $saved_options = cc_get_option('inkthemes_options');
    $std = '';
    foreach ($template as $option) {
        if ($option['type'] != 'heading') {
            $id = isset($option['id']) ? $option['id'] : null;
            if (isset($option['std'])) {
                $std = $option['std'];
            }
            $db_option = cc_get_option($id);
            if (empty($db_option)) {
                if (is_array($option['type'])) {
                    foreach ($option['type'] as $child) {
                        $c_id = $child['id'];
                        $c_std = $child['std'];
                        cc_update_option($c_id, $c_std);
                        $of_array[$c_id] = $c_std;
                    }
                } else {
                    cc_update_option($id, $std);
                    $of_array[$id] = $std;
                }
            } else {
                //So just store the old values over again.
                $of_array[$id] = $db_option;
            }
        }
    }
    cc_update_option('inkthemes_options', $of_array);
}
Exemplo n.º 2
0
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;
        cc_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
        cc_delete_option($id);
    } elseif ($save_type == 'options' or $save_type == 'framework') {
        $data = $_POST['data'];
        parse_str($data, $output);
        //print_r($output);
        //Pull options
        $options = cc_get_option('of_template');
        foreach ($options as $option_array) {
            $id = $option_array['id'];
            $old_value = cc_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;
                            }
                            cc_update_option($id, stripslashes($new_value));
                        }
                    }
                } elseif ($new_value == '' && $type == 'checkbox') {
                    // Checkbox Save
                    cc_update_option($id, 'false');
                } elseif ($new_value == 'true' && $type == 'checkbox') {
                    // Checkbox Save
                    cc_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])) {
                            cc_update_option($multicheck_id, 'false');
                        } else {
                            cc_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'];
                    cc_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'];
                    cc_update_option($id, $border_array);
                } elseif ($type != 'upload_min') {
                    cc_update_option($id, stripslashes($new_value));
                }
            }
        }
    }
    die;
}