WP_Automatic_Updater::is_vcs_checkout( string $context )

Check 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

$context

(string) (Required) 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

File: wp-admin/includes/class-wp-automatic-updater.php

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

		// Search all directories we've found for evidence of version control.
		foreach ( $vcs_dirs as $vcs_dir ) {
			foreach ( $check_dirs as $check_dir ) {
				$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 );
	}

Changelog

Version Description
3.7.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_automatic_updater/is_vcs_checkout