-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjetpack-toggle-development-admin.php
More file actions
76 lines (67 loc) · 1.49 KB
/
jetpack-toggle-development-admin.php
File metadata and controls
76 lines (67 loc) · 1.49 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
<?php
/**
* Jetpack Toggle Development Mode Admin.
*
* @package HWDSB_JP
*/
/**
* Admin class for Jetpack Toggle Development Mode.
*/
class HWDSB_JP_Admin {
/**
* Initializer.
*/
public static function init() {
return new self;
}
/**
* Constructor.
*/
protected function __construct() {
if ( false === $this->enable_field() ) {
// Remove the Jetpack main menu while we're at it!
remove_submenu_page( 'jetpack', 'jetpack' );
return;
}
register_setting( 'general', 'hwdsb_use_jetpack', array( $this, 'validate' ) );
add_settings_field(
'hwdsb-use-jetpack',
__( 'Jetpack', 'hwdsb-jp' ),
array( $this, 'display_field' ),
'general'
);
}
/**
* Validate our option.
*/
public function validate( $input ) {
return intval( $input );
}
/**
* Display our field.
*/
public function display_field() {
$setting = (int) get_option( 'hwdsb_use_jetpack' );
?>
<label for="hwdsb-use-jetpack">
<input type="checkbox" <?php checked( $setting, 1 ); ?> value="1" id="hwdsb-use-jetpack" name="hwdsb_use_jetpack">
<?php _e( 'Enable WordPress.com Jetpack functionality?' ); ?>
</label>
<?php
}
/**
* Helper method to determine if we should see this admin field.
*/
protected function enable_field() {
if ( is_super_admin() ) {
return true;
}
// If username contains numbers, this is a student, so bail!
$user = wp_get_current_user();
if ( 1 === preg_match( '#\d#', $user->user_login ) ) {
return false;
} else {
return true;
}
}
}