VersionPress\Utils\UninstallationUtil::uninstallationShouldRemoveGitRepo PHP Метод

uninstallationShouldRemoveGitRepo() публичный статический Метод

Returns true if VP uninstallation should remove the Git repo from the root folder (and back it up somewhere). This is true if the first commit is VersionPress commit. Otherwise, the Git repo was probably created by the user before VP was installed and we should keep the repo untouched.
public static uninstallationShouldRemoveGitRepo ( ) : boolean
Результат boolean
    public static function uninstallationShouldRemoveGitRepo()
    {
        global $versionPressContainer;
        /** @var GitRepository $repository */
        $repository = $versionPressContainer->resolve(VersionPressServices::GIT_REPOSITORY);
        $initialCommit = $repository->getInitialCommit();
        if (!$initialCommit) {
            return false;
        }
        /** @var CommitMessageParser $commitMessageParser */
        $commitMessageParser = $versionPressContainer->resolve(VersionPressServices::COMMIT_MESSAGE_PARSER);
        $changeInfoEnvelope = $commitMessageParser->parse($initialCommit->getMessage());
        $changeInfoList = $changeInfoEnvelope->getChangeInfoList();
        $firstChangeInfo = $changeInfoList[0];
        return $changeInfoList[0]->getScope() === 'versionpress' && $firstChangeInfo->getAction() === 'activate';
    }

Usage Example

Пример #1
0
    // Flushing rewrite rules after clone / pull / push
    //----------------------------------
    add_action('wp_loaded', function () {
        if (get_transient('vp_flush_rewrite_rules') && !defined('WP_CLI')) {
            require_once ABSPATH . 'wp-admin/includes/misc.php';
            require_once ABSPATH . 'wp-admin/includes/file.php';
            flush_rewrite_rules();
            delete_transient('vp_flush_rewrite_rules');
        }
    });
}
//----------------------------------
// Auto-update
//----------------------------------
add_filter('automatic_updates_is_vcs_checkout', function () {
    $forceUpdate = UninstallationUtil::uninstallationShouldRemoveGitRepo();
    // first commit was created by VersionPress
    return !$forceUpdate;
    // 'false' forces the update
});
function vp_register_hooks()
{
    global $versionPressContainer;
    /** @var Committer $committer */
    $committer = $versionPressContainer->resolve(VersionPressServices::COMMITTER);
    /** @var Mirror $mirror */
    $mirror = $versionPressContainer->resolve(VersionPressServices::MIRROR);
    /** @var DbSchemaInfo $dbSchemaInfo */
    $dbSchemaInfo = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA);
    /** @var VpidRepository $vpidRepository */
    $vpidRepository = $versionPressContainer->resolve(VersionPressServices::VPID_REPOSITORY);
All Usage Examples Of VersionPress\Utils\UninstallationUtil::uninstallationShouldRemoveGitRepo