WP_Automatic_Updater::is_vcs_checkout( string $context ): bool
- Since
- 3.7.0
- Source
wp-admin/includes/class-wp-automatic-updater.php:127
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
$contextor 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
- Scaling
- Scales with input
- Instructions
- 24–50
- Plugin surface
- 1 hook
- Called by
- 1
Reads or writes the filesystem via is_dir().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 61.
Third-party callbacks on 'automatic_updates_is_vcs_checkout' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - filesystemfilesystem access
is_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.
| When | Instructions | Calls it makes |
|---|---|---|
$context === false | 24–26 | untrailingslashit(), array_unique(), apply_filters() |
$context !== false | 30–32 | untrailingslashit(), untrailingslashit(), array_unique(), apply_filters() |
$context === false && !$check_dirs && ->is_allowed_dir() && is_dir() | 43–44 | untrailingslashit(), array_unique(), ->is_allowed_dir(), rtrim(), is_dir(), apply_filters() |
$context !== false && !$check_dirs && ->is_allowed_dir() && is_dir() | 49–50 | untrailingslashit(), untrailingslashit(), array_unique(), ->is_allowed_dir(), rtrim(), is_dir(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 61 | 24–50 | 11 | |
| 8.5 | 61 | 24–50 | 11 | |
| 8.4 | 61 | 24–50 | 11 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 65 | 24–50 | 11 | |
| 8.2 | 65 | 24–50 | 11 | 1 more instruction than PHP 8.1 |
| 8.1 | 64 | 24–62 | 11 | |
| 7.4 | 64 | 24–62 | 11 |
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:
- 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
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Automatic_Updater::is_allowed_dir()Checks whether access to a given directory is allowed.
Used by · 1
- WP_Automatic_Updater::should_update()Tests to see if we can and should update a specific item.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 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.