WP_Automatic_Updater::is_vcs_checkout( string $context ): bool

Checks for version control checkouts.

Description

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.

Parameters

$contextstringrequired
The filesystem path to check, in addition to ABSPATH.

Return

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

Source

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

Hooks

apply_filters( ‘automatic_updates_is_vcs_checkout’, bool $checkout, string $context )

Filters whether the automatic updater should consider a filesystem location to be potentially managed by a version control system.

Changelog

VersionDescription
3.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.