/**
  * prepare the ad post type to be saved
  *
  * @since 1.0.0
  * @param int $post_id id of the post
  * @todo handling this more dynamic based on ad type
  */
 public function save_ad($post_id)
 {
     // only use for ads, no other post type
     if (!isset($_POST['post_type']) || $this->post_type != $_POST['post_type'] || !isset($_POST['advanced_ad']['type'])) {
         return;
     }
     // don’t do this on revisions
     if (wp_is_post_revision($post_id)) {
         return;
     }
     // get ad object
     $ad = new Advanced_Ads_Ad($post_id);
     if (!$ad instanceof Advanced_Ads_Ad) {
         return;
     }
     // filter to allow change of submitted ad settings
     $_POST['advanced_ad'] = apply_filters('advanced-ads-ad-settings-pre-save', $_POST['advanced_ad']);
     $ad->type = $_POST['advanced_ad']['type'];
     if (isset($_POST['advanced_ad']['output'])) {
         $ad->set_option('output', $_POST['advanced_ad']['output']);
     } else {
         $ad->set_option('output', array());
     }
     /**
      * deprecated since introduction of "visitors" in 1.5.4
      */
     if (isset($_POST['advanced_ad']['visitor'])) {
         $ad->set_option('visitor', $_POST['advanced_ad']['visitor']);
     } else {
         $ad->set_option('visitor', array());
     }
     // visitor conditions
     if (isset($_POST['advanced_ad']['visitors'])) {
         $ad->set_option('visitors', $_POST['advanced_ad']['visitors']);
     } else {
         $ad->set_option('visitors', array());
     }
     // save size
     $ad->width = 0;
     if (isset($_POST['advanced_ad']['width'])) {
         $ad->width = absint($_POST['advanced_ad']['width']);
     }
     $ad->height = 0;
     if (isset($_POST['advanced_ad']['height'])) {
         $ad->height = absint($_POST['advanced_ad']['height']);
     }
     if (!empty($_POST['advanced_ad']['description'])) {
         $ad->description = esc_textarea($_POST['advanced_ad']['description']);
     } else {
         $ad->description = '';
     }
     if (!empty($_POST['advanced_ad']['content'])) {
         $ad->content = $_POST['advanced_ad']['content'];
     } else {
         $ad->content = '';
     }
     if (!empty($_POST['advanced_ad']['conditions'])) {
         $ad->conditions = $_POST['advanced_ad']['conditions'];
     } else {
         $ad->conditions = array();
     }
     // prepare expiry date
     if (isset($_POST['advanced_ad']['expiry_date']['enabled'])) {
         $year = absint($_POST['advanced_ad']['expiry_date']['year']);
         $month = absint($_POST['advanced_ad']['expiry_date']['month']);
         $day = absint($_POST['advanced_ad']['expiry_date']['day']);
         $hour = absint($_POST['advanced_ad']['expiry_date']['hour']);
         $minute = absint($_POST['advanced_ad']['expiry_date']['minute']);
         $expiration_date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hour, $minute, '00');
         $valid_date = wp_checkdate($month, $day, $year, $expiration_date);
         if (!$valid_date) {
             $ad->expiry_date = 0;
         } else {
             // as PHP 5.2 has not reliable 'u' option need to calculate timestamps this way
             $gmDate = get_gmt_from_date($expiration_date, 'Y-m-d-H-i');
             list($year, $month, $day, $hour, $minute) = explode('-', $gmDate);
             $ad->expiry_date = gmmktime($hour, $minute, 0, $month, $day, $year);
         }
     } else {
         $ad->expiry_date = 0;
     }
     $ad->save();
 }