/var/www/html_us/wp-content/plugins/woocommerce/src/Admin/API/AI/BusinessDescription.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php

declare( strict_types );

namespace 
Automattic\WooCommerce\Admin\API\AI;

use 
WP_Error;
use 
WP_REST_Request;
use 
WP_REST_Response;

defined'ABSPATH' ) || exit;

/**
 * Store Title controller
 *
 * @internal
 */
class BusinessDescription extends AIEndpoint {
    
/**
     * Endpoint.
     *
     * @var string
     */
    
protected $endpoint 'business-description';

    
/**
     * Register routes.
     */
    
public function register_routes() {
        
$this->register(
            array(
                array(
                    
'methods'             => \WP_REST_Server::CREATABLE,
                    
'callback'            => array( $this'update_business_description' ),
                    
'permission_callback' => array( Middleware::class, 'is_authorized' ),
                    
'args'                => array(
                        
'business_description' => array(
                            
'description' => __'The business description for a given store.''woocommerce' ),
                            
'type'        => 'string',
                        ),
                    ),
                ),
                
'schema' => array( $this'get_schema' ),
            )
        );
    }

    
/**
     * Update the business description.
     *
     * @param WP_REST_Request $request Request object.
     * @return WP_REST_Response|WP_Error Response object.
     */
    
public function update_business_description$request ) {

        
$business_description $request->get_param'business_description' );

        if ( ! 
$business_description ) {
            return new 
WP_Error(
                
'invalid_business_description',
                
__'Invalid business description.''woocommerce' )
            );
        }

        
update_option'last_business_description_with_ai_content_generated'$business_description );

        return 
rest_ensure_response(
            array(
                
'ai_content_generated' => true,
            )
        );
    }

    
/**
     * Get the Business Description response.
     *
     * @return array
     */
    
public function get_schema() {
        return array(
            
'ai_content_generated' => true,
        );
    }
}