Completed
Push — master ( eae0f6...0655df )
by Benjamin
10:54
created

WP_Site_Monitor::init_settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 15
nc 1
nop 0
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
	 * The loader that's responsible for registering all hooks and filters.
28
	 *
29
	 * @var Hook_Loader $loader Maintains and registers all hooks for the plugin.
30
	 * @since 1.0.0
31
	 */
32
	protected $loader;
33
34
	/**
35
	 * Define the core functionality of the plugin.
36
	 *
37
	 * @since 1.0.0
38
	 */
39
	public function __construct() {
40
		$this->init();
41
	}
42
43
	/**
44
	 * Initialise plugin files.
45
	 *
46
	 * @since 1.0.0
47
	 */
48
	public function init() {
49
		require_once WPSM_PATH . 'src/class-hook-loader.php';
50
		$this->loader = new Hook_Loader();
51
52
		if ( is_admin() ) {
0 ignored issues
show
Bug introduced by
The function is_admin 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

52
		if ( /** @scrutinizer ignore-call */ is_admin() ) {
Loading history...
53
			$this->loader->add_action( 'admin_menu', $this, 'display_settings_page' );
54
			$this->loader->add_action( 'admin_init', $this, 'init_settings' );
55
		}
56
57
		$this->loader->run();
58
	}
59
60
	/**
61
	 * Fired during plugin activation.
62
	 *
63
	 * @since 1.0.0
64
	 */
65
	public static function activate() {
66
	}
67
68
	/**
69
	 * Fired during plugin deactivation,
70
	 *
71
	 * @since 1.0.0
72
	 */
73
	public static function deactivate() {
74
	}
75
76
	/**
77
	 * Fired during plugin deletion.
78
	 *
79
	 * @since 1.0.0
80
	 */
81
	public static function uninstall() {
82
	}
83
84
	/**
85
	 * Display the admin settings page.
86
	 *
87
	 * @since 1.0.0
88
	 */
89
	public function display_settings_page() {
90
		add_options_page(
0 ignored issues
show
Bug introduced by
The function add_options_page 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

90
		/** @scrutinizer ignore-call */ 
91
  add_options_page(
Loading history...
91
			__( 'WP Site Monitor Settings', 'wp-site-monitor' ),
0 ignored issues
show
Bug introduced by
The function __ 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

91
			/** @scrutinizer ignore-call */ 
92
   __( 'WP Site Monitor Settings', 'wp-site-monitor' ),
Loading history...
92
			__( 'WP Site Monitor', 'wp-site-monitor' ),
93
			'manage_options',
94
			'wp_site_monitor',
95
			array( $this, 'settings_page_html' )
96
		);
97
	}
98
99
	/**
100
	 * Settings page template.
101
	 *
102
	 * @since 1.0.0
103
	 */
104
	public function settings_page_html() {
105
		if ( ! current_user_can( 'manage_options' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can 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

105
		if ( ! /** @scrutinizer ignore-call */ current_user_can( 'manage_options' ) ) {
Loading history...
106
			return;
107
		}
108
		?>
109
		<div class="wrap">
110
			<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
0 ignored issues
show
Bug introduced by
The function get_admin_page_title 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

110
			<h1><?php echo esc_html( /** @scrutinizer ignore-call */ get_admin_page_title() ); ?></h1>
Loading history...
Bug introduced by
The function esc_html 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

110
			<h1><?php echo /** @scrutinizer ignore-call */ esc_html( get_admin_page_title() ); ?></h1>
Loading history...
111
			<form action="options.php" method="POST">
112
				<?php
113
				settings_fields( 'wp_site_monitor_group' );
0 ignored issues
show
Bug introduced by
The function settings_fields 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

113
				/** @scrutinizer ignore-call */ 
114
    settings_fields( 'wp_site_monitor_group' );
Loading history...
114
				do_settings_sections( 'wp_site_monitor' );
0 ignored issues
show
Bug introduced by
The function do_settings_sections 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

114
				/** @scrutinizer ignore-call */ 
115
    do_settings_sections( 'wp_site_monitor' );
Loading history...
115
				submit_button( 'Save Settings' );
0 ignored issues
show
Bug introduced by
The function submit_button 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

115
				/** @scrutinizer ignore-call */ 
116
    submit_button( 'Save Settings' );
Loading history...
116
				?>
117
			</form>
118
		</div>
119
		<?php
120
	}
121
122
	/**
123
	 * Initialise plugin settings.
124
	 *
125
	 * @since 1.0.0
126
	 */
127
	public function init_settings() {
128
		register_setting( 'wp_site_monitor_group', 'wp_site_monitor_option', 'string' );
0 ignored issues
show
Bug introduced by
The function register_setting 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

128
		/** @scrutinizer ignore-call */ 
129
  register_setting( 'wp_site_monitor_group', 'wp_site_monitor_option', 'string' );
Loading history...
129
130
		add_settings_section(
0 ignored issues
show
Bug introduced by
The function add_settings_section 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

130
		/** @scrutinizer ignore-call */ 
131
  add_settings_section(
Loading history...
131
			'wp_site_monitor_section_id',
132
			__( 'WP Site Monitor Settings', 'wp-site-monitor' ),
0 ignored issues
show
Bug introduced by
The function __ 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

132
			/** @scrutinizer ignore-call */ 
133
   __( 'WP Site Monitor Settings', 'wp-site-monitor' ),
Loading history...
133
			array( $this, 'setting_section_html' ),
134
			'wp_site_monitor'
135
		);
136
137
		add_settings_field(
0 ignored issues
show
Bug introduced by
The function add_settings_field 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

137
		/** @scrutinizer ignore-call */ 
138
  add_settings_field(
Loading history...
138
			'wp_site_monitor_option_id',
139
			__( 'Some Input', 'wp-site-monitor' ),
140
			array( $this, 'setting_input_html' ),
141
			'wp_site_monitor',
142
			'wp_site_monitor_section_id',
143
			[
144
				'label_for'         => 'wporg_field_pill',
145
				'class'             => 'wporg_row',
146
				'wporg_custom_data' => 'custom',
147
			]
148
		);
149
	}
150
151
	/**
152
	 * Form text.
153
	 *
154
	 * @param array $args Arguments passed into add_settings_section.
155
	 *
156
	 * @since 1.0.0
157
	 */
158
	public function setting_section_html( $args ) {
159
		?>
160
		<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'WP Site Monitor settings text', 'wp-site-monitor' ); ?></p>
0 ignored issues
show
Bug introduced by
The function esc_attr 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

160
		<p id="<?php echo /** @scrutinizer ignore-call */ esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'WP Site Monitor settings text', 'wp-site-monitor' ); ?></p>
Loading history...
Bug introduced by
The function esc_html_e 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

160
		<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php /** @scrutinizer ignore-call */ esc_html_e( 'WP Site Monitor settings text', 'wp-site-monitor' ); ?></p>
Loading history...
161
		<?php
162
	}
163
164
	/**
165
	 * Form inputs.
166
	 *
167
	 * @param array $args Element parameters.
168
	 *
169
	 * @since 1.0.0
170
	 */
171
	public function setting_input_html( $args ) {
172
		$options = get_option( 'wp_site_monitor' );
0 ignored issues
show
Bug introduced by
The function get_option 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

172
		$options = /** @scrutinizer ignore-call */ get_option( 'wp_site_monitor' );
Loading history...
173
		?>
174
		<select id="<?php echo esc_attr( $args['label_for'] ); ?>"
0 ignored issues
show
Bug introduced by
The function esc_attr 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

174
		<select id="<?php echo /** @scrutinizer ignore-call */ esc_attr( $args['label_for'] ); ?>"
Loading history...
175
				data-custom="<?php echo esc_attr( $args['wporg_custom_data'] ); ?>"
176
				name="wporg_options[<?php echo esc_attr( $args['label_for'] ); ?>]"
177
		>
178
			<option value="red" <?php echo isset( $options[ $args['label_for'] ] ) ? ( selected( $options[ $args['label_for'] ], 'red', false ) ) : ( '' ); ?>>
0 ignored issues
show
Bug introduced by
The function selected 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

178
			<option value="red" <?php echo isset( $options[ $args['label_for'] ] ) ? ( /** @scrutinizer ignore-call */ selected( $options[ $args['label_for'] ], 'red', false ) ) : ( '' ); ?>>
Loading history...
179
				<?php esc_html_e( 'red pill', 'wporg' ); ?>
0 ignored issues
show
Bug introduced by
The function esc_html_e 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

179
				<?php /** @scrutinizer ignore-call */ esc_html_e( 'red pill', 'wporg' ); ?>
Loading history...
180
			</option>
181
			<option value="blue" <?php echo isset( $options[ $args['label_for'] ] ) ? ( selected( $options[ $args['label_for'] ], 'blue', false ) ) : ( '' ); ?>>
182
				<?php esc_html_e( 'blue pill', 'wporg' ); ?>
183
			</option>
184
		</select>
185
		<p class="description">
186
			<?php esc_html_e( 'You take the blue pill and the story ends. You wake in your bed and you believe whatever you want to believe.', 'wporg' ); ?>
187
		</p>
188
		<p class="description">
189
			<?php esc_html_e( 'You take the red pill and you stay in Wonderland and I show you how deep the rabbit-hole goes.', 'wporg' ); ?>
190
		</p>
191
		<?php
192
	}
193
}
194