1234
This commit is contained in:
@@ -56,16 +56,16 @@ class Igny8RestAPI {
|
||||
)
|
||||
));
|
||||
|
||||
// Get post status by content_id
|
||||
register_rest_route('igny8/v1', '/post-status/(?P<content_id>\d+)', array(
|
||||
// Get post status by content_id or post_id
|
||||
register_rest_route('igny8/v1', '/post-status/(?P<id>\d+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_post_status_by_content_id'),
|
||||
'callback' => array($this, 'get_post_status'),
|
||||
'permission_callback' => array($this, 'check_permission'),
|
||||
'args' => array(
|
||||
'content_id' => array(
|
||||
'id' => array(
|
||||
'required' => true,
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 content ID'
|
||||
'description' => 'WordPress post ID or IGNY8 content ID (tries both)'
|
||||
)
|
||||
)
|
||||
));
|
||||
@@ -254,12 +254,13 @@ class Igny8RestAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post status by content_id
|
||||
* Get post status by post ID or content_id
|
||||
* Accepts either WordPress post_id or IGNY8 content_id
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_post_status_by_content_id($request) {
|
||||
public function get_post_status($request) {
|
||||
// Double-check connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
@@ -269,49 +270,71 @@ class Igny8RestAPI {
|
||||
);
|
||||
}
|
||||
|
||||
$content_id = intval($request['content_id']);
|
||||
$id = intval($request['id']);
|
||||
$post = null;
|
||||
$lookup_method = null;
|
||||
|
||||
// Find post by content_id meta
|
||||
$posts = get_posts(array(
|
||||
'meta_key' => '_igny8_content_id',
|
||||
'meta_value' => $content_id,
|
||||
'post_type' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any',
|
||||
'fields' => 'ids' // Only get IDs for performance
|
||||
));
|
||||
// First try as WordPress post ID
|
||||
if (post_type_exists('post') || post_type_exists('page')) {
|
||||
$post = get_post($id);
|
||||
if ($post) {
|
||||
$lookup_method = 'wordpress_post_id';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($posts)) {
|
||||
// If not found, try as IGNY8 content_id
|
||||
if (!$post) {
|
||||
$posts = get_posts(array(
|
||||
'meta_key' => '_igny8_content_id',
|
||||
'meta_value' => $id,
|
||||
'post_type' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any'
|
||||
));
|
||||
|
||||
if (!empty($posts)) {
|
||||
$post = $posts[0];
|
||||
$lookup_method = 'igny8_content_id';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$post) {
|
||||
return rest_ensure_response(array(
|
||||
'success' => false,
|
||||
'message' => 'Post not found',
|
||||
'content_id' => $content_id
|
||||
'searched_id' => $id
|
||||
));
|
||||
}
|
||||
|
||||
$post_id = $posts[0];
|
||||
$post = get_post($post_id);
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'success' => true,
|
||||
'data' => array(
|
||||
'post_id' => $post_id,
|
||||
'post_id' => $post->ID,
|
||||
'post_status' => $post->post_status,
|
||||
'post_title' => $post->post_title,
|
||||
'post_type' => $post->post_type,
|
||||
'post_modified' => $post->post_modified,
|
||||
'post_url' => get_permalink($post->ID),
|
||||
'wordpress_status' => $post->post_status,
|
||||
'igny8_status' => igny8_map_wp_status_to_igny8($post->post_status),
|
||||
'status_mapping' => array(
|
||||
'publish' => 'completed',
|
||||
'draft' => 'draft',
|
||||
'pending' => 'pending',
|
||||
'private' => 'completed',
|
||||
'trash' => 'archived',
|
||||
'future' => 'scheduled'
|
||||
),
|
||||
'content_id' => $content_id,
|
||||
'url' => get_permalink($post_id),
|
||||
'last_synced' => get_post_meta($post_id, '_igny8_last_synced', true)
|
||||
'content_id' => get_post_meta($post->ID, '_igny8_content_id', true),
|
||||
'task_id' => get_post_meta($post->ID, '_igny8_task_id', true),
|
||||
'last_synced' => get_post_meta($post->ID, '_igny8_last_synced', true),
|
||||
'lookup_method' => $lookup_method
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post status by content_id (DEPRECATED - use get_post_status instead)
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_post_status_by_content_id($request) {
|
||||
// Redirect to new unified method
|
||||
return $this->get_post_status($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: generate a request_id (UUIDv4 if available)
|
||||
@@ -483,6 +506,21 @@ class Igny8RestAPI {
|
||||
$content_id = isset($content_data['content_id']) ? $content_data['content_id'] : null;
|
||||
$task_id = isset($content_data['task_id']) ? $content_data['task_id'] : null;
|
||||
|
||||
// ALWAYS log incoming data for debugging
|
||||
error_log('========== IGNY8 PUBLISH REQUEST ==========');
|
||||
error_log('Content ID: ' . $content_id);
|
||||
error_log('Task ID: ' . $task_id);
|
||||
error_log('Title: ' . (isset($content_data['title']) ? $content_data['title'] : 'MISSING'));
|
||||
error_log('Content HTML: ' . (isset($content_data['content_html']) ? strlen($content_data['content_html']) . ' chars' : 'MISSING'));
|
||||
error_log('Categories: ' . (isset($content_data['categories']) ? json_encode($content_data['categories']) : 'MISSING'));
|
||||
error_log('Tags: ' . (isset($content_data['tags']) ? json_encode($content_data['tags']) : 'MISSING'));
|
||||
error_log('Featured Image: ' . (isset($content_data['featured_image_url']) ? $content_data['featured_image_url'] : 'MISSING'));
|
||||
error_log('Gallery Images: ' . (isset($content_data['gallery_images']) ? count($content_data['gallery_images']) . ' images' : 'MISSING'));
|
||||
error_log('SEO Title: ' . (isset($content_data['seo_title']) ? 'YES' : 'NO'));
|
||||
error_log('SEO Description: ' . (isset($content_data['seo_description']) ? 'YES' : 'NO'));
|
||||
error_log('Primary Keyword: ' . (isset($content_data['primary_keyword']) ? $content_data['primary_keyword'] : 'MISSING'));
|
||||
error_log('===========================================');
|
||||
|
||||
// Validate required fields
|
||||
if (empty($content_id)) {
|
||||
return $this->build_unified_response(
|
||||
|
||||
Reference in New Issue
Block a user