From fb32d41386cab058581b3eb2e0e18d88b07d74fd Mon Sep 17 00:00:00 2001 From: rosell-dk Date: Mon, 18 Feb 2019 13:29:03 +0100 Subject: [PATCH] Fix records of which .htaccess files we have rules in (if possible). Closes #169 --- lib/migrate/migrate6.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/migrate/migrate6.php b/lib/migrate/migrate6.php index ee7f5ff6..26dee3c1 100644 --- a/lib/migrate/migrate6.php +++ b/lib/migrate/migrate6.php @@ -15,6 +15,21 @@ include_once __DIR__ . '/../classes/Paths.php'; use \WebPExpress\Paths; +/** + * Fix records - if possible + */ +function webpexpress_migrate6_fixHtaccessRecordsForDir($dirId) { + $haveRules = HTAccess::haveWeRulesInThisHTAccess(Paths::getAbsDirById($dirId) . '/.htaccess'); + + // PS: $haveRules may be null, meaning "maybe" + if ($haveRules === true) { + HTAccess::addToActiveHTAccessDirsArray($dirId); + } + if ($haveRules === false) { + HTAccess::removeFromActiveHTAccessDirsArray($dirId); + } +} + function webpexpress_migrate6() { // Regenerate .htaccess file if placed in root (so rewrites does not apply in wp-admin area) @@ -39,6 +54,21 @@ function webpexpress_migrate6() { } } + // The records about which .htaccess files that contains rules were not correct. + // Correct them if possible (haveWeRulesInThisHTAccess() may return null, if we cannot determine) + // https://github.com/rosell-dk/webp-express/issues/169 + + $dirsToFix = [ + 'index', + 'home', + 'wp-content', + 'plugins', + 'uploads' + ]; + foreach ($dirsToFix as $dirId) { + webpexpress_migrate6_fixHtaccessRecordsForDir($dirId); + } + update_option('webp-express-migration-version', '6'); }