Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2011
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. /* this is the input field */
  2.                 ...
  3.                 <input type="file" name="MoobLogoUpload" id="MoobLogoUpload" size="40" />
  4.                
  5.                 <?php if ($file = $options['MoobLogoUpload']) {
  6.                         echo "<img src='{$file['url']}' />";
  7.                       }
  8.                 ?>
  9.                 ...
  10.  
  11.  
  12.  
  13.  
  14. /* and this is your ajax function with the upload extra in it */
  15.  
  16. add_action('wp_ajax_test_theme_data_save', 'test_theme_save_ajax');
  17.  
  18. function test_theme_save_ajax() {
  19.  
  20.     check_ajax_referer('test-theme-data', 'security');
  21.  
  22.     $data = $_POST;
  23.     unset($data['security'], $data['action']);
  24.  
  25. /* ### upload extra */
  26.     if ($data['MoobLogoUpload']) {
  27.             $overrides = array('test_form' => false);
  28.             $file = wp_handle_upload($data['MoobLogoUpload'], $overrides);
  29.             $data['MoobLogoUpload'] = $file;
  30.         }
  31.  
  32. /* ### upload extra END */
  33.  
  34.     if(!is_array(get_option('test_theme'))) {
  35.         $options = array();
  36.     } else {
  37.         $options = get_option('test_theme');
  38.     }
  39.    
  40.     if(!empty($data)) {
  41.         $diff = array_diff($options, $data);
  42.         $diff2 = array_diff($data, $options);
  43.         $diff = array_merge($diff, $diff2);
  44.     } else {
  45.         $diff = array();
  46.     }
  47.  
  48.     if(!empty($diff)) {
  49.         if(update_option('test_theme', $data)) {
  50.             die('1');
  51.         } else {
  52.             die('0');
  53.         }
  54.     } else {
  55.         die('1');
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement