= $ts) { continue; } $access_days = (int) get_post_meta($download_id, '_ToDownload_access_days', true); if ($access_days <= 0) { $settings = get_option('ToDownload_settings', []); $access_days = is_array($settings) ? (int) ($settings['default_access_days'] ?? 0) : 0; } $access_days = max(0, $access_days); $expires_ts = 0; if ($access_days > 0) { $expires_ts = $ts + ($access_days * DAY_IN_SECONDS); $expires_ts = (int) apply_filters('ToDownload_subscription_expires_ts', $expires_ts, $email, $download_id, $order_id); } $by_download[$download_id] = [ 'download_id' => $download_id, 'last_order_id' => $order_id, 'last_order_at' => $at, 'last_order_ts' => $ts, 'access_days' => $access_days, 'expires_ts' => $expires_ts, ]; } } $now = time(); $rows = []; foreach ($by_download as $download_id => $row) { $expires_ts = (int) ($row['expires_ts'] ?? 0); $status = 'active'; if ($expires_ts > 0 && $now > $expires_ts) { $status = 'expired'; } $row['status'] = $status; unset($row['last_order_ts']); $rows[] = $row; } usort($rows, function ($a, $b) { return (int) ($b['expires_ts'] ?? 0) <=> (int) ($a['expires_ts'] ?? 0); }); return $rows; } }