VersionPress\Utils\WpConfigEditor::removeVersionPressConstants PHP Method

removeVersionPressConstants() public static method

Removes VersionPress public constants from config files.
public static removeVersionPressConstants ( array $configFiles )
$configFiles array List of config file paths from which constants should be removed.
    public static function removeVersionPressConstants($configFiles)
    {
        foreach ($configFiles as $configFile) {
            $constantsForRegex = join('|', self::$vpPublicConstants);
            // https://regex101.com/r/zD3mJ4/2
            $defineRegexPattern = "/(define\\s*\\(\\s*['\"]({$constantsForRegex})['\"]\\s*,.*\\)\\s*;)/m";
            $wpConfigContent = file_get_contents($configFile);
            file_put_contents($configFile, preg_replace($defineRegexPattern, '', $wpConfigContent));
        }
    }

Usage Example

コード例 #1
0
require_once dirname(__FILE__) . '/bootstrap.php';
global $versionPressContainer;
/** @var \VersionPress\Database\Database $database */
$database = $versionPressContainer->resolve(VersionPressServices::DATABASE);
$queries[] = "DROP TABLE IF EXISTS `{$database->vp_id}`";
$vpOptionsReflection = new ReflectionClass(VersionPressOptions::class);
$usermetaToDelete = array_values($vpOptionsReflection->getConstants());
$queryRestriction = '"' . join('", "', $usermetaToDelete) . '"';
$queries[] = "DELETE FROM `{$database->usermeta}` WHERE meta_key IN ({$queryRestriction})";
foreach ($queries as $query) {
    $database->query($query);
}
delete_option('vp_rest_api_plugin_version');
FileSystem::remove(VP_VPDB_DIR);
$wpConfigPath = \VersionPress\Utils\WordPressMissingFunctions::getWpConfigPath();
\VersionPress\Utils\WpConfigEditor::removeVersionPressConstants([$wpConfigPath, dirname($wpConfigPath . '/' . WpConfigSplitter::COMMON_CONFIG_NAME)]);
if (UninstallationUtil::uninstallationShouldRemoveGitRepo()) {
    $backupsDir = WP_CONTENT_DIR . '/vpbackups';
    if (!file_exists($backupsDir)) {
        FileSystem::mkdir($backupsDir);
        file_put_contents($backupsDir . '/.gitignore', 'git-backup-*');
        SecurityUtils::protectDirectory($backupsDir);
    }
    $backupPath = $backupsDir . '/git-backup-' . date("YmdHis");
    FileSystem::rename(VP_PROJECT_ROOT . '/.git', $backupPath, true);
    $productionGitignore = VP_PROJECT_ROOT . '.gitignore';
    $templateGitignore = __DIR__ . '/src/Initialization/.gitignore.tpl';
    if (FileSystem::filesHaveSameContents($productionGitignore, $templateGitignore)) {
        FileSystem::remove($productionGitignore);
    }
}