Passed
Push — master ( 8429c0...4d016b )
by Benjamin
01:44
created

Settings_Menu::display_settings_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
ccs 7
cts 7
cp 1
crap 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
	 * The loader that's responsible for registering all hooks and filters.
22
	 *
23
	 * @var Hook_Loader
24
	 * @since 1.0.0
25
	 */
26
	protected $loader;
27
28
	/**
29
	 * Settings page slug.
30
	 *
31
	 * @var string
32
	 * @since 1.0.0
33
	 */
34
	protected $settings_page;
35
36
	/**
37
	 * Setting options group name.
38
	 *
39
	 * @var string
40
	 * @since 1.0.0
41
	 */
42
	protected $option_group;
43
44
	/**
45
	 * Initialise the plugin settings and menus.
46
	 *
47
	 * @since 1.0.0
48
	 */
49 2
	public function __construct() {
50 2
		$this->settings_page = 'wp_site_monitor';
51 2
		$this->option_group  = $this->settings_page;
52
53 2
		$this->loader = new Hook_Loader();
54
55 2
		$this->loader->add_action( 'admin_init', $this, 'init_settings' );
56 2
		$this->loader->add_action( 'admin_menu', $this, 'display_settings_page' );
57
58 2
		$this->loader->run();
59 2
	}
60
61
	/**
62
	 * Initialise plugin settings.
63
	 *
64
	 * @since 1.0.0
65
	 */
66 1
	public function init_settings() {
67 1
		register_setting( $this->option_group, 'wp_site_monitor_enable' );
68
69 1
		add_settings_section(
70 1
			'wp_site_monitor_enable_section',
71 1
			__( 'Enable/Disable WP Site Monitor', 'wp-site-monitor' ),
72 1
			array( $this, 'setting_section_html' ),
73 1
			$this->settings_page
74
		);
75
76 1
		add_settings_field(
77 1
			'wp_site_monitor_enable',
78 1
			__( 'Enable WP Site Monitor', 'wp-site-monitor' ),
79 1
			array( $this, 'setting_input_html' ),
80 1
			$this->settings_page,
81 1
			'wp_site_monitor_enable_section'
82
		);
83 1
	}
84
85
	/**
86
	 * Display the admin settings page.
87
	 *
88
	 * @since 1.0.0
89
	 */
90 1
	public function display_settings_page() {
91 1
		add_options_page(
92 1
			__( 'WP Site Monitor Settings', 'wp-site-monitor' ),
93 1
			__( 'WP Site Monitor', 'wp-site-monitor' ),
94 1
			'manage_options',
95 1
			$this->settings_page,
96 1
			array( $this, 'settings_page_html' )
97
		);
98 1
	}
99
100
	/**
101
	 * Settings page template.
102
	 *
103
	 * @since 1.0.0
104
	 */
105
	public function settings_page_html() {
106
		if ( ! current_user_can( 'manage_options' ) ) {
107
			return;
108
		}
109
		?>
110
		<div class="wrap">
111
			<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
112
			<form action="options.php" method="POST">
113
				<?php
114
				settings_fields( $this->option_group );
115
				do_settings_sections( $this->settings_page );
116
				submit_button();
117
				?>
118
			</form>
119
		</div>
120
		<?php
121
	}
122
123
	/**
124
	 * Form text.
125
	 *
126
	 * @param array $args Arguments passed into add_settings_section.
127
	 *
128
	 * @since 1.0.0
129
	 */
130
	public function setting_section_html( $args ) {
131
		?>
132
		<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Use these options to control which extra data is available over the REST API.', 'wp-site-monitor' ); ?></p>
133
		<?php
134
	}
135
136
	/**
137
	 * Form inputs.
138
	 *
139
	 * @since 1.0.0
140
	 */
141
	public function setting_input_html() {
142
		?>
143
		<input type="checkbox"
144
			name="wp_site_monitor_enable"
145
			id=""<?php checked( get_option( 'wp_site_monitor_enable' ), 1 ); ?> value="1">
0 ignored issues
show
Bug introduced by
The function checked was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

145
			id=""<?php /** @scrutinizer ignore-call */ checked( get_option( 'wp_site_monitor_enable' ), 1 ); ?> value="1">
Loading history...
146
147
		<p class="description">
148
			<?php esc_html_e( 'This checkbox enables/disables all plugin functionality.', 'wp-site-monitor' ); ?>
149
		</p>
150
		<?php
151
	}
152
}
153