Passed
Push — master ( 3e66dc...5a0d43 )
by Benjamin
04:00
created

Settings_Menu   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 96.88%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 72
ccs 31
cts 32
cp 0.9688
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A display_settings_page() 0 7 1
A init_settings() 0 16 1
A setting_input_html() 0 2 1
A settings_page_html() 0 6 2
A setting_section_html() 0 2 1
1
<?php
2
/**
3
 * Register all settings and menus for the plugin.
4
 *
5
 * @package WPSiteMonitor
6
 * @link https://github.com/BWibrew/WP-Site-Monitor/
7
 * @author Benjamin Wibrew <[email protected]>
8
 * @since 1.0.0
9
 */
10
11
namespace WPSiteMonitor;
12
13
/**
14
 * Class Settings_Menu
15
 *
16
 * @package WPSiteMonitor
17
 */
18
class Settings_Menu {
19
20
	/**
21
	 * Initialise plugin settings.
22
	 *
23
	 * @since 1.0.0
24
	 */
25 4
	public function init_settings() {
26 4
		register_setting( WP_Site_Monitor::OPTION_GROUP, WP_Site_Monitor::OPTION_NAME );
27
28 4
		add_settings_section(
29 4
			WP_Site_Monitor::OPTION_NAME . '_section',
30 4
			__( 'Enable/Disable WP Site Monitor', 'wp-site-monitor' ),
31 4
			array( $this, 'setting_section_html' ),
32 4
			WP_Site_Monitor::OPTION_GROUP
33
		);
34
35 4
		add_settings_field(
36 4
			WP_Site_Monitor::OPTION_NAME,
37 4
			__( 'Enable WP Site Monitor', 'wp-site-monitor' ),
38 4
			array( $this, 'setting_input_html' ),
39 4
			WP_Site_Monitor::OPTION_GROUP,
40 4
			WP_Site_Monitor::OPTION_NAME . '_section'
41
		);
42 4
	}
43
44
	/**
45
	 * Display the admin settings page.
46
	 *
47
	 * @since 1.0.0
48
	 */
49 1
	public function display_settings_page() {
50 1
		add_options_page(
51 1
			__( 'WP Site Monitor Settings', 'wp-site-monitor' ),
52 1
			__( 'WP Site Monitor', 'wp-site-monitor' ),
53 1
			'manage_options',
54 1
			WP_Site_Monitor::OPTION_GROUP,
55 1
			array( $this, 'settings_page_html' )
56
		);
57 1
	}
58
59
	/**
60
	 * Settings page template.
61
	 *
62
	 * @since 1.0.0
63
	 */
64 1
	public function settings_page_html() {
65 1
		if ( ! current_user_can( 'manage_options' ) ) {
66
			return;
67
		}
68
69 1
		require_once WPSM_PATH . 'templates/settings-page.php';
70 1
	}
71
72
	/**
73
	 * Form text.
74
	 *
75
	 * @param array $args Arguments passed into add_settings_section.
76
	 *
77
	 * @since 1.0.0
78
	 */
79 2
	public function setting_section_html( $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

79
	public function setting_section_html( /** @scrutinizer ignore-unused */ $args ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80 2
		require_once WPSM_PATH . 'templates/setting-section.php';
81 2
	}
82
83
	/**
84
	 * Form inputs.
85
	 *
86
	 * @since 1.0.0
87
	 */
88 2
	public function setting_input_html() {
89 2
		require_once WPSM_PATH . 'templates/setting-input.php';
90 2
	}
91
}
92