1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Simple admin interface to activate/deactivate modules |
4
|
|
|
* |
5
|
|
|
* @package Jetpack |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Debug_Helper; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Jetpack_Debug_Helper_Admin |
12
|
|
|
*/ |
13
|
|
|
class Admin { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Option name. |
17
|
|
|
*/ |
18
|
|
|
const OPTION_NAME = 'jetpack_debug_helper_active_modules'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor. |
22
|
|
|
*/ |
23
|
|
|
public function __construct() { |
24
|
|
|
add_action( 'admin_menu', array( $this, 'register_submenu_page' ), 1000 ); |
25
|
|
|
add_action( 'admin_post_store_debug_active_modules', array( $this, 'update_option' ) ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Register's submenu. |
30
|
|
|
*/ |
31
|
|
|
public function register_submenu_page() { |
32
|
|
|
add_submenu_page( |
33
|
|
|
'jetpack', |
34
|
|
|
'Debug tools', |
35
|
|
|
'Debug tools', |
36
|
|
|
'manage_options', |
37
|
|
|
'debug-tools', |
38
|
|
|
array( $this, 'render_ui' ), |
39
|
|
|
99 |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the list of active modules |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public static function get_active_modules() { |
49
|
|
|
return get_option( self::OPTION_NAME, array() ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Render UI. |
54
|
|
|
*/ |
55
|
|
|
public function render_ui() { |
56
|
|
|
$stored_options = get_option( self::OPTION_NAME, array() ); |
57
|
|
|
global $jetpack_dev_debug_modules; |
58
|
|
|
?> |
59
|
|
|
<h1>Jetpack Debug tools</h1> |
60
|
|
|
<p>This plugin adds debugging tools to your jetpack. Choose which tools you want to activate.</p> |
61
|
|
|
|
62
|
|
|
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"> |
63
|
|
|
<input type="hidden" name="action" value="store_debug_active_modules"> |
64
|
|
|
<?php wp_nonce_field( 'store-debug-modules' ); ?> |
65
|
|
|
|
66
|
|
|
<?php foreach ( $jetpack_dev_debug_modules as $module_slug => $module_details ) : ?> |
67
|
|
|
|
68
|
|
|
<p> |
69
|
|
|
<input type="checkbox" name="active_modules[]" value="<?php echo esc_attr( $module_slug ); ?>" <?php checked( in_array( $module_slug, (array) $stored_options, true ) ); ?> /> |
70
|
|
|
<b><?php echo esc_html( $module_details['name'] ); ?></b> |
71
|
|
|
<?php echo esc_html( $module_details['description'] ); ?> |
72
|
|
|
</p> |
73
|
|
|
|
74
|
|
|
<?php endforeach; ?> |
75
|
|
|
|
76
|
|
|
<input type="submit" value="Save" class="button button-primary"> |
77
|
|
|
|
78
|
|
|
</form> |
79
|
|
|
<br> |
80
|
|
|
|
81
|
|
|
<?php |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Store options. |
86
|
|
|
*/ |
87
|
|
|
public function update_option() { |
88
|
|
|
check_admin_referer( 'store-debug-modules' ); |
89
|
|
|
$active_modules = ! empty( $_POST['active_modules'] ) ? (array) $_POST['active_modules'] : array(); |
90
|
|
|
update_option( self::OPTION_NAME, $active_modules ); |
91
|
|
|
if ( wp_get_referer() ) { |
92
|
|
|
wp_safe_redirect( wp_get_referer() ); |
93
|
|
|
} else { |
94
|
|
|
wp_safe_redirect( get_home_url() ); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
add_action( |
101
|
|
|
'plugins_loaded', |
102
|
|
|
function() { |
103
|
|
|
new Admin(); |
104
|
|
|
} |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
|