Automattic\WooCommerce\Admin\RemoteSpecs
DataSourcePoller::read_data_source
Read a single data source and return the read specs
Method of the class: DataSourcePoller{}
Hooks from the method
Returns
Array. The specs that have been read from the data source.
Usage
$result = DataSourcePoller::read_data_source( $url );
- $url(string) (required)
- The URL to read the specs from.
DataSourcePoller::read_data_source() DataSourcePoller::read data source code WC 10.8.1
protected static function read_data_source( $url ) {
$logger_context = array( 'source' => $url );
$logger = self::get_logger();
$response = wp_remote_get(
add_query_arg(
'locale',
get_user_locale(),
$url
),
array(
/**
* Filters the HTTP timeout (in seconds) used when fetching remote specs data sources.
*
* @since 10.8.0
* @param int $timeout Timeout in seconds. Default 3.
*/
'timeout' => max( 1, absint( apply_filters( 'woocommerce_data_source_poller_timeout', 3 ) ) ),
'user-agent' => 'WooCommerce/' . WC_VERSION . '; ' . home_url( '/' ),
)
);
if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
$logger->error(
'Error getting data feed',
$logger_context
);
// phpcs:ignore
$logger->error( print_r( $response, true ), $logger_context );
return array();
}
$body = $response['body'];
$specs = json_decode( $body );
if ( null === $specs ) {
$logger->error(
'Empty response in data feed',
$logger_context
);
return array();
}
if ( ! is_array( $specs ) ) {
$logger->error(
'Data feed is not an array',
$logger_context
);
return array();
}
return $specs;
}