of_ajax_callback

The ColorWay Theme of ajax callback function.

Description

of_ajax_callback(); 

Usage

  1. if ( !function_exists( 'of_ajax_callback' ) ) { 
  2. require_once '/functions/admin-interface.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = of_ajax_callback(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions/admin-interface.php  
  1. function of_ajax_callback() { 
  2. global $wpdb; // this is how you get access to the database 
  3.  
  4.  
  5. $save_type = $_POST['type']; 
  6. //Uploads 
  7. if($save_type == 'upload') { 
  8.  
  9. $clickedID = $_POST['data']; // Acts as the name 
  10. $filename = $_FILES[$clickedID]; 
  11. $filename['name'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', $filename['name']);  
  12.  
  13. $override['test_form'] = false; 
  14. $override['action'] = 'wp_handle_upload';  
  15. $uploaded_file = wp_handle_upload($filename, $override); 
  16.  
  17. $upload_tracking[] = $clickedID; 
  18. update_option( $clickedID , $uploaded_file['url'] ); 
  19.  
  20. if(!empty($uploaded_file[error])) {echo 'Upload Error: ' . $uploaded_file[error]; }  
  21. else { echo $uploaded_file['url']; } // Is the Response 
  22. elseif($save_type == 'image_reset') { 
  23.  
  24. $id = $_POST['data']; // Acts as the name 
  25. global $wpdb; 
  26. $query = "DELETE FROM $wpdb->options WHERE option_name LIKE '$id'"; 
  27. $wpdb->query($query); 
  28.  
  29. }  
  30. elseif ($save_type == 'options' OR $save_type == 'framework') { 
  31. $data = $_POST['data']; 
  32.  
  33. parse_str($data, $output); 
  34. //print_r($output); 
  35.  
  36. //Pull options 
  37. $options = get_option('of_template'); 
  38.  
  39. foreach($options as $option_array) { 
  40.  
  41. $id = $option_array['id']; 
  42. $old_value = get_option($id); 
  43. $new_value = ''; 
  44.  
  45. if(isset($output[$id])) { 
  46. $new_value = $output[$option_array['id']]; 
  47.  
  48. if(isset($option_array['id'])) { // Non - Headings... 
  49.  
  50.  
  51. $type = $option_array['type']; 
  52.  
  53. if ( is_array($type)) { 
  54. foreach($type as $array) { 
  55. if($array['type'] == 'text') { 
  56. $id = $array['id']; 
  57. $std = $array['std']; 
  58. $new_value = $output[$id]; 
  59. if($new_value == '') { $new_value = $std; } 
  60. update_option( $id, stripslashes($new_value)); 
  61. }  
  62. elseif($new_value == '' && $type == 'checkbox') { // Checkbox Save 
  63.  
  64. update_option($id, 'false'); 
  65. elseif ($new_value == 'true' && $type == 'checkbox') { // Checkbox Save 
  66.  
  67. update_option($id, 'true'); 
  68. elseif($type == 'multicheck') { // Multi Check Save 
  69.  
  70. $option_options = $option_array['options']; 
  71.  
  72. foreach ($option_options as $options_id => $options_value) { 
  73.  
  74. $multicheck_id = $id . "_" . $options_id; 
  75.  
  76. if(!isset($output[$multicheck_id])) { 
  77. update_option($multicheck_id, 'false'); 
  78. else{ 
  79. update_option($multicheck_id, 'true');  
  80. }  
  81. elseif($type == 'typography') { 
  82.  
  83. $typography_array = array();  
  84.  
  85. $typography_array['size'] = $output[$option_array['id'] . '_size']; 
  86.  
  87. $typography_array['face'] = stripslashes($output[$option_array['id'] . '_face']); 
  88.  
  89. $typography_array['style'] = $output[$option_array['id'] . '_style']; 
  90.  
  91. $typography_array['color'] = $output[$option_array['id'] . '_color']; 
  92.  
  93. update_option($id, $typography_array); 
  94.  
  95. elseif($type == 'border') { 
  96.  
  97. $border_array = array();  
  98.  
  99. $border_array['width'] = $output[$option_array['id'] . '_width']; 
  100.  
  101. $border_array['style'] = $output[$option_array['id'] . '_style']; 
  102.  
  103. $border_array['color'] = $output[$option_array['id'] . '_color']; 
  104.  
  105. update_option($id, $border_array); 
  106.  
  107. elseif($type != 'upload_min') { 
  108.  
  109. update_option($id, stripslashes($new_value)); 
  110. }  
  111.  
  112.  
  113. die(); 
  114.