WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

CLI_Command::get_updates() private WP-CLI 1.0

Returns update information.

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

Хуков нет.

Возвращает

null. Ничего.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_updates( $assoc_args );
$assoc_args (обязательный)
-

Код CLI_Command::get_updates() WP-CLI 2.5.0

private function get_updates( $assoc_args ) {
	$url = 'https://api.github.com/repos/wp-cli/wp-cli/releases?per_page=100';

	$options = [
		'timeout'  => 30,
		'insecure' => (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ),
	];

	$headers = [
		'Accept' => 'application/json',
	];

	$github_token = getenv( 'GITHUB_TOKEN' );
	if ( false !== $github_token ) {
		$headers['Authorization'] = 'token ' . $github_token;
	}

	$response = Utils\http_request( 'GET', $url, null, $headers, $options );

	if ( ! $response->success || 200 !== $response->status_code ) {
		WP_CLI::error( sprintf( 'Failed to get latest version (HTTP code %d).', $response->status_code ) );
	}

	$release_data = json_decode( $response->body );

	$updates = [
		'major' => false,
		'minor' => false,
		'patch' => false,
	];
	foreach ( $release_data as $release ) {

		// Get rid of leading "v" if there is one set.
		$release_version = $release->tag_name;
		if ( 'v' === substr( $release_version, 0, 1 ) ) {
			$release_version = ltrim( $release_version, 'v' );
		}

		$update_type = Utils\get_named_sem_ver( $release_version, WP_CLI_VERSION );
		if ( ! $update_type ) {
			continue;
		}

		if ( ! isset( $release->assets[0]->browser_download_url ) ) {
			continue;
		}

		if ( ! empty( $updates[ $update_type ] ) && ! Comparator::greaterThan( $release_version, $updates[ $update_type ]['version'] ) ) {
			continue;
		}

		$updates[ $update_type ] = [
			'version'     => $release_version,
			'update_type' => $update_type,
			'package_url' => $release->assets[0]->browser_download_url,
		];
	}

	foreach ( $updates as $type => $value ) {
		if ( empty( $value ) ) {
			unset( $updates[ $type ] );
		}
	}

	foreach ( [ 'major', 'minor', 'patch' ] as $type ) {
		if ( true === Utils\get_flag_value( $assoc_args, $type ) ) {
			return ! empty( $updates[ $type ] ) ? [ $updates[ $type ] ] : false;
		}
	}

	if ( empty( $updates ) && preg_match( '#-alpha-(.+)$#', WP_CLI_VERSION, $matches ) ) {
		$version_url = 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/NIGHTLY_VERSION';
		$response    = Utils\http_request( 'GET', $version_url, null, [], $options );
		if ( ! $response->success || 200 !== $response->status_code ) {
			WP_CLI::error( sprintf( 'Failed to get current nightly version (HTTP code %d)', $response->status_code ) );
		}
		$nightly_version = trim( $response->body );
		if ( WP_CLI_VERSION !== $nightly_version ) {
			$updates['nightly'] = [
				'version'     => $nightly_version,
				'update_type' => 'nightly',
				'package_url' => 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar',
			];
		}
	}

	return array_values( $updates );
}