WC_Helper_Updater::_update_checkprivate staticWC 1.0

Run an update check API call.

The call is cached based on the payload (product ids, file ids). If the payload changes, the cache is going to miss.

Method of the class: WC_Helper_Updater{}

No Hooks.

Returns

Array. Update data for each requested product.

Usage

$result = WC_Helper_Updater::_update_check( $payload );
$payload(array) (required)
Information about the plugin to update.

WC_Helper_Updater::_update_check() code WC 10.4.3

private static function _update_check( $payload ) {
	if ( empty( $payload ) ) {
		return array();
	}
	ksort( $payload );
	$hash = md5( wp_json_encode( $payload ) );

	$cache_key = '_woocommerce_helper_updates';
	$data      = get_transient( $cache_key );

	if ( self::should_use_cached_update_data( $data, $hash ) ) {
		return $data['products'];
	}

	$data = array(
		'hash'     => $hash,
		'updated'  => time(),
		'products' => array(),
		'errors'   => array(),
	);

	if ( WC_Helper::is_site_connected() ) {
		$request = WC_Helper_API::post(
			'update-check',
			array(
				'body'          => wp_json_encode( array( 'products' => $payload ) ),
				'authenticated' => true,
			)
		);
	} else {
		$request = WC_Helper_API::post(
			'update-check-public',
			array(
				'body' => wp_json_encode( array( 'products' => $payload ) ),
			)
		);
	}

	if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
		$data['errors'][] = 'http-error';
	} else {
		$data['products'] = json_decode( wp_remote_retrieve_body( $request ), true );
	}

	set_transient( $cache_key, $data, 12 * HOUR_IN_SECONDS );
	return $data['products'];
}