Esempio n. 1
0
 function colabs_remaining_days($post_id)
 {
     $post = get_post($post_id);
     $remain_days = __('No Expires', 'colabsthemes');
     $days = get_post_meta($post->ID, '_colabs_property_duration', true);
     if (get_post_meta($post->ID, 'expires', true) && !$days) {
         $expire_timestamp = get_post_meta($post->ID, 'expires', true);
         $days = colabs_days_between_dates(date('y-m-d', $expire_timestamp), date('y-m-d', strtotime('NOW')), $precision = 0);
     }
     if ($days) {
         if ($days >= 1) {
             $expire_date = strtotime($post->post_date . '+' . $days . ' days');
             $days = colabs_days_between_dates(date('y-m-d', $expire_date), date('y-m-d', strtotime('NOW')), $precision = 0);
             if ($days >= 1) {
                 if ($days > 30) {
                     $remain_days = __('Valid Until', 'colabsthemes') . '<small>( ' . date_i18n(get_option('date_format'), $expire_date) . ' )</small>';
                 } else {
                     $remain_days = __('Valid Until', 'colabsthemes') . '<small>( ' . $days . ' ' . _n('Day', 'Days', $days, 'colabsthemes') . ' )</small>';
                 }
             } else {
                 // $remain_days = __('Valid Until','colabsthemes').'<small>( '.human_time_diff( strtotime('NOW'), $expire_date ).' )</small>';
                 $remain_days = __('Expired', 'colabsthemes');
             }
         } else {
             $remain_days = __('Expired', 'colabsthemes');
         }
     }
     return apply_filters('colabs_remaining_days', $remain_days);
 }
Esempio n. 2
0
 /**
  * Upgrade property duration
  *
  * Replace old 'expires' meta key containing the expiration date 
  * with the new property duration key
  */
 public function upgrade_property_duration()
 {
     // Colabs_log()->write_log( 'Theme Upgrade: Update Property Duration' );
     $args = array('post_type' => COLABS_POST_TYPE, 'meta_key' => 'expires', 'post_status' => 'any', 'nopaging' => true);
     $legacy_expire = new WP_Query($args);
     foreach ($legacy_expire->posts as $post) {
         $expires = get_post_meta($post->ID, 'expires', true);
         $expire_date = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($expires));
         $duration = colabs_days_between_dates($expire_date, $post->post_date, 0);
         if (intval($duration) < 0) {
             // set the default property duration for expired properties
             $duration = 30;
             _colabs_expire_property($post->ID);
         }
         update_post_meta($post->ID, '_colabs_property_duration', $duration);
         // Colabs_log()->write_log( sprintf( 'Theme Upgrade: Update Property Durations - Updated property #%d duration to %d', $post->ID, $duration ) );
     }
 }