/var/www/html_us/wp-content/plugins/woocommerce/src/Utilities/RestApiUtil.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
<?php

namespace Automattic\WooCommerce\Utilities;

/**
 * Utility methods related to the REST API.
 */
class RestApiUtil {

    
/**
     * Get data from a WooCommerce API endpoint.
     * This method used to be part of the WooCommerce Legacy REST API.
     *
     * @since 9.0.0
     *
     * @param string $endpoint Endpoint.
     * @param array  $params Params to pass with request.
     * @return array|\WP_Error
     */
    
public function get_endpoint_data$endpoint$params = array() ) {
        
$request = new \WP_REST_Request'GET'$endpoint );
        if ( 
$params ) {
            
$request->set_query_params$params );
        }
        
$response rest_do_request$request );
        
$server   rest_get_server();
        
$json     wp_json_encode$server->response_to_data$responsefalse ) );
        return 
json_decode$jsontrue );
    }
}