increment_generation_count($attachment_id); } } /** * Increment the generation count for an image * * @param int $attachment_id The attachment ID * @return void */ public function increment_generation_count($attachment_id) { $current_count = (int) get_post_meta($attachment_id, 'aiimatg_generated_count', true); update_post_meta($attachment_id, 'aiimatg_generated_count', $current_count + 1); } /** * Add generation count to REST API responses * * @param WP_REST_Response $response The response object * @param WP_Post $post The post object * @param WP_REST_Request $request The request object * @return WP_REST_Response Modified response */ public function add_generation_count_to_rest($response, $post, $request) { if ($post->post_type === 'attachment' && !is_wp_error($response)) { $response->data['aiimatg_generated_count'] = (int) get_post_meta($post->ID, 'aiimatg_generated_count', true); } return $response; } /** * Add generation count to image data * * @param array $image_data The image data * @return array Modified image data */ public function add_generation_count_to_image_data($image_data) { if (isset($image_data['id'])) { $image_data['generated_count'] = (int) get_post_meta($image_data['id'], 'aiimatg_generated_count', true); } return $image_data; } /** * Get generation count for an image * * @param int $attachment_id The attachment ID * @return int The generation count */ public function get_generation_count($attachment_id) { return (int) get_post_meta($attachment_id, 'aiimatg_generated_count', true); } }