function poloray_options()
 {
     // VARIABLES
     $themename = 'Poloray Theme';
     $shortname = "of";
     // Populate OptionsFramework option in array for use in theme
     global $of_options;
     $of_options = poloray_get_option('of_options');
     //Front page on/off
     $file_rename = array("on" => "On", "off" => "Off");
     // Background Defaults
     $background_defaults = array('color' => '', 'image' => '', 'repeat' => 'repeat', 'position' => 'top center', 'attachment' => 'scroll');
     // Pull all the categories into an array
     $options_categories = array();
     $options_categories_obj = get_categories();
     foreach ($options_categories_obj as $category) {
         $options_categories[$category->cat_ID] = $category->cat_name;
     }
     // Populate OptionsFramework option in array for use in theme
     $contact_option = array("on" => "On", "off" => "Off");
     // Pull all the pages into an array
     $options_pages = array();
     $options_pages_obj = get_pages('sort_column=post_parent,menu_order');
     $options_pages[''] = 'Select a page:';
     foreach ($options_pages_obj as $page) {
         $options_pages[$page->ID] = $page->post_title;
     }
     // If using image radio buttons, define a directory path
     $imagepath = get_template_directory_uri() . '/images/';
     $options = array(array("name" => "General Settings", "type" => "heading"), array("name" => "Custom Logo", "desc" => "Choose your own logo. Optimal Size: 300px Wide by 90px Height.", "id" => "poloray_logo", "type" => "upload"), array("name" => "Custom Favicon", "desc" => "Specify a 16px x 16px image that will represent your website's favicon.", "id" => "poloray_favicon", "type" => "upload"), array("name" => "Front Page On/Off", "desc" => "Check on for enabling front page or check off for enabling blog page in front page", "id" => "re_nm", "std" => "on", "type" => "radio", "options" => $file_rename), array("name" => "Top Feature Settings", "type" => "heading"), array("name" => "Top Feature Heading", "desc" => "Enter your text for Top Feature.", "id" => "poloray_slider_heading", "std" => "", "type" => "textarea"), array("name" => "Top Feature Description", "desc" => "Enter your text for Top Feature Description.", "id" => "poloray_slider_description", "std" => "", "type" => "textarea"), array("name" => "Top Feature Image", "desc" => "Choose your image or video. Optimal size is 422px wide and height 224px", "id" => "poloray_slideimage1", "std" => "", "type" => "upload"), array("name" => "Top Feature  Link", "desc" => "Enter your text for Top Feature  Link.", "id" => "poloray_slider_link", "std" => "", "type" => "text"), array("name" => "Home Page Feature Settings", "type" => "heading"), array("name" => "Home Page Tagline", "desc" => "Enter your text for home page tagline", "id" => "poloray_mainheading", "std" => "", "type" => "textarea"), array("name" => "Home Page Button Text", "desc" => "Enter your text for home page button", "id" => "poloray_homepage_button", "std" => "", "type" => "text"), array("name" => "Home Page Button Link", "desc" => "Enter your text for home page button link", "id" => "poloray_homepage_button_link", "std" => "", "type" => "text"), array("name" => "Home Page Feature Section Starts From Here.", "type" => "saperate", "class" => "saperator"), array("name" => "First Feature Image", "desc" => "Choose image for your first Feature area. Optimal size 170px x 170px", "id" => "poloray_wimg1", "std" => "", "type" => "upload"), array("name" => "First Feature Heading", "desc" => "Enter your text for first col heading.", "id" => "poloray_firsthead", "std" => "", "type" => "textarea"), array("name" => "First Feature Description", "desc" => "Enter your text for first col description.", "id" => "poloray_firstdesc", "std" => "", "type" => "textarea"), array("name" => "First feature Link", "desc" => "Enter your text for First feature Link.", "id" => "poloray_feature_link1", "std" => "", "type" => "text"), array("name" => "Second Feature Starts From Here.", "type" => "saperate", "class" => "saperator"), array("name" => "Second Feature Image", "desc" => "Choose image for your second Feature area. Optimal size 170px x 170px", "id" => "poloray_fimg2", "std" => "", "type" => "upload"), array("name" => "Second Feature Heading", "desc" => "Enter your heading for second Feature area", "id" => "poloray_headline2", "std" => "", "type" => "textarea"), array("name" => "Second Col Description", "desc" => "Enter your text for second col description.", "id" => "poloray_seconddesc", "std" => "", "type" => "textarea"), array("name" => "Second feature Link", "desc" => "Enter your text for Second feature Link.", "id" => "poloray_feature_link2", "std" => "", "type" => "text"), array("name" => "Third Feature Starts From Here.", "type" => "saperate", "class" => "saperator"), array("name" => "Third Feature Image", "desc" => "Choose image for your thrid Feature. Optimal size 170px x 170px", "id" => "poloray_fimg3", "std" => "", "type" => "upload"), array("name" => "Third Feature Heading", "desc" => "Enter your heading for third Feature area", "id" => "poloray_headline3", "std" => "", "type" => "textarea"), array("name" => "Third Feature Description", "desc" => "Enter your text for Third Feature description.", "id" => "poloray_thirddesc", "std" => "", "type" => "textarea"), array("name" => "Third feature Link", "desc" => "Enter your text for Second feature Link.", "id" => "poloray_feature_link3", "std" => "", "type" => "text"), array("name" => "Fourth Feature Starts From Here.", "type" => "saperate", "class" => "saperator"), array("name" => "Fourth Feature Image", "desc" => "Choose image for your Fourth Feature. Optimal size 170px x 170px", "id" => "poloray_fimg4", "std" => "", "type" => "upload"), array("name" => "Fourth Feature Heading", "desc" => "Enter your heading for Fourth Feature area", "id" => "poloray_headline4", "std" => "", "type" => "textarea"), array("name" => "Fourth Feature Description", "desc" => "Enter your text for Fourth Feature description.", "id" => "poloray_fourthdesc", "std" => "", "type" => "textarea"), array("name" => "Fourth feature Link", "desc" => "Enter your text for Fourth feature Link.", "id" => "poloray_feature_link4", "std" => "", "type" => "text"), array("name" => "Styling Options", "type" => "heading"), array("name" => "Custom CSS", "desc" => "Quickly add some CSS to your theme by adding it to this block.", "id" => "poloray_customcss", "std" => "", "type" => "textarea"), array("name" => "Social Logos", "type" => "heading"), array("name" => "Facebook URL", "desc" => "Enter your Facebook URL if you have one", "id" => "poloray_facebook", "std" => "#", "type" => "text"), array("name" => "Twitter URL", "desc" => "Enter your Twitter URL if you have one", "id" => "poloray_twitter", "std" => "#", "type" => "text"), array("name" => "Yahoo URL", "desc" => "Enter your Yahoo Feed URL if you have one", "id" => "poloray_yahoo", "std" => "#", "type" => "text"), array("name" => "Rss URL", "desc" => "Enter your Rss URL if you have one", "id" => "poloray_rss", "std" => "#", "type" => "text"), array("name" => "Digg URL", "desc" => "Enter your Digg URL if you have one", "id" => "poloray_digg", "std" => "#", "type" => "text"), array("name" => "Pinterest URL", "desc" => "Enter your Pinterest Feed URL if you have one", "id" => "poloray_pinterest", "std" => "#", "type" => "text"));
     poloray_update_option('of_template', $options);
     poloray_update_option('of_themename', $themename);
     poloray_update_option('of_shortname', $shortname);
 }
