WP_Automatic_Updater::is_vcs_checkout │ public │ WP 3.7.0

Checks for version control checkouts.

Checks for Subversion, Git, Mercurial, and Bazaar. It recursively looks up the filesystem to the top of the drive, erring on the side of detecting a VCS checkout somewhere.

ABSPATH is always checked in addition to whatever $context is (which may be the wp-content directory, for example). The underlying assumption is that if you are using version control anywhere, then you should be making decisions for how things get updated.

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

Хуки из метода

Возвращает

bool. True if a VCS checkout was discovered at $context or ABSPATH, or anywhere higher. False otherwise.

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

$WP_Automatic_Updater = new WP_Automatic_Updater();
$WP_Automatic_Updater->is_vcs_checkout( $context );
$context(строка) (обязательный)
The filesystem path to check, in addition to ABSPATH.

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

С версии 3.7.0 Введена.

Код WP_Automatic_Updater::is_vcs_checkout() WP 7.1.2

public function is_vcs_checkout( $context ) {
	$context_dirs = array( untrailingslashit( $context ) );
	if ( ABSPATH !== $context ) {
		$context_dirs[] = untrailingslashit( ABSPATH );
	}

	$vcs_dirs   = array( '.svn', '.git', '.hg', '.bzr' );
	$check_dirs = array();

	foreach ( $context_dirs as $context_dir ) {
		// Walk up from $context_dir to the root.
		do {
			$check_dirs[] = $context_dir;

			// Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here.
			if ( dirname( $context_dir ) === $context_dir ) {
				break;
			}

			// Continue one level at a time.
		} while ( $context_dir = dirname( $context_dir ) );
	}

	$check_dirs = array_unique( $check_dirs );
	$checkout   = false;

	// Search all directories we've found for evidence of version control.
	foreach ( $vcs_dirs as $vcs_dir ) {
		foreach ( $check_dirs as $check_dir ) {
			if ( ! $this->is_allowed_dir( $check_dir ) ) {
				continue;
			}

			$checkout = is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" );
			if ( $checkout ) {
				break 2;
			}
		}
	}

	/**
	 * Filters whether the automatic updater should consider a filesystem
	 * location to be potentially managed by a version control system.
	 *
	 * @since 3.7.0
	 *
	 * @param bool $checkout  Whether a VCS checkout was discovered at `$context`
	 *                        or ABSPATH, or anywhere higher.
	 * @param string $context The filesystem context (a path) against which
	 *                        filesystem status should be checked.
	 */
	return apply_filters( 'automatic_updates_is_vcs_checkout', $checkout, $context );
}