/home/suroeste/public_html/wp-content/plugins/woocommerce/src/StoreApi/Routes/V1/AI
Edit: /home/suroeste/public_html/wp-content/plugins/woocommerce/src/StoreApi/Routes/V1/AI/Patterns.php (3098B)
\WP_REST_Server::CREATABLE,
'callback' => [ $this, 'get_response' ],
'permission_callback' => [ Middleware::class, 'is_authorized' ],
'args' => [
'business_description' => [
'description' => __( 'The business description for a given store.', 'woocommerce' ),
'type' => 'string',
],
'images' => [
'description' => __( 'The images for a given store.', 'woocommerce' ),
'type' => 'object',
],
],
],
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'get_response' ],
'permission_callback' => [ Middleware::class, 'is_authorized' ],
],
'schema' => [ $this->schema, 'get_public_item_schema' ],
'allow_batch' => [ 'v1' => true ],
];
}
/**
* Update patterns with the content and images powered by AI.
*
* @param \WP_REST_Request $request Request object.
*
* @return WP_Error|\WP_HTTP_Response|\WP_REST_Response
*/
protected function get_route_post_response( \WP_REST_Request $request ) {
$business_description = sanitize_text_field( wp_unslash( $request['business_description'] ) );
$ai_connection = new Connection();
$site_id = $ai_connection->get_site_id();
if ( is_wp_error( $site_id ) ) {
return $this->error_to_response( $site_id );
}
$token = $ai_connection->get_jwt_token( $site_id );
$images = $request['images'];
try {
( new UpdatePatterns() )->generate_content( $ai_connection, $token, $images, $business_description );
return rest_ensure_response( array( 'ai_content_generated' => true ) );
} catch ( WP_Error $e ) {
return $this->error_to_response( $e );
}
}
/**
* Remove patterns generated by AI.
*
* @param \WP_REST_Request $request Request object.
*
* @return bool|string|WP_Error|\WP_REST_Response
*/
protected function get_route_delete_response( \WP_REST_Request $request ) {
PatternsHelper::delete_patterns_ai_data_post();
return rest_ensure_response( array( 'removed' => true ) );
}
}