function poloray_option_setup()
{
    //Update EMPTY options
    $of_array = array();
    add_option('of_options', $of_array);
    $template = poloray_get_option('of_template');
    $saved_options = poloray_get_option('of_options');
    $std = '';
    foreach ($template as $option) {
        if ($option['type'] != 'heading') {
            if (isset($option['id'])) {
                $id = $option['id'];
            }
            if (isset($option['std'])) {
                $std = $option['std'];
            }
            $db_option = poloray_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'];
                        poloray_update_option($c_id, $c_std);
                        $of_array[$c_id] = $c_std;
                    }
                } else {
                    poloray_update_option($id, $std);
                    $of_array[$id] = $std;
                }
            } else {
                //So just store the old values over again.
                $of_array[$id] = $db_option;
            }
        }
    }
    poloray_update_option('of_options', $of_array);
}
function poloray_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;
        poloray_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
        poloray_delete_option($id);
    } elseif ($save_type == 'options' or $save_type == 'framework') {
        $data = $_POST['data'];
        parse_str($data, $output);
        //print_r($output);
        //Pull options
        $options = poloray_get_option('of_template');
        foreach ($options as $option_array) {
            $id = $option_array['id'];
            $old_value = poloray_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;
                            }
                            poloray_update_option($id, stripslashes($new_value));
                        }
                    }
                } elseif ($new_value == '' && $type == 'checkbox') {
                    // Checkbox Save
                    poloray_update_option($id, 'false');
                } elseif ($new_value == 'true' && $type == 'checkbox') {
                    // Checkbox Save
                    poloray_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])) {
                            poloray_update_option($multicheck_id, 'false');
                        } else {
                            poloray_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'];
                    poloray_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'];
                    poloray_update_option($id, $border_array);
                } elseif ($type != 'upload_min') {
                    poloray_update_option($id, stripslashes($new_value));
                }
            }
        }
    }
    die;
}