From 2127b1bdd73ecd2423e443992da4b442f5a3c1a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 04 Feb 2026 21:19:25 +0000
Subject: [PATCH] =Major overhaul of MetaManager.php -> Meta.php and RestRouteManager.php -> Rest.php. Seems to work for JakeVan
---
inc/integrations/PostMark.php | 60 +++++++++++++++++++++++++++++++++---------------------------
1 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/inc/integrations/PostMark.php b/inc/integrations/PostMark.php
index 41f467c..9882d6c 100644
--- a/inc/integrations/PostMark.php
+++ b/inc/integrations/PostMark.php
@@ -15,6 +15,13 @@
*/
class PostMark extends Integrations
{
+ protected ?string $server_token = null;
+ protected string $message_stream = 'outbound';
+ protected string $from_email;
+ protected string $from_name;
+ protected bool $track_open;
+ protected bool $track_links;
+ protected ?string $lastMessageId = null;
/**
* Constructor
*/
@@ -22,9 +29,10 @@
{
$this->service_name = 'postmark';
$this->title = 'PostMark';
- $this->description = 'Professional transactional email delivery service';
$this->icon = 'envelope-simple';
+ $this->cacheName = ($userID)? 'gmb_'.$userID : 'postmark';
+
// PostMark API configuration
$this->apiBase = 'https://api.postmarkapp.com';
$this->apiVersion = 'v1';
@@ -48,12 +56,13 @@
];
// Required credentials
- $this->requiredCredentials = [
+ $this->fields = [
'server_token' => [
'label' => 'Server API Token',
- 'type' => 'password',
+ 'type' => 'text',
+ 'subtype'=> 'password',
'placeholder' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
- 'description' => 'Your PostMark Server API Token'
+ 'hint' => 'Your PostMark Server API Token'
],
'message_stream' => [
'label' => 'Message Stream ID',
@@ -101,7 +110,7 @@
parent::__construct($userID);
// Hook into WordPress mail system if integration is healthy
- if ($this->is_healthy && $this->hasValidCredentials()) {
+ if ($this->is_healthy && $this->isSetUp()) {
$this->initializeMailHooks();
}
}
@@ -249,6 +258,9 @@
*/
protected function sendEmail(array $payload): bool|WP_Error
{
+ if (!$this->isSetUp()) {
+ return false;
+ }
try {
$response = $this->postRequest('email', $payload);
@@ -271,7 +283,7 @@
return true;
} catch (\Exception $e) {
- $this->handleException($e, 'email');
+ $this->logError('[POSTMARK]', ['method' => 'sendEmail', 'error' => $e->getMessage()]);
return new WP_Error(
'postmark_send_failed',
$e->getMessage()
@@ -407,9 +419,7 @@
// Clean up whitespace
$text = preg_replace('/\s+/', ' ', $text);
- $text = trim($text);
-
- return $text;
+ return trim($text);
}
/**
@@ -459,22 +469,15 @@
/**
* Override makeRequest to add PostMark headers
*/
- protected function makeRequest(
- string $method,
- string $endpoint,
- array $params = [],
- array $headers = []
- ): mixed {
+ protected function getRequestHeaders(): array {
$credentials = $this->getCredentials();
// Add PostMark specific headers
- $headers = array_merge([
+ return [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'X-Postmark-Server-Token' => $credentials['server_token'] ?? ''
- ], $headers);
-
- return parent::makeRequest($method, $endpoint, $params, $headers);
+ ];
}
/**
@@ -500,7 +503,7 @@
return $stats;
}
} catch (\Exception $e) {
- $this->handleException($e, 'stats/outbound');
+ $this->logError('stats/outbound', ['error' => $e->getMessage()]);
}
return [];
@@ -517,7 +520,7 @@
'offset' => $offset
]);
} catch (\Exception $e) {
- $this->handleException($e, 'bounces');
+ $this->logError('[POSTMARK]', ['method' => 'getBounces', 'error' => $e->getMessage()]);
return [];
}
}
@@ -634,11 +637,14 @@
protected function initialize(): void
{
- // TODO: Implement initialize() method.
- }
-
- protected function getRequestHeaders(): array
- {
- // TODO: Implement getRequestHeaders() method.
+ if (empty($this->credentials)) {
+ $this->loadCredentials();
+ }
+ $this->server_token = (array_key_exists('server_token', $this->credentials)) ? $this->credentials['server_token'] : null;
+ $this->from_email = (array_key_exists('from_email', $this->credentials)) ? $this->credentials['from_email'] : get_bloginfo('admin_email');
+ $this->from_name = (array_key_exists('from_name', $this->credentials)) ? $this->credentials['from_name'] : get_bloginfo('name');
+ $this->message_stream = (array_key_exists('message_stream', $this->credentials)) ? $this->credentials['message_stream'] : 'outbound';
+ $this->track_open = (array_key_exists('track_open', $this->credentials)) ? $this->credentials['track_open'] : false;
+ $this->track_links = (array_key_exists('track_links', $this->credentials)) ? $this->credentials['track_links'] : false;
}
}
--
Gitblit v1.10.0