Skip to content

Commit e03ac26

Browse files
committed
wip
1 parent 3e68bc5 commit e03ac26

File tree

5 files changed

+46
-20
lines changed

5 files changed

+46
-20
lines changed

simple-analytics.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
define('SimpleAnalytics\\PLUGIN_URL', plugin_dir_url(__FILE__));
2323
define('SimpleAnalytics\\PLUGIN_PATH', plugin_dir_path(__FILE__));
24+
define('SimpleAnalytics\\ENTRYPOINT_FILE', __FILE__);
2425

2526
/**
2627
* @note Manual loading rather than Composer to avoid potential conflict with plugins/themes that ship older autoloader.
2728
*/
2829
require __DIR__ . '/src/Support/SvgIcon.php';
2930
require __DIR__ . '/helpers.php';
31+
require __DIR__ . '/src/PluginLifecycle.php';
3032
require __DIR__ . '/src/Plugin.php';
3133
require __DIR__ . '/src/Setting.php';
3234
require __DIR__ . '/src/SettingName.php';

src/Plugin.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@
1111

1212
class Plugin
1313
{
14-
public function boot(): void
14+
use PluginLifecycle;
15+
16+
protected function onBoot(): void
1517
{
16-
add_action('init', $this->onInit(...));
17-
is_admin() && $this->defineAdminPage();
18+
if (is_admin()) $this->defineAdminPage();
19+
}
20+
21+
public function onActivation(): void
22+
{
23+
24+
}
25+
26+
public function onDeactivation(): void
27+
{
28+
1829
}
1930

2031
public function onInit(): void

src/PluginLifecycle.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace SimpleAnalytics;
4+
5+
trait PluginLifecycle
6+
{
7+
public function boot(): void
8+
{
9+
$this->onBoot();
10+
add_action('init', $this->onInit(...));
11+
register_activation_hook(ENTRYPOINT_FILE, $this->onActivation(...));
12+
register_deactivation_hook(ENTRYPOINT_FILE, $this->onDeactivation(...));
13+
}
14+
15+
abstract protected function onBoot(): void;
16+
17+
abstract public function onInit(): void;
18+
19+
abstract public function onActivation(): void;
20+
21+
abstract public function onDeactivation(): void;
22+
}

src/SettingsData.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace SimpleAnalytics;
4+
5+
readonly class SettingsData
6+
{
7+
8+
}

uninstall.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)