Skip to content

Commit

Permalink
Properly change autoload value of plugin options on (de)activation
Browse files Browse the repository at this point in the history
Fixes #160.
  • Loading branch information
chesio committed Jun 27, 2024
1 parent da3bb74 commit 7507817
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

WordPress 6.4 or newer is now required!

### Added

* Disable autoloading of plugin options when plugin is deactivated [#160](https://github.com/chesio/bc-security/issues/160).

### Changed

* WordPress 6.4 is required [#159](https://github.com/chesio/bc-security/issues/159).
Expand Down
9 changes: 9 additions & 0 deletions classes/BlueChip/Security/Core/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ public function reset(): bool
}


/**
* Set $autoload value of option.
*/
public function setAutoload(bool $autoload): bool
{
return wp_set_option_autoload($this->option_name, $autoload);
}


/**
* Remove the data from database (= hard reset).
*
Expand Down
9 changes: 7 additions & 2 deletions classes/BlueChip/Security/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ private function init(): void
*/
public function activate(): void
{
// Explicitly persist every setting object, so related option is autoloaded.
// Make sure plugin related options are autoloaded when plugin is active.
foreach ($this->settings as $settings) {
$settings->persist();
$settings->setAutoload(true);
}

// Install every module that requires it.
Expand Down Expand Up @@ -196,6 +196,11 @@ public function deactivate(): void
$module->deactivate();
}
}

// Make sure plugin related options are *not* autoloaded when plugin is inactive.
foreach ($this->settings as $settings) {
$settings->setAutoload(false);
}
}


Expand Down

0 comments on commit 7507817

Please sign in to comment.