Skip to content
Browse files

Merging in @helgaviking's changes so checkboxes save correctly.

  • Loading branch information...
1 parent 073968a commit ab67c64c0edb75ff3e8c6a0c80da1708d43c4fc9 @devinsays devinsays committed Jan 25, 2011
Showing with 45 additions and 58 deletions.
  1. +45 −58 admin/admin-interface.php
View
103 admin/admin-interface.php
@@ -11,25 +11,24 @@ function optionsframework_admin_init() {
global $my_options, $options_machine;
$options_machine = new Options_Machine($my_options);
+
//if reset is pressed->replace options with defaults
if ( isset($_REQUEST['page']) && $_REQUEST['page'] == 'optionsframework' ) {
if (isset($_REQUEST['of_reset']) && 'reset' == $_REQUEST['of_reset']) {
+
$nonce=$_POST['security'];
+
if (!wp_verify_nonce($nonce, 'of_ajax_nonce') ) {
header('Location: themes.php?page=optionsframework&reset=error');
die('Security Check');
} else {
$defaults = (array) $options_machine->Defaults;
- if(update_option(OPTIONS,$options_machine->Defaults)) {
- header('Location: themes.php?page=optionsframework&reset=true');
- die($options_machine->Defaults);
- } else {
- header('Location: themes.php?page=optionsframework&reset=error');
- die('error');
- }
- }
+ update_option(OPTIONS,$options_machine->Defaults);
+ header('Location: themes.php?page=optionsframework&reset=true');
+ die($options_machine->Defaults);
+ }
}
- }
+ }
}
add_action('admin_init','optionsframework_admin_init');
@@ -123,12 +122,14 @@ function of_style_only() {
/*-----------------------------------------------------------------------------------*/
function of_load_only() {
+
+ add_action('admin_head', 'of_admin_head');
+
wp_enqueue_script('jquery-ui-core');
wp_register_script('jquery-input-mask', ADMIN .'js/jquery.maskedinput-1.2.2.js', array( 'jquery' ));
wp_enqueue_script('jquery-input-mask');
wp_enqueue_script('color-picker', ADMIN .'js/colorpicker.js', array('jquery'));
wp_enqueue_script('ajaxupload', ADMIN .'js/ajaxupload.js', array('jquery'));
- add_action('admin_head', 'of_admin_head');
}
@@ -415,77 +416,63 @@ function() {
function of_ajax_callback() {
global $options_machine;
+
$nonce=$_POST['security'];
if (! wp_verify_nonce($nonce, 'of_ajax_nonce') ) die('-1');
- // Get options array from db
+ //get options array from db
$all = get_option(OPTIONS);
+
$save_type = $_POST['type'];
- // Uploads
- if($save_type == 'upload') {
+ //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;
- // Update $options array with image URL
- $upload_image = $all; // Preserve current data
- $upload_image[$clickedID] = $uploaded_file['url'];
- update_option(OPTIONS, $upload_image ) ;
- if(!empty($uploaded_file['error'])) { echo 'Upload Error: ' . $uploaded_file['error']; }
- else { echo $uploaded_file['url']; } // Is the Response
+
+ $upload_tracking[] = $clickedID;
+
+ //update $options array w/ image URL
+ $upload_image = $all; //preserve current data
+
+ $upload_image[$clickedID] = $uploaded_file['url'];
+
+ update_option(OPTIONS, $upload_image ) ;
+
+
+ if(!empty($uploaded_file['error'])) {echo 'Upload Error: ' . $uploaded_file['error']; }
+ else { echo $uploaded_file['url']; } // Is the Response
}
- elseif($save_type == 'image_reset') {
+ elseif($save_type == 'image_reset'){
+
$id = $_POST['data']; // Acts as the name
- $delete_image = $all; // Preserve rest of data
- $delete_image[$id] = ''; // Update array key with empty value
+
+ $delete_image = $all; //preserve rest of data
+ $delete_image[$id] = ''; //update array key with empty value
update_option(OPTIONS, $delete_image ) ;
+
}
- elseif ($save_type == 'save') {
+ elseif ($save_type == 'save') {
+
parse_str($_POST['data'], $data);
unset($data['security']);
unset($data['of_save']);
-
- if(!is_array($all)) {
- $my_options = array();
- } else {
- $my_options = $all;
-
- }
-
- if(!empty($data)) {
- $diff = array_diff($my_options, $data);
- $diff2 = array_diff($data, $my_options);
- $diff = array_merge($diff, $diff2);
- } else {
- $diff = array();
- }
-
- if(!empty($diff)) {
- $update= array();
- $update = $all; // Preserve rest of data
- $update = $data;
-
- if( update_option(OPTIONS, $update) ) {
- die('1');
- } else {
- die('0');
- }
- } else {
- die('1');
- }
+
+ update_option(OPTIONS, $data);
+ die('1');
} elseif ($save_type == 'reset') {
- if( update_option(OPTIONS,$options_machine->Defaults) ) {
- die(1);
- } else {
- die(0);
- }
+ update_option(OPTIONS,$options_machine->Defaults);
+ die(1); //options reset
+
}
die();

0 comments on commit ab67c64

Please sign in to comment.
Something went wrong with that request. Please try again.