WP_Site_Monitor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * The core plugin class.
4
 *
5
 * This is used to define internationalization, admin-specific hooks, and
6
 * public-facing site hooks.
7
 *
8
 * Also maintains the unique identifier of this plugin as well as the current
9
 * version of the plugin.
10
 *
11
 * @package WPSiteMonitor
12
 * @link https://github.com/BWibrew/WP-Site-Monitor/
13
 * @author Benjamin Wibrew <[email protected]>
14
 * @since 1.0.0
15
 */
16
17
namespace WPSiteMonitor;
18
19
/**
20
 * Class WP_Site_Monitor
21
 *
22
 * @package WPSiteMonitor
23
 */
24
class WP_Site_Monitor {
25
26
	/**
27
	 * Setting options group name.
28
	 *
29
	 * @var string
30
	 * @since 1.0.0
31
	 */
32
	const OPTION_GROUP = 'wp_site_monitor';
33
34
	/**
35
	 * The setting option names.
36
	 *
37
	 * @var string
38
	 * @since 1.0.0
39
	 */
40
	const OPTION_NAMES = array(
41
		'enable'     => self::OPTION_GROUP . '_enable',
42
		'wp_version' => self::OPTION_GROUP . '_wp_version',
43
		'plugins'    => self::OPTION_GROUP . '_plugins',
44
	);
45
46
	/**
47
	 * Instance of API class.
48
	 *
49
	 * @var API
50
	 * @since 1.0.0
51
	 */
52
	public $api;
53
54
	/**
55
	 * Instance of Settings_Menu class.
56
	 *
57
	 * @var Settings_Menu
58
	 * @since 1.0.0
59
	 */
60
	public $settings_menu;
61
62
	/**
63
	 * The loader that's responsible for registering all hooks and filters.
64
	 *
65
	 * @var Hook_Loader $loader Maintains and registers all hooks for the plugin.
66
	 * @since 1.0.0
67
	 */
68
	protected $loader;
69
70
	/**
71
	 * Define the core functionality of the plugin.
72
	 *
73
	 * @since 1.0.0
74
	 */
75 7
	public function __construct() {
76 7
		$this->loader = new Hook_Loader();
77
78 7
		$this->init();
79 7
	}
80
81
	/**
82
	 * Initialise plugin files.
83
	 *
84
	 * @since 1.0.0
85
	 */
86 7
	public function init() {
87 7
		if ( is_admin() ) {
88 5
			$this->settings_menu = new Settings_Menu();
89
90 5
			$this->loader->add_action( 'admin_init', $this->settings_menu, 'init_settings' );
91 5
			$this->loader->add_action( 'admin_menu', $this->settings_menu, 'display_settings_page' );
92
		}
93
94 7
		if ( get_option( self::OPTION_NAMES['enable'], true ) ) {
95 6
			$this->api = new API();
96
97 6
			$this->loader->add_action( 'rest_api_init', $this->api, 'register_routes' );
98
		}
99
100 7
		$this->loader->run();
101 7
	}
102
103
	/**
104
	 * Fired during plugin deactivation,
105
	 *
106
	 * @since 1.0.0
107
	 */
108 1
	public static function deactivate() {
109 1
		unregister_setting( self::OPTION_GROUP, self::OPTION_NAMES['enable'] );
110 1
		unregister_setting( self::OPTION_GROUP, self::OPTION_NAMES['wp_version'] );
111 1
		unregister_setting( self::OPTION_GROUP, self::OPTION_NAMES['plugins'] );
112 1
	}
113
114
	/**
115
	 * Fired during plugin deletion.
116
	 *
117
	 * @since 1.0.0
118
	 */
119 1
	public static function uninstall() {
120 1
		delete_option( self::OPTION_NAMES['enable'] );
121 1
		delete_option( self::OPTION_NAMES['wp_version'] );
122 1
		delete_option( self::OPTION_NAMES['plugins'] );
123 1
	}
124
}
125