fix fix fix

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-01 00:13:46 +00:00
parent 90b532d13b
commit 42bc24f2c0
11 changed files with 1592 additions and 26 deletions

View File

@@ -322,6 +322,9 @@ function igny8_create_wordpress_post_from_task($content_data, $allowed_post_type
update_post_meta($post_id, '_igny8_content_id', $content_data['content_id']);
}
// Send status webhook to IGNY8
igny8_send_status_webhook($post_id, $content_data, $wp_status);
return $post_id;
}
@@ -1140,3 +1143,70 @@ function igny8_cron_sync_from_igny8() {
}
}
/**
* Send status webhook to IGNY8 backend
* Notifies IGNY8 when WordPress post status changes
*
* @param int $post_id WordPress post ID
* @param array $content_data Content data containing content_id
* @param string $post_status WordPress post status
*/
function igny8_send_status_webhook($post_id, $content_data, $post_status) {
// Only send webhook if connection is enabled
if (!igny8_is_connection_enabled()) {
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');
return;
}
// 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');
return;
}
$webhook_url = rtrim($api_base, '/') . '/integration/webhooks/wordpress/status/';
// 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');
return;
}
// Prepare webhook payload
$payload = array(
'post_id' => $post_id,
'content_id' => intval($content_id),
'post_status' => $post_status,
'post_url' => get_permalink($post_id),
'post_title' => get_the_title($post_id),
'site_url' => get_site_url(),
);
// Send webhook asynchronously
$response = wp_remote_post($webhook_url, array(
'headers' => array(
'Content-Type' => 'application/json',
'X-IGNY8-API-KEY' => $api_key,
),
'body' => json_encode($payload),
'timeout' => 10,
'blocking' => false, // Non-blocking for better performance
));
if (is_wp_error($response)) {
error_log('IGNY8: Status webhook failed: ' . $response->get_error_message());
} else {
error_log("IGNY8: Status webhook sent for content {$content_id}, post {$post_id}, status {$post_status}");
}
}

View File

@@ -77,6 +77,9 @@ function igny8_sync_post_status_to_igny8($post_id, $post, $update) {
update_post_meta($post_id, '_igny8_wordpress_status', $post_status);
update_post_meta($post_id, '_igny8_last_synced', current_time('mysql'));
error_log("IGNY8: Synced post {$post_id} status ({$post_status}) to task {$task_id}");
// Send status webhook to IGNY8 backend
igny8_send_status_webhook($post_id, array('content_id' => $content_id), $post_status);
} else {
error_log("IGNY8: Failed to sync post status: " . ($response['error'] ?? 'Unknown error'));
}