blurpritn adn site builde cleanup
This commit is contained in:
@@ -1167,36 +1167,51 @@ function igny8_cron_sync_from_igny8() {
|
||||
* @param string $post_status WordPress post status
|
||||
*/
|
||||
function igny8_send_status_webhook($post_id, $content_data, $post_status) {
|
||||
// Get site information for logging
|
||||
$site_id = get_option('igny8_site_id', 'unknown');
|
||||
$site_domain = parse_url(home_url(), PHP_URL_HOST);
|
||||
$log_prefix = "[{$site_id}-{$site_domain}]";
|
||||
|
||||
Igny8_Logger::separator("{$log_prefix} 📤 SENDING STATUS WEBHOOK TO IGNY8");
|
||||
|
||||
// Only send webhook if connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ Connection not enabled, skipping webhook", 'webhooks');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get required data
|
||||
$content_id = $content_data['content_id'] ?? get_post_meta($post_id, '_igny8_content_id', true);
|
||||
if (!$content_id) {
|
||||
error_log('IGNY8: Cannot send status webhook - no content_id');
|
||||
Igny8_Logger::error("{$log_prefix} ❌ Cannot send status webhook - no content_id", 'webhooks');
|
||||
return;
|
||||
}
|
||||
|
||||
Igny8_Logger::info("{$log_prefix} Content ID: {$content_id}", 'webhooks');
|
||||
Igny8_Logger::info("{$log_prefix} Post ID: {$post_id}", 'webhooks');
|
||||
Igny8_Logger::info("{$log_prefix} Post Status: {$post_status}", 'webhooks');
|
||||
|
||||
// Get API endpoint from settings
|
||||
$api = new Igny8API();
|
||||
$api_base = $api->get_api_base();
|
||||
|
||||
if (!$api_base) {
|
||||
error_log('IGNY8: Cannot send status webhook - no API base URL');
|
||||
Igny8_Logger::error("{$log_prefix} ❌ Cannot send status webhook - no API base URL", 'webhooks');
|
||||
return;
|
||||
}
|
||||
|
||||
$webhook_url = rtrim($api_base, '/') . '/integration/webhooks/wordpress/status/';
|
||||
Igny8_Logger::info("{$log_prefix} Webhook URL: {$webhook_url}", 'webhooks');
|
||||
|
||||
// Get API key
|
||||
$api_key = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_api_key') : get_option('igny8_api_key');
|
||||
if (!$api_key) {
|
||||
error_log('IGNY8: Cannot send status webhook - no API key');
|
||||
Igny8_Logger::error("{$log_prefix} ❌ Cannot send status webhook - no API key", 'webhooks');
|
||||
return;
|
||||
}
|
||||
|
||||
Igny8_Logger::info("{$log_prefix} API Key: ***" . substr($api_key, -4), 'webhooks');
|
||||
|
||||
// Prepare webhook payload
|
||||
$payload = array(
|
||||
'post_id' => $post_id,
|
||||
@@ -1207,7 +1222,10 @@ function igny8_send_status_webhook($post_id, $content_data, $post_status) {
|
||||
'site_url' => get_site_url(),
|
||||
);
|
||||
|
||||
Igny8_Logger::info("{$log_prefix} Payload: " . json_encode($payload), 'webhooks');
|
||||
|
||||
// Send webhook asynchronously
|
||||
Igny8_Logger::info("{$log_prefix} Sending POST request to IGNY8...", 'webhooks');
|
||||
$response = wp_remote_post($webhook_url, array(
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
@@ -1219,9 +1237,11 @@ function igny8_send_status_webhook($post_id, $content_data, $post_status) {
|
||||
));
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
error_log('IGNY8: Status webhook failed: ' . $response->get_error_message());
|
||||
Igny8_Logger::error("{$log_prefix} ❌ Status webhook failed: " . $response->get_error_message(), 'webhooks');
|
||||
} else {
|
||||
error_log("IGNY8: Status webhook sent for content {$content_id}, post {$post_id}, status {$post_status}");
|
||||
Igny8_Logger::info("{$log_prefix} ✅ Status webhook sent successfully for content {$content_id}, post {$post_id}, status {$post_status}", 'webhooks');
|
||||
}
|
||||
|
||||
Igny8_Logger::separator("{$log_prefix} ✅ WEBHOOK SEND COMPLETED");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user