ACF_Updates::get_plugin_updates()publicACF 5.6.9

get_plugin_updates

Checks for plugin updates.

{} Это метод класса: ACF_Updates{}

Хуков нет.

Возвращает

Массив|WP_Error..

Использование

$ACF_Updates = new ACF_Updates();
$ACF_Updates->get_plugin_updates( $force_check );
$force_check(true|false)
Bypasses cached result.
По умолчанию: false

Список изменений

С версии 5.6.9 Введена.
С версии 5.7.2 Added 'checked' comparison

Код ACF_Updates::get_plugin_updates() ACF 5.10.2

function get_plugin_updates( $force_check = false ) {

	// var
	$transient_name = 'acf_plugin_updates';

	// construct array of 'checked' plugins
	// sort by key to avoid detecting change due to "include order"
	$checked = array();
	foreach ( $this->plugins as $basename => $plugin ) {
		$checked[ $basename ] = $plugin['version'];
	}
	ksort( $checked );

	// $force_check prevents transient lookup
	if ( ! $force_check ) {
		$transient = get_transient( $transient_name );

		// if cached response was found, compare $transient['checked'] against $checked and ignore if they don't match (plugins/versions have changed)
		if ( is_array( $transient ) ) {
			$transient_checked = isset( $transient['checked'] ) ? $transient['checked'] : array();
			if ( wp_json_encode( $checked ) !== wp_json_encode( $transient_checked ) ) {
				$transient = false;
			}
		}
		if ( $transient !== false ) {
			return $transient;
		}
	}

	// vars
	$post = array(
		'plugins' => wp_json_encode( $this->plugins ),
		'wp'      => wp_json_encode(
			array(
				'wp_name'     => get_bloginfo( 'name' ),
				'wp_url'      => home_url(),
				'wp_version'  => get_bloginfo( 'version' ),
				'wp_language' => get_bloginfo( 'language' ),
				'wp_timezone' => get_option( 'timezone_string' ),
			)
		),
		'acf'     => wp_json_encode(
			array(
				'acf_version' => get_option( 'acf_version' ),
				'acf_pro'     => ( defined( 'ACF_PRO' ) && ACF_PRO ),
			)
		),
	);

	// request
	$response = $this->request( 'v2/plugins/update-check', $post );

	// append checked reference
	if ( is_array( $response ) ) {
		$response['checked'] = $checked;
	}

	// allow json to include expiration but force minimum and max for safety
	$expiration = $this->get_expiration( $response, DAY_IN_SECONDS, MONTH_IN_SECONDS );

	// update transient
	set_transient( $transient_name, $response, $expiration );

	// return
	return $response;
}