-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlugin.php
More file actions
85 lines (74 loc) · 1.96 KB
/
Copy pathPlugin.php
File metadata and controls
85 lines (74 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace HWP\Previews;
use HWP\Previews\Admin\Settings_Page;
use HWP\Previews\Hooks\Preview_Hooks;
use HWP\Previews\Integration\Faust_Integration;
/**
* Plugin class for HWP Previews.
*
* This class serves as the main entry point for the plugin, handling initialization, action and filter hooks.
*
* @link https://github.com/wpengine/hwptoolkit/tree/main/plugins/hwp-previews
*
* @package HWP\Previews
*/
final class Plugin {
/**
* The instance of the plugin.
*
* @var \HWP\Previews\Plugin|null
*/
protected static ?Plugin $instance = null;
/**
* Private constructor to prevent direct instantiation.
*/
protected function __construct() {
}
/**
* Constructor
*/
public static function init(): self {
if ( ! isset( self::$instance ) || ! ( is_a( self::$instance, self::class ) ) ) {
self::$instance = new self();
self::$instance->setup();
}
/**
* Fire off init action.
*
* @param \HWP\Previews\Plugin $instance the instance of the plugin class.
*/
do_action( 'hwp_previews_init', self::$instance );
return self::$instance;
}
/**
* Initialize the plugin admin, frontend & api functionality.
*/
public function setup(): void {
Settings_Page::init();
Preview_Hooks::init();
Faust_Integration::init();
}
/**
* Throw error on object clone.
* The whole idea of the singleton design pattern is that there is a single object
* therefore, we don't want the object to be cloned.
*
* @codeCoverageIgnore
*
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __METHOD__, 'The plugin Plugin class should not be cloned.', '0.0.1' );
}
/**
* Disable unserializing of the class.
*
* @codeCoverageIgnore
*/
public function __wakeup(): void {
// De-serializing instances of the class is forbidden.
_doing_it_wrong( __METHOD__, 'De-serializing instances of the plugin Main class is not allowed.', '0.0.1' );
}
}