get_core_checksums()

最后更新于:2021-11-26 09:02:14

get_core_checksums( string$version, string$locale)

Gets and caches the checksums for the given version of GeChiUI.

参数

$version

(string) (Required) Version string to query.

$locale

(string) (Required) Locale to query.

响应

(array|false) An array of checksums on success, false on failure.

源文件

文件: gc-admin/includes/update.php

function get_core_checksums( $version, $locale ) {
	$http_url = 'http://api.gechiui.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
	$url      = $http_url;

	$ssl = gc_http_supports( array( 'ssl' ) );
	if ( $ssl ) {
		$url = set_url_scheme( $url, 'https' );
	}

	$options = array(
		'timeout' => gc_doing_cron() ? 30 : 3,
	);

	$response = gc_remote_get( $url, $options );
	if ( $ssl && is_gc_error( $response ) ) {
		trigger_error(
			sprintf(
				/* translators: %s: Support forums URL. */
				__( 'An unexpected error occurred. Something may be wrong with GeChiUI.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://docs.gechiui.com/functions/get_core_checksums/%s">support forums</a>.' ),
				__( 'https://gechiui.org/support/forums/' )
			) . ' ' . __( '(GeChiUI could not establish a secure connection to GeChiUI.org. Please contact your server administrator.)' ),
			headers_sent() || GC_DEBUG ? E_USER_WARNING : E_USER_NOTICE
		);
		$response = gc_remote_get( $http_url, $options );
	}

	if ( is_gc_error( $response ) || 200 != gc_remote_retrieve_response_code( $response ) ) {
		return false;
	}

	$body = trim( gc_remote_retrieve_body( $response ) );
	$body = json_decode( $body, true );

	if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
		return false;
	}

	return $body['checksums'];
}