logging system
This commit is contained in:
@@ -71,19 +71,28 @@ function igny8_cache_task_brief($task_id, $post_id, $api = null) {
|
||||
* @return int|WP_Error WordPress post ID or error
|
||||
*/
|
||||
function igny8_create_wordpress_post_from_task($content_data, $allowed_post_types = array()) {
|
||||
error_log('========== IGNY8 CREATE WP POST ==========');
|
||||
error_log('Content ID: ' . (isset($content_data['content_id']) ? $content_data['content_id'] : 'N/A'));
|
||||
error_log('Task ID: ' . (isset($content_data['task_id']) ? $content_data['task_id'] : 'N/A'));
|
||||
error_log('Title: ' . (isset($content_data['title']) ? $content_data['title'] : 'N/A'));
|
||||
// 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} 🎯 CREATE WORDPRESS POST FROM IGNY8");
|
||||
Igny8_Logger::info("{$log_prefix} Content ID: " . ($content_data['content_id'] ?? 'N/A'));
|
||||
Igny8_Logger::info("{$log_prefix} Task ID: " . ($content_data['task_id'] ?? 'N/A'));
|
||||
Igny8_Logger::info("{$log_prefix} Title: " . ($content_data['title'] ?? 'N/A'));
|
||||
Igny8_Logger::separator();
|
||||
|
||||
$api = new Igny8API();
|
||||
|
||||
if (!$api->is_authenticated()) {
|
||||
error_log('IGNY8: NOT AUTHENTICATED - Aborting post creation');
|
||||
Igny8_Logger::error("{$log_prefix} ❌ NOT AUTHENTICATED - Aborting post creation");
|
||||
return new WP_Error('igny8_not_authenticated', 'IGNY8 API not authenticated');
|
||||
}
|
||||
|
||||
Igny8_Logger::info("{$log_prefix} ✅ API authenticated");
|
||||
|
||||
$post_type = igny8_resolve_post_type_for_task($content_data);
|
||||
Igny8_Logger::info("{$log_prefix} STEP 1: Resolved post type: {$post_type}");
|
||||
|
||||
if (!empty($allowed_post_types) && !in_array($post_type, $allowed_post_types, true)) {
|
||||
return new WP_Error('igny8_post_type_disabled', sprintf('Post type %s is disabled for automation', $post_type));
|
||||
@@ -204,80 +213,80 @@ function igny8_create_wordpress_post_from_task($content_data, $allowed_post_type
|
||||
|
||||
// Handle categories
|
||||
if (!empty($content_data['categories'])) {
|
||||
error_log('IGNY8: Processing ' . count($content_data['categories']) . ' categories');
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Processing " . count($content_data['categories']) . " categories");
|
||||
$category_ids = igny8_process_categories($content_data['categories'], $post_id);
|
||||
if (!empty($category_ids)) {
|
||||
wp_set_post_terms($post_id, $category_ids, 'category');
|
||||
error_log('IGNY8: ✅ Assigned ' . count($category_ids) . ' categories to post ' . $post_id);
|
||||
Igny8_Logger::info("{$log_prefix} ✅ Assigned " . count($category_ids) . " categories to post {$post_id}");
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No category IDs returned from processing');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No category IDs returned from processing");
|
||||
}
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No categories in content_data');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No categories in content_data");
|
||||
}
|
||||
|
||||
// Handle tags
|
||||
if (!empty($content_data['tags'])) {
|
||||
error_log('IGNY8: Processing ' . count($content_data['tags']) . ' tags');
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Processing " . count($content_data['tags']) . " tags");
|
||||
$tag_ids = igny8_process_tags($content_data['tags'], $post_id);
|
||||
if (!empty($tag_ids)) {
|
||||
wp_set_post_terms($post_id, $tag_ids, 'post_tag');
|
||||
error_log('IGNY8: ✅ Assigned ' . count($tag_ids) . ' tags to post ' . $post_id);
|
||||
Igny8_Logger::info("{$log_prefix} ✅ Assigned " . count($tag_ids) . " tags to post {$post_id}");
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No tag IDs returned from processing');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No tag IDs returned from processing");
|
||||
}
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No tags in content_data');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No tags in content_data");
|
||||
}
|
||||
|
||||
// Handle featured image
|
||||
if (!empty($content_data['featured_image'])) {
|
||||
error_log('IGNY8: Setting featured image from featured_image field');
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting featured image from featured_image field");
|
||||
igny8_set_featured_image($post_id, $content_data['featured_image']);
|
||||
} elseif (!empty($content_data['featured_image_url'])) {
|
||||
error_log('IGNY8: Setting featured image from featured_image_url field: ' . $content_data['featured_image_url']);
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting featured image from URL: " . $content_data['featured_image_url']);
|
||||
igny8_set_featured_image($post_id, $content_data['featured_image_url']);
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No featured image in content_data');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No featured image in content_data");
|
||||
}
|
||||
// Handle meta title and meta description (SEO)
|
||||
if (!empty($content_data['meta_title'])) {
|
||||
error_log('IGNY8: Setting SEO meta title: ' . $content_data['meta_title']);
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting SEO meta title: " . $content_data['meta_title']);
|
||||
update_post_meta($post_id, '_yoast_wpseo_title', $content_data['meta_title']);
|
||||
update_post_meta($post_id, '_seopress_titles_title', $content_data['meta_title']);
|
||||
update_post_meta($post_id, '_aioseo_title', $content_data['meta_title']);
|
||||
// Generic meta
|
||||
update_post_meta($post_id, '_igny8_meta_title', $content_data['meta_title']);
|
||||
} elseif (!empty($content_data['seo_title'])) {
|
||||
error_log('IGNY8: Setting SEO meta title from seo_title: ' . $content_data['seo_title']);
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting SEO meta title from seo_title: " . $content_data['seo_title']);
|
||||
update_post_meta($post_id, '_yoast_wpseo_title', $content_data['seo_title']);
|
||||
update_post_meta($post_id, '_seopress_titles_title', $content_data['seo_title']);
|
||||
update_post_meta($post_id, '_aioseo_title', $content_data['seo_title']);
|
||||
update_post_meta($post_id, '_igny8_meta_title', $content_data['seo_title']);
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No SEO title in content_data');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No SEO title in content_data");
|
||||
}
|
||||
|
||||
if (!empty($content_data['meta_description'])) {
|
||||
error_log('IGNY8: Setting SEO meta description');
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting SEO meta description");
|
||||
update_post_meta($post_id, '_yoast_wpseo_metadesc', $content_data['meta_description']);
|
||||
update_post_meta($post_id, '_seopress_titles_desc', $content_data['meta_description']);
|
||||
update_post_meta($post_id, '_aioseo_description', $content_data['meta_description']);
|
||||
// Generic meta
|
||||
update_post_meta($post_id, '_igny8_meta_description', $content_data['meta_description']);
|
||||
} elseif (!empty($content_data['seo_description'])) {
|
||||
error_log('IGNY8: Setting SEO meta description from seo_description');
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting SEO meta description from seo_description");
|
||||
update_post_meta($post_id, '_yoast_wpseo_metadesc', $content_data['seo_description']);
|
||||
update_post_meta($post_id, '_seopress_titles_desc', $content_data['seo_description']);
|
||||
update_post_meta($post_id, '_aioseo_description', $content_data['seo_description']);
|
||||
update_post_meta($post_id, '_igny8_meta_description', $content_data['seo_description']);
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No SEO description in content_data');
|
||||
Igny8_Logger::warning("{$log_prefix} ⚠️ No SEO description in content_data");
|
||||
}
|
||||
|
||||
// Handle gallery images
|
||||
if (!empty($content_data['gallery_images'])) {
|
||||
error_log('IGNY8: Setting gallery with ' . count($content_data['gallery_images']) . ' images');
|
||||
Igny8_Logger::info("{$log_prefix} STEP: Setting gallery with " . count($content_data['gallery_images']) . " images");
|
||||
igny8_set_gallery_images($post_id, $content_data['gallery_images']);
|
||||
}
|
||||
|
||||
@@ -311,9 +320,9 @@ function igny8_create_wordpress_post_from_task($content_data, $allowed_post_type
|
||||
$response = $api->put("/writer/tasks/{$content_data['task_id']}/", $update_data);
|
||||
|
||||
if ($response['success']) {
|
||||
error_log("IGNY8: Updated task {$content_data['task_id']} with WordPress post {$post_id} (status: {$wp_status})");
|
||||
Igny8_Logger::info("{$log_prefix} ✅ Updated IGNY8 task {$content_data['task_id']} with WordPress post {$post_id} (status: {$wp_status})");
|
||||
} else {
|
||||
error_log("IGNY8: Failed to update task: " . ($response['error'] ?? 'Unknown error'));
|
||||
Igny8_Logger::error("{$log_prefix} ❌ Failed to update IGNY8 task: " . ($response['error'] ?? 'Unknown error'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +334,12 @@ function igny8_create_wordpress_post_from_task($content_data, $allowed_post_type
|
||||
// Send status webhook to IGNY8
|
||||
igny8_send_status_webhook($post_id, $content_data, $wp_status);
|
||||
|
||||
Igny8_Logger::separator("{$log_prefix} 🎉 POST CREATION COMPLETED SUCCESSFULLY");
|
||||
Igny8_Logger::info("{$log_prefix} WordPress Post ID: {$post_id}");
|
||||
Igny8_Logger::info("{$log_prefix} Post URL: " . get_permalink($post_id));
|
||||
Igny8_Logger::info("{$log_prefix} Post Status: {$wp_status}");
|
||||
Igny8_Logger::separator();
|
||||
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user