/** * Count days between passed dates. * * @param string A date for compare * @param string A date for compare * @param int Precision of results * @return float|bool Quantity of days or false if passed incorrect dates */ function appthemes_days_between_dates($date1, $date2 = '', $precision = 1) { if (empty($date2)) { $date2 = current_time('mysql'); } if (!is_string($date1) || !is_string($date2)) { return false; } $date1 = strtotime($date1); $date2 = strtotime($date2); $days = round(appthemes_seconds_to_days($date1 - $date2), $precision); return $days; }
function appthemes_process_membership_order($current_user, $order) { //if order ID matches pending membership id suffix, then process the order by extendning the date and setting the ID if (isset($current_user->active_membership_pack)) { $user_active_pack_id = get_pack_id($current_user->active_membership_pack); } else { $user_active_pack_id = false; } if (isset($current_user->membership_expires)) { $user_active_pack_expiration = $current_user->membership_expires; } else { $user_active_pack_expiration = strtotime(current_time('mysql')); } if ($order['total_cost'] == 0 || $order['order_id'] == $_REQUEST['oid'] || $order['order_id'] == $_REQUEST['custom'] || $order['order_id'] == $_REQUEST['invoice']) { //update the user profile to current order pack_id taking it off "pending" status and setup the membership object update_user_meta($current_user->ID, 'active_membership_pack', $order['pack_id']); $membership = get_pack($order['pack_id']); //extend membership if its still active, so long as its not free (otherwise free extentions could be infinite) $expires_in_days = appthemes_seconds_to_days(strtotime($user_active_pack_expiration) - strtotime(current_time('mysql'))); $purchase = $order['pack_duration'] . ' ' . __('days', 'appthemes'); if ($expires_in_days > 0 && $order['total_cost'] > 0 && $order['pack_id'] == $user_active_pack_id) { $updated_expires_date = appthemes_mysql_date($user_active_pack_expiration, $order['pack_duration']); } else { $updated_expires_date = appthemes_mysql_date(current_time('mysql'), $order['pack_duration']); } update_user_meta($current_user->ID, 'membership_expires', $updated_expires_date); $order['updated_expires_date'] = $updated_expires_date; delete_option($order['option_order_id']); //return the order information in case its needed return $order; } else { //get orders of the user $the_order = get_user_orders($current_user->ID, $order['order_id']); return false; } }
function appthemes_days_between_dates($date1, $date2 = '', $precision = '1') { if (empty($date2)) { $date2 = current_time('mysql'); } //setup the times based on string dates, if dates are not strings return false. if (is_string($date1)) { $date1 = strtotime($date1); } else { return false; } if (is_string($date2)) { $date2 = strtotime($date2); } else { return false; } $days = round(appthemes_seconds_to_days($date1 - $date2), $precision); return $days; }