WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Admin

DataSourcePoller::read_data_source() protected WC 1.0

Read a single data source and return the read specs

{} It's a method of the class: DataSourcePoller{}

No Hooks.

Return

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.

Code of DataSourcePoller::read_data_source() WC 6.1.0

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
		)
	);

	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 [];
	}

	$body  = $response['body'];
	$specs = json_decode( $body );

	if ( null === $specs ) {
		$logger->error(
			'Empty response in data feed',
			$logger_context
		);

		return [];
	}

	if ( ! is_array( $specs ) ) {
		$logger->error(
			'Data feed is not an array',
			$logger_context
		);

		return [];
	}

	return $specs;
}