1. function wp_insert_post($post_id, $post = null){
  2.            
  3.             if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
  4.                 return $post_id;   
  5.            
  6.             if( !current_user_can( 'edit_post', $post_id ) ) // check permissions
  7.                 return $post_id;
  8.            
  9.             if (($post->post_type == "create_afflink") || ($post->post_type == "sales_pages") || ($post->post_type == "squeeze_pages") || ($post->post_type == "post") || ($post->post_type == "page")){
  10.            
  11.                 // Loop through the POST data
  12.                 foreach ($this->meta_fields as $key) {
  13.                
  14.                     if ( defined('DOING_AJAX') ) {
  15.                         return  ;
  16.                     } else {           
  17.                        
  18.                         $value = @$_POST[$key];                    
  19.                        
  20.                        
  21.                         if ( isset($_POST[$field]) || empty($value)) {
  22.                             delete_post_meta($post_id, $key);
  23.                             continue;
  24.                         }
  25.                    
  26.                         // If value is a string it should be unique
  27.                         if (!is_array($value)) {
  28.                             // Update meta                     
  29.                             if (!update_post_meta($post_id, $key, $value) && isset($_POST[$field]) && $_POST[$field] != '') {
  30.                                 add_post_meta($post_id, $key, $value);
  31.                             }
  32.                         } else {
  33.                             // If passed along is an array, we should remove all previous data
  34.                                 wsm_log_debug('$value is an array, so removing all previous data...',true,false);
  35.                                 wsm_log_debug_array($value,true);
  36.                             delete_post_meta($post_id, $key);
  37.                                 wsm_log_debug('Removed all custom field data from post id: '.$post_id.' for the key '.$key,true,false);
  38.                            
  39.                             // Loop through the array adding new values to the post meta as different entries with the same name
  40.                             foreach ($value as $entry){
  41.                                 wsm_log_debug('Beginning foreach loop to save data for $value as $entry...',true,false);   
  42.                                 //if (!empty($entry))
  43.                                     add_post_meta($post_id, $key, $entry);
  44.                                         wsm_log_debug('Successfully updated custom field data for post id: '.$post_id.' for the key '.$key.' with the $value as $entry '.$entry,true,false);
  45.                                         wsm_log_debug('Returning to the beginning of data save loop or ending...',true,true);      
  46.                             }
  47.                             wsm_log_debug('Ended array custom field data save loop for post id: '.$post_id.' for the key '.$key.'. Custom field data for key is as follows:',true,false);
  48.                             $custom = get_post_custom($post_id);
  49.                             $contentdownloads = $custom["wsm-content-downloads"];
  50.                             wsm_log_debug_array($contentdownloads,true);
  51.                             wsm_log_debug('Ending data saving operation and reloading the page...',true,true);
  52.                                
  53.                         }
  54.                     }
  55.                 }      
  56.             }//End Check for post type
  57.         }