/**
  * Print the CSV document headers.
  *
  * @return  void
  * @access  protected
  * @since   1.0.0
  */
 protected function print_headers()
 {
     ignore_user_abort(true);
     if (!charitable_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
         set_time_limit(0);
     }
     /* Check for PHP 5.3+ */
     if (function_exists('get_called_class')) {
         $class = get_called_class();
         $export = $class::EXPORT_TYPE;
     } else {
         $export = '';
     }
     nocache_headers();
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=charitable-export-' . $export . '-' . date('m-d-Y') . '.csv');
     header('Expires: 0');
 }
 /**
  * Print the CSV document headers. 
  *
  * @return  void
  * @access  protected
  * @since   1.0.0
  */
 protected function print_headers()
 {
     ignore_user_abort(true);
     if (!charitable_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
         set_time_limit(0);
     }
     nocache_headers();
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=charitable-export-' . self::EXPORT_TYPE . '-' . date('m-d-Y') . '.csv');
     header("Expires: 0");
 }
 /**
  * Fix the donation dates.
  *
  * This upgrade routine was added in 1.3.0
  *
  * @see 	https://github.com/Charitable/Charitable/issues/58
  *
  * @return  void
  * @access  public
  * @since   1.3.0
  */
 public function fix_donation_dates()
 {
     if (!current_user_can('manage_charitable_settings')) {
         wp_die(__('You do not have permission to do Charitable upgrades', 'charitable'), __('Error', 'charitable'), array('response' => 403));
     }
     ignore_user_abort(true);
     if (!charitable_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
         @set_time_limit(0);
     }
     $step = isset($_GET['step']) ? absint($_GET['step']) : 1;
     $number = 20;
     $total = Charitable_Donations::count_all();
     /**
      * If there are no donations to update, go ahead and wrap it up right now.
      */
     if (!$total) {
         $this->finish_upgrade('fix_donation_dates');
     }
     $donations = get_posts(array('post_type' => Charitable::DONATION_POST_TYPE, 'posts_per_page' => $number, 'paged' => $step, 'post_status' => array_keys(Charitable_Donation::get_valid_donation_statuses())));
     if (count($donations)) {
         /**
          * Prevent donation receipt & admin notifications from getting resent.
          */
         remove_action('save_post_' . Charitable::DONATION_POST_TYPE, array('Charitable_Email_Donation_Receipt', 'send_with_donation_id'));
         remove_action('save_post_' . Charitable::DONATION_POST_TYPE, array('Charitable_Email_New_Donation', 'send_with_donation_id'));
         foreach ($donations as $donation) {
             /**
              * Thankfully, we store the timestamp of the donation in the log,
              * so we can use that to correct any incorrect post_date/post_date_gmt
              * values.
              */
             $donation_log = get_post_meta($donation->ID, '_donation_log', true);
             if (empty($donation_log)) {
                 continue;
             }
             $time = $donation_log[0]['time'];
             $date_gmt = gmdate('Y-m-d H:i:s', $time);
             if ($date_gmt == $donation->post_date_gmt) {
                 continue;
             }
             $date = get_date_from_gmt($date_gmt);
             wp_update_post(array('ID' => $donation->ID, 'post_date' => $date, 'post_date_gmt' => $date_gmt));
         }
         $step++;
         $redirect = add_query_arg(array('page' => 'charitable-upgrades', 'charitable-upgrade' => 'fix_donation_dates', 'step' => $step, 'number' => $number, 'total' => $total), admin_url('index.php'));
         wp_redirect($redirect);
         exit;
     }
     $this->upgrade_logs();
     $this->finish_upgrade('fix_donation_dates');
 }