Using WordPress ‘automatic_updates_is_vcs_checkout’ PHP filter

The automatic_updates_is_vcs_checkout WordPress PHP filter checks if a filesystem location is managed by a version control system (VCS) and determines whether automatic updates should be allowed.

Usage

add_filter('automatic_updates_is_vcs_checkout', 'your_custom_function', 10, 2);

function your_custom_function($checkout, $context) {
    // your custom code here
    return $checkout;
}

Parameters

  • $checkout (bool) – Whether a VCS checkout was discovered at $context or ABSPATH, or anywhere higher.
  • $context (string) – The filesystem context (a path) against which filesystem status should be checked.

More information

See WordPress Developer Resources: automatic_updates_is_vcs_checkout

Examples

Disable automatic updates for VCS managed locations

Disable automatic updates for filesystem locations managed by a version control system.

add_filter('automatic_updates_is_vcs_checkout', 'disable_automatic_updates_for_vcs', 10, 2);

function disable_automatic_updates_for_vcs($checkout, $context) {
    if ($checkout) {
        return true;
    }
    return $checkout;
}

Always allow automatic updates

Always allow automatic updates, regardless of whether the location is managed by a version control system or not.

add_filter('automatic_updates_is_vcs_checkout', 'always_allow_automatic_updates', 10, 2);

function always_allow_automatic_updates($checkout, $context) {
    return false;
}

Check for a specific VCS

Allow automatic updates only if the location is managed by a specific version control system, such as Git.

add_filter('automatic_updates_is_vcs_checkout', 'allow_automatic_updates_for_git', 10, 2);

function allow_automatic_updates_for_git($checkout, $context) {
    if ($checkout && is_dir($context . '/.git')) {
        return false;
    }
    return $checkout;
}

Check for custom VCS location

Allow automatic updates only if the location is not managed by a version control system in a custom directory.

add_filter('automatic_updates_is_vcs_checkout', 'allow_automatic_updates_for_custom_directory', 10, 2);

function allow_automatic_updates_for_custom_directory($checkout, $context) {
    if ($checkout && is_dir($context . '/custom-vcs-directory')) {
        return true;
    }
    return $checkout;
}

Disable automatic updates for a specific plugin

Disable automatic updates for a specific plugin if it’s managed by a version control system.

add_filter('automatic_updates_is_vcs_checkout', 'disable_automatic_updates_for_specific_plugin', 10, 2);

function disable_automatic_updates_for_specific_plugin($checkout, $context) {
    if ($checkout && strpos($context, 'wp-content/plugins/my-plugin') !== false) {
        return true;
    }
    return $checkout;
}