WC_Helper_Updater::_update_check()private 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.

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

No Hooks.

Return

Array. Update data for each requested product.

Usage

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

Code of WC_Helper_Updater::_update_check() WC 6.7.0

private static function _update_check( $payload ) {
	ksort( $payload );
	$hash = md5( wp_json_encode( $payload ) );

	$cache_key = '_woocommerce_helper_updates';
	$data      = get_transient( $cache_key );
	if ( false !== $data ) {
		if ( hash_equals( $hash, $data['hash'] ) ) {
			return $data['products'];
		}
	}

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

	$request = WC_Helper_API::post(
		'update-check',
		array(
			'body'          => wp_json_encode( array( 'products' => $payload ) ),
			'authenticated' => true,
		)
	);

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