1234
This commit is contained in:
@@ -71,9 +71,15 @@ 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'));
|
||||
|
||||
$api = new Igny8API();
|
||||
|
||||
if (!$api->is_authenticated()) {
|
||||
error_log('IGNY8: NOT AUTHENTICATED - Aborting post creation');
|
||||
return new WP_Error('igny8_not_authenticated', 'IGNY8 API not authenticated');
|
||||
}
|
||||
|
||||
@@ -198,45 +204,81 @@ 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');
|
||||
$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);
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No category IDs returned from processing');
|
||||
}
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No categories in content_data');
|
||||
}
|
||||
|
||||
// Handle tags
|
||||
if (!empty($content_data['tags'])) {
|
||||
error_log('IGNY8: 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);
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No tag IDs returned from processing');
|
||||
}
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ 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_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_set_featured_image($post_id, $content_data['featured_image_url']);
|
||||
} else {
|
||||
error_log('IGNY8: ⚠️ No featured image in content_data');
|
||||
}
|
||||
|
||||
// Handle image gallery (1-5 images)
|
||||
if (!empty($content_data['gallery_images'])) {
|
||||
igny8_set_image_gallery($post_id, $content_data['gallery_images']);
|
||||
}
|
||||
|
||||
// Handle meta title and meta description (SEO)
|
||||
if (!empty($content_data['meta_title'])) {
|
||||
error_log('IGNY8: 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']);
|
||||
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');
|
||||
}
|
||||
|
||||
if (!empty($content_data['meta_description'])) {
|
||||
error_log('IGNY8: 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');
|
||||
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');
|
||||
}
|
||||
|
||||
// Handle gallery images
|
||||
if (!empty($content_data['gallery_images'])) {
|
||||
error_log('IGNY8: Setting gallery with ' . count($content_data['gallery_images']) . ' images');
|
||||
igny8_set_gallery_images($post_id, $content_data['gallery_images']);
|
||||
}
|
||||
|
||||
// Get the actual WordPress post status (after creation)
|
||||
|
||||
Reference in New Issue
Block a user