Skip to content

Commit

Permalink
Fix records of which .htaccess files we have rules in (if possible). C…
Browse files Browse the repository at this point in the history
…loses #169
  • Loading branch information
rosell-dk committed Feb 18, 2019
1 parent ead8765 commit fb32d41
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/migrate/migrate6.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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');
}

Expand Down

0 comments on commit fb32d41

Please sign in to comment.