Automattic\WooCommerce\Blocks\AIContent
UpdatePatterns::generate_content()
Generate AI content and assign AI-managed images to Patterns.
Метод класса: UpdatePatterns{}
Хуков нет.
Возвращает
true|false|WP_Error
.
Использование
$UpdatePatterns = new UpdatePatterns(); $UpdatePatterns->generate_content( $ai_connection, $token, $images, $business_description );
- $ai_connection(Connection) (обязательный)
- The AI connection.
- $token(строка|WP_Error) (обязательный)
- The JWT token.
- $images(массив|WP_Error) (обязательный)
- The array of images.
- $business_description(строка) (обязательный)
- The business description.
Код UpdatePatterns::generate_content() UpdatePatterns::generate content WC 9.5.1
public function generate_content( $ai_connection, $token, $images, $business_description ) { if ( is_wp_error( $token ) ) { return $token; } $images = ContentProcessor::verify_images( $images, $ai_connection, $token, $business_description ); $patterns_dictionary = PatternsHelper::get_patterns_dictionary(); if ( is_wp_error( $patterns_dictionary ) ) { return $patterns_dictionary; } $patterns = $this->assign_selected_images_to_patterns( $patterns_dictionary, $images['images'] ); if ( is_wp_error( $patterns ) ) { return new WP_Error( 'failed_to_set_pattern_images', __( 'Failed to set the pattern images.', 'woocommerce' ) ); } $ai_generated_patterns_content = $this->generate_ai_content_for_patterns( $ai_connection, $token, $patterns, $business_description ); if ( is_wp_error( $ai_generated_patterns_content ) ) { return new WP_Error( 'failed_to_set_pattern_content', __( 'Failed to set the pattern content.', 'woocommerce' ) ); } $patterns_ai_data_post = PatternsHelper::get_patterns_ai_data_post(); if ( isset( $patterns_ai_data_post->post_content ) && json_decode( $patterns_ai_data_post->post_content ) === $ai_generated_patterns_content ) { return true; } $updated_content = PatternsHelper::upsert_patterns_ai_data_post( $ai_generated_patterns_content ); if ( is_wp_error( $updated_content ) ) { return new WP_Error( 'failed_to_update_patterns_content', __( 'Failed to update patterns content.', 'woocommerce' ) ); } return true; }