WC_Helper::fetch_helper_connection_info
Get details of the current WooCommerce.com connection.
Метод класса: WC_Helper{}
Хуков нет.
Возвращает
Массив|WP_Error.
Использование
$result = WC_Helper::fetch_helper_connection_info();
Код WC_Helper::fetch_helper_connection_info() WC Helper::fetch helper connection info WC 10.3.4
public static function fetch_helper_connection_info() {
$data = self::get_cached_connection_data();
if ( false !== $data ) {
return $data;
}
$request = WC_Helper_API::get(
'connection-info',
array(
'authenticated' => true,
'query_string' => '?url=' . rawurlencode( home_url() ),
)
);
$status = wp_remote_retrieve_response_code( $request );
if ( 200 !== $status ) {
return new WP_Error(
'invalid_response',
'Invalid response from WooCommerce.com',
array( 'status' => $status )
);
}
$connection_data = json_decode( wp_remote_retrieve_body( $request ), true );
$url = $connection_data['url'] ?? '';
if ( ! empty( $url ) ) {
$auth = WC_Helper_Options::get( 'auth' );
$auth['url'] = $url;
WC_Helper_Options::update( 'auth', $auth );
set_transient( self::CACHE_KEY_CONNECTION_DATA, $connection_data, 1 * HOUR_IN_SECONDS );
}
return $connection_data;
}