// Handler for post submission event to create timeline entry
add_action( 'voxel/app-events/post-types/equioment/post:submitted', function( $event ) {
global $wpdb;
// Get required data
$post_id = $event->post->get_id();
$user_id = $event->post->get_author()->get_id();
$permalink = get_permalink($post_id);
// Get featured image URL
$thumbnail_id = get_post_thumbnail_id($post_id);
$image_url = wp_get_attachment_url($thumbnail_id);
// Prepare the details array
$details = array(
'link_preview' => array(
'url' => $permalink,
'title' => $event->post->get_title() . ' - ' . parse_url(get_site_url(), PHP_URL_HOST),
'image' => $image_url
)
);
// Prepare data for insert
$data = array(
'user_id' => $user_id,
'post_id' => 196,
'feed' => 'post_wall',
'content' => $permalink,
'details' => wp_json_encode($details),
'moderation' => 1,
'created_at' => current_time('mysql'),
'like_count' => 0,
'reply_count' => 0,
'_index' => str_replace(array(':', '/', '.', '-'), array('U_3A', 'U_2F', 'U_2E', 'U_2D'), $permalink)
);
// Insert the record
$table_name = $wpdb->prefix . 'voxel_timeline';
$result = $wpdb->insert($table_name, $data);
// Log the result if debugging is enabled
if (defined('WP_DEBUG') && WP_DEBUG === true) {
if ($result === false) {
error_log('Timeline insert failed for post ID: ' . $post_id . ' - ' . $wpdb->last_error);
} else {
error_log('Timeline insert successful for post ID: ' . $post_id . ' - Timeline ID: ' . $wpdb->insert_id);
}
}
});