Skip to content

Commit e082b6f

Browse files
committed
wip
1 parent e03ac26 commit e082b6f

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ insert_final_newline = true
77
indent_style = space
88
indent_size = 4
99
trim_trailing_whitespace = true
10+
max_line_length = 80

src/Plugin.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@
99
use SimpleAnalytics\Scripts\AutomatedEventsScript;
1010
use SimpleAnalytics\Scripts\InactiveScript;
1111

12-
class Plugin
12+
final class Plugin
1313
{
1414
use PluginLifecycle;
1515

16+
#[\Override]
1617
protected function onBoot(): void
1718
{
1819
if (is_admin()) $this->defineAdminPage();
1920
}
2021

22+
#[\Override]
2123
public function onActivation(): void
2224
{
23-
25+
$this->registerOptions();
2426
}
2527

26-
public function onDeactivation(): void
28+
#[\Override]
29+
public function onUninstall(): void
2730
{
28-
31+
$this->deleteOptions();
2932
}
3033

34+
#[\Override]
3135
public function onInit(): void
3236
{
3337
$shouldCollect = (new TrackingPolicy)->shouldCollectAnalytics();
@@ -43,6 +47,25 @@ public function onInit(): void
4347
}
4448
}
4549

50+
/**
51+
* Register all options with autoload=true
52+
* to preload them on each page and avoid
53+
* extra database queries.
54+
*/
55+
protected function registerOptions(): void
56+
{
57+
foreach (SettingName::cases() as $name) {
58+
add_option($name, null, null, true);
59+
}
60+
}
61+
62+
protected function deleteOptions(): void
63+
{
64+
foreach (SettingName::cases() as $name) {
65+
delete_option($name);
66+
}
67+
}
68+
4669
protected function addScripts(bool $collect): void
4770
{
4871
$scripts = new ScriptManager;

src/PluginLifecycle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ abstract public function onInit(): void;
1818

1919
abstract public function onActivation(): void;
2020

21-
abstract public function onDeactivation(): void;
21+
abstract public function onUninstall(): void;
2222
}

src/SettingName.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ class SettingName
2727
const string EVENT_USE_TITLE = 'simpleanalytics_event_use_title';
2828
const string EVENT_FULL_URLS = 'simpleanalytics_event_full_urls';
2929
const string EVENT_SA_GLOBAL = 'simpleanalytics_event_sa_global';
30+
31+
static function cases(): array
32+
{
33+
return (new \ReflectionClass(__CLASS__))->getConstants();
34+
}
3035
}

src/Settings/Blocks/CalloutBlock.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function __construct(
1212
) {
1313
}
1414

15+
#[\Override]
1516
public function render(): void
1617
{
1718
?>

0 commit comments

Comments
 (0)