Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 100 additions & 11 deletions inc/integrations/host-providers/class-enhance-host-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function on_add_domain($domain, $site_id): void {
$server_id = defined('WU_ENHANCE_SERVER_ID') ? WU_ENHANCE_SERVER_ID : '';

if (empty($server_id)) {
wu_log_add('integration-enhance', 'Server ID not configured');
wu_log_add('integration-enhance', 'ERROR: Server ID not configured. Please define WU_ENHANCE_SERVER_ID in wp-config.php');
return;
}

Expand All @@ -144,11 +144,33 @@ public function on_add_domain($domain, $site_id): void {

// Check if domain was added successfully
if (wu_get_isset($domain_response, 'id')) {
wu_log_add('integration-enhance', sprintf('Domain %s added successfully. SSL will be automatically provisioned via LetsEncrypt when DNS resolves.', $domain));
wu_log_add('integration-enhance', sprintf('SUCCESS: Domain %s added successfully with ID: %s. SSL will be automatically provisioned via LetsEncrypt when DNS resolves.', $domain, $domain_response['id']));
} elseif (isset($domain_response['error'])) {
wu_log_add('integration-enhance', sprintf('Failed to add domain %s. Error: %s', $domain, wp_json_encode($domain_response)));
$error_context = '';
if (isset($domain_response['response_code'])) {
$error_context = sprintf(' (HTTP %d)', $domain_response['response_code']);
}
wu_log_add('integration-enhance', sprintf('ERROR: Failed to add domain %s%s. Details: %s', $domain, $error_context, wp_json_encode($domain_response)));

// Add specific error guidance
if (isset($domain_response['response_code'])) {
switch ($domain_response['response_code']) {
case 401:
wu_log_add('integration-enhance', 'TROUBLESHOOTING: API authentication failed. Check your WU_ENHANCE_API_TOKEN is valid.');
break;
case 403:
wu_log_add('integration-enhance', 'TROUBLESHOOTING: Access forbidden. Ensure your API token has System Administrator role.');
break;
case 404:
wu_log_add('integration-enhance', 'TROUBLESHOOTING: Server not found. Verify WU_ENHANCE_SERVER_ID is correct.');
break;
case 409:
wu_log_add('integration-enhance', sprintf('TROUBLESHOOTING: Domain %s may already exist in Enhance. Check your Enhance panel.', $domain));
break;
}
}
} else {
wu_log_add('integration-enhance', sprintf('Domain %s may have been added, but response was unclear: %s', $domain, wp_json_encode($domain_response)));
wu_log_add('integration-enhance', sprintf('WARNING: Domain %s may have been added, but response was unclear: %s', $domain, wp_json_encode($domain_response)));
}
}

Expand All @@ -167,7 +189,7 @@ public function on_remove_domain($domain, $site_id): void {
$server_id = defined('WU_ENHANCE_SERVER_ID') ? WU_ENHANCE_SERVER_ID : '';

if (empty($server_id)) {
wu_log_add('integration-enhance', 'Server ID not configured');
wu_log_add('integration-enhance', 'ERROR: Server ID not configured. Please define WU_ENHANCE_SERVER_ID in wp-config.php');
return;
}

Expand All @@ -177,6 +199,11 @@ public function on_remove_domain($domain, $site_id): void {
'GET'
);

if (isset($domains_list['error'])) {
wu_log_add('integration-enhance', sprintf('ERROR: Failed to list domains for removal. Details: %s', wp_json_encode($domains_list)));
return;
}

$domain_id = null;

if (isset($domains_list['items']) && is_array($domains_list['items'])) {
Expand All @@ -189,17 +216,25 @@ public function on_remove_domain($domain, $site_id): void {
}

if (empty($domain_id)) {
wu_log_add('integration-enhance', sprintf('Could not find domain ID for %s, it may have already been removed', $domain));
wu_log_add('integration-enhance', sprintf('WARNING: Could not find domain ID for %s, it may have already been removed from Enhance', $domain));
return;
}

wu_log_add('integration-enhance', sprintf('Found domain %s with ID: %s, proceeding with deletion', $domain, $domain_id));

// Delete the domain
$delete_response = $this->send_enhance_api_request(
'/servers/' . $server_id . '/domains/' . $domain_id,
'DELETE'
);

wu_log_add('integration-enhance', sprintf('Domain %s removal request sent', $domain));
if (isset($delete_response['success']) && $delete_response['success']) {
wu_log_add('integration-enhance', sprintf('SUCCESS: Domain %s (ID: %s) removed successfully', $domain, $domain_id));
} elseif (isset($delete_response['error'])) {
wu_log_add('integration-enhance', sprintf('ERROR: Failed to remove domain %s. Details: %s', $domain, wp_json_encode($delete_response)));
} else {
wu_log_add('integration-enhance', sprintf('Domain %s removal request sent (HTTP 204 or similar)', $domain));
}
}

/**
Expand Down Expand Up @@ -245,25 +280,79 @@ public function test_connection(): void {
if (empty($server_id)) {
$error = new \WP_Error('no-server-id', __('Server ID is not configured', 'ultimate-multisite'));
wp_send_json_error($error);
return;
}

wu_log_add('integration-enhance', sprintf('Testing connection with server ID: %s', $server_id));

// Test by attempting to list domains
$response = $this->send_enhance_api_request(
'/servers/' . $server_id . '/domains',
'GET'
);

// Check for successful response
if (isset($response['items']) || isset($response['id'])) {
wu_log_add('integration-enhance', 'Connection test successful');
wp_send_json_success(
[
'message' => __('Connection successful', 'ultimate-multisite'),
]
);
} else {
$error = new \WP_Error('connection-failed', __('Failed to connect to Enhance API', 'ultimate-multisite'));
wp_send_json_error($error);
}

// Handle error responses with detailed messages
wu_log_add('integration-enhance', sprintf('Connection test failed. Response: %s', wp_json_encode($response)));

// Build detailed error message
$error_message = __('Failed to connect to Enhance API', 'ultimate-multisite');
$error_details = [];

if (isset($response['error'])) {
$error_details[] = $response['error'];
}

if (isset($response['response_code'])) {
// translators: %d is the HTTP status code number
$error_details[] = sprintf(__('HTTP Status: %d', 'ultimate-multisite'), $response['response_code']);

// Provide specific guidance based on status code
switch ($response['response_code']) {
case 401:
$error_details[] = __('Authentication failed. Please verify your API token is correct and has not expired.', 'ultimate-multisite');
break;
case 403:
$error_details[] = __('Access forbidden. Please ensure your API token has the System Administrator role.', 'ultimate-multisite');
break;
case 404:
$error_details[] = __('Server not found. Please verify your Server ID is correct.', 'ultimate-multisite');
break;
case 500:
case 502:
case 503:
$error_details[] = __('Enhance server error. Please check your Enhance Control Panel status.', 'ultimate-multisite');
break;
}
}

if (isset($response['response_body'])) {
$error_body = json_decode($response['response_body'], true);
if (json_last_error() === JSON_ERROR_NONE && isset($error_body['message'])) {
// translators: %s is the error message from the Enhance API
$error_details[] = sprintf(__('API Message: %s', 'ultimate-multisite'), $error_body['message']);
}
}

// Add troubleshooting tips
$error_details[] = __('Please check:', 'ultimate-multisite');
$error_details[] = __('1. API URL includes /api/ at the end (e.g., https://panel.example.com/api/)', 'ultimate-multisite');
$error_details[] = __('2. API token is valid and has System Administrator role', 'ultimate-multisite');
$error_details[] = __('3. Server ID matches a server in your Enhance panel', 'ultimate-multisite');
$error_details[] = __('4. Your WordPress server can reach the Enhance panel', 'ultimate-multisite');

$error_message .= ': ' . implode(' ', $error_details);

$error = new \WP_Error('connection-failed', $error_message);
wp_send_json_error($error);
}
Comment on lines +304 to 356
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Search for API URL patterns in the Enhance integration files
rg "panel\." inc/integrations/host-providers/class-enhance-host-provider.php -A 2 -B 2

# Also check for /api/ usage
rg "/api" inc/integrations/host-providers/class-enhance-host-provider.php -A 2 -B 2

# Look for API URL construction or validation
rg "api_url|base_url|endpoint" inc/integrations/host-providers/class-enhance-host-provider.php -A 3 -B 1

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 2278


🏁 Script executed:

# Check the entire Enhance host provider file for API URL handling
wc -l inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 148


🏁 Script executed:

# Get the full context of how API URLs are constructed and used
head -100 inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 2090


🏁 Script executed:

# Search for send_enhance_api_request calls to see what endpoints are used
rg "send_enhance_api_request" inc/integrations/host-providers/class-enhance-host-provider.php -A 1

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 565


🏁 Script executed:

# Look for endpoint definitions or API calls
rg "\'/api" inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 153


🏁 Script executed:

# Check around line 100-200 to see actual API endpoint usage
sed -n '100,200p' inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 3941


🏁 Script executed:

# Search for any documentation or comments about Enhance API URL format
rg "ENHANCE_API_URL" inc/integrations/host-providers/class-enhance-host-provider.php -B 3 -A 3

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 934


🏁 Script executed:

# Check if there are any tests or examples that show correct format
fd "test" inc/integrations/host-providers/ -o fd "example" inc/integrations/host-providers/

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 204


🏁 Script executed:

# Look at the complete get_fields method to see the placeholder
sed -n '97,120p' inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 784


Incorrect API URL guidance in error message at line 347.

The error message suggests users should include /api/ at the end of the API URL (e.g., https://panel.example.com/api/), but this contradicts the UI placeholder and code structure. The endpoints are constructed without /api/ prefix (e.g., /servers/{id}/domains), so the base URL should not include /api/. Update line 347 to match the placeholder example:

Change:

__('1. API URL includes /api/ at the end (e.g., https://panel.example.com/api/)', 'ultimate-multisite')

To:

__('1. API URL is correct (e.g., https://panel.example.com)', 'ultimate-multisite')
🤖 Prompt for AI Agents
In inc/integrations/host-providers/class-enhance-host-provider.php around lines
304 to 356, the troubleshooting tip incorrectly tells users to include "/api/"
at the end of the API URL; update that tip to instruct users to provide the base
panel URL without "/api/" (for example "https://panel.example.com") so it
matches the UI placeholder and how endpoints are constructed.


/**
Expand Down
Loading