Automattic\WooCommerce\Admin\RemoteSpecs
DataSourcePoller::read_data_source
Read a single data source and return the read specs
Метод класса: DataSourcePoller{}
Хуков нет.
Возвращает
Массив. The specs that have been read from the data source.
Использование
$result = DataSourcePoller::read_data_source( $url );
- $url(строка) (обязательный)
- The URL to read the specs from.
Код DataSourcePoller::read_data_source() DataSourcePoller::read data source WC 10.5.2
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(
'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;
}