WC_Admin_Addons::fetch
Make wp_safe_remote_get request to WooCommerce.com endpoint. Optionally pass user auth token, locale or country.
Метод класса: WC_Admin_Addons{}
Хуков нет.
Возвращает
Массив|WP_Error.
Использование
$result = WC_Admin_Addons::fetch( $url, $options );
- $url(строка) (обязательный)
- URL to request.
- $options(?array)
- Options for the request. For example, to pass auth token, locale and country, pass array( 'auth' => true, 'locale' => true, 'country' => true, ).
По умолчанию: array()
Код WC_Admin_Addons::fetch() WC Admin Addons::fetch WC 10.4.3
public static function fetch( $url, $options = array() ) {
$headers = array();
if ( isset( $options['auth'] ) && $options['auth'] ) {
$auth = WC_Helper_Options::get( 'auth' );
if ( isset( $auth['access_token'] ) && ! empty( $auth['access_token'] ) ) {
$headers['Authorization'] = 'Bearer ' . $auth['access_token'];
}
}
$parameters = array();
if ( isset( $options['locale'] ) && $options['locale'] ) {
$parameters['locale'] = get_user_locale();
}
if ( isset( $options['country'] ) && $options['country'] ) {
$country = WC()->countries->get_base_country();
if ( ! empty( $country ) ) {
$parameters['country'] = $country;
}
}
// Check if URL already has query parameters.
$connector = strpos( $url, '?' ) !== false ? '&' : '?';
$query_string = ! empty( $parameters ) ? $connector . http_build_query( $parameters ) : '';
return wp_safe_remote_get(
$url . $query_string,
array(
'headers' => $headers,
'user-agent' => 'WooCommerce/' . WC()->version . '; ' . get_bloginfo( 'url' ),
)
);
}