GC_Automatic_Updater::is_vcs_checkout()
最后更新于:2021-11-26 09:19:02
GC_Automatic_Updater::is_vcs_checkout( string$context)Check for version control checkouts.
参数
- $context
-
(string) (Required) The filesystem path to check, in addition to ABSPATH.
响应
(bool) True if a VCS checkout was discovered at $context
or ABSPATH, or anywhere higher. False otherwise.
源文件
文件: gc-admin/includes/class-gc-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 );
}