ACF

Updater::get_plugin_updatespublicACF 5.6.9

Checks for plugin updates.

Метод класса: Updater{}

Хуков нет.

Возвращает

Массив|WP_Error..

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

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

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

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

Код Updater::get_plugin_updates() ACF 6.4.2

public function get_plugin_updates( $force_check = false ) {
	$transient_name = 'acf_plugin_updates';

	// Don't call our site if no plugins have registered updates.
	if ( empty( $this->plugins ) ) {
		return array();
	}

	// 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;
		}
	}

	$post = array(
		'plugins' => wp_json_encode( $this->plugins ),
		'wp'      => wp_json_encode(
			array(
				'wp_name'      => get_bloginfo( 'name' ),
				'wp_url'       => acf_get_home_url(),
				'wp_version'   => get_bloginfo( 'version' ),
				'wp_language'  => get_bloginfo( 'language' ),
				'wp_timezone'  => get_option( 'timezone_string' ),
				'wp_multisite' => (int) is_multisite(),
				'php_version'  => PHP_VERSION,
			)
		),
		'acf'     => wp_json_encode(
			array(
				'acf_version' => get_option( 'acf_version' ),
				'acf_pro'     => acf_is_pro(),
				'block_count' => function_exists( 'acf_pro_get_registered_block_count' ) ? acf_pro_get_registered_block_count() : 0,
			)
		),
	);

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

	// Append checked reference.
	if ( is_array( $response ) ) {
		$response['checked'] = $checked;

		if ( isset( $response['license_status'] ) && function_exists( 'acf_pro_update_license_status' ) ) {
			acf_pro_update_license_status( $response['license_status'] );
			unset( $response['license_status'] );
		}
	}

	// Allow json to include expiration but force minimum and max for safety.
	$expiration = $this->get_expiration( $response );

	// Update transient and return.
	set_transient( $transient_name, $response, $expiration );
	return $response;
}