wppaste
WordPress

WP_Automatic_Updater::is_vcs_checkout( string $context ): bool

Since
3.7.0
Source
wp-admin/includes/class-wp-automatic-updater.php:127
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.

Compatibility

WordPress
since 3.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

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

Return value

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

Performance profile

How much work a call to WP_Automatic_Updater::is_vcs_checkout() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via is_dir().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
24–50

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 61.

Plugin surface
1 hook

Third-party callbacks on 'automatic_updates_is_vcs_checkout' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • filesystemfilesystem accessis_dir()called directly

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Automatic_Updater::is_vcs_checkout() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$context === false24–26untrailingslashit(), array_unique(), apply_filters()
$context !== false30–32untrailingslashit(), untrailingslashit(), array_unique(), apply_filters()
$context === false && !$check_dirs && ->is_allowed_dir() && is_dir()43–44untrailingslashit(), array_unique(), ->is_allowed_dir(), rtrim(), is_dir(), apply_filters()
$context !== false && !$check_dirs && ->is_allowed_dir() && is_dir()49–50untrailingslashit(), untrailingslashit(), array_unique(), ->is_allowed_dir(), rtrim(), is_dir(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6124–5011
8.56124–5011
8.46124–50114 fewer instructions than PHP 8.3
8.36524–5011
8.26524–50111 more instruction than PHP 8.1
8.16424–6211
7.46424–6211

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Automatic_Updater::is_vcs_checkout() runs, in this order:

  1. apply_filters( automatic_updates_is_vcs_checkout )filterline 178 (+51 into the body)

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

Uses · 3

Used by · 1

Source code

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

Changelog

Introduced in 3.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-admin/includes/class-wp-automatic-updater.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.