forked from mrxkon/wp-live-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-wp-live-debug.php
More file actions
381 lines (350 loc) · 13.1 KB
/
Copy pathclass-wp-live-debug.php
File metadata and controls
381 lines (350 loc) · 13.1 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php //phpcs:ignore
/**
*
* Plugin Name: WP Live Debug
* Description: Enables debugging and adds a screen into the WordPress Admin to view the debug.log.
* Version: 4.9.8.6
* Author: Konstantinos (xkon) Xenos
* Author URI: https://xkon.gr
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-live-debug
* Domain Path: /languages
*
*/
/*
Copyright Konstantinos Xenos ( https://xkon.gr )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
Credits & Licences:
This is a personal project that I use for debugging, but some parts of the code are written by other awesome people.
So props also go to:
WPMU DEV ( https://premium.wpmudev.org ) for parts of debug info & Shared UI
- Shared UI ( https://github.com/wpmudev/shared-ui ) - Licence GPLv2
The WordPress.org ( https://wordpress.org ) community for parts of debug info
- Health Check ( https://wordpress.org/plugins/health-check/ ) - Licence GPLv2 - ( https://github.com/wordpress/health-check )
*/
/**************************************************/
/****************** Plugin Start ******************/
/**************************************************/
// Check that the file is not accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
die( 'We\'re sorry, but you can not directly access this file.' );
}
/**
* Define the plugin version for internal use
*/
define( 'WP_LIVE_DEBUG_VERSION', '4.9.8.6' );
define( 'WP_LIVE_DEBUG_WP_CONFIG', ABSPATH . 'wp-config.php' );
define( 'WP_LIVE_DEBUG_WP_CONFIG_BACKUP_ORIGINAL', ABSPATH . 'wp-config.wpld-original-backup.php' );
define( 'WP_LIVE_DEBUG_WP_CONFIG_BACKUP', ABSPATH . 'wp-config.wpld-manual-backup.php' );
/**
* WP_Live_Debug Class.
*/
if ( ! class_exists( 'WP_Live_Debug' ) ) {
class WP_Live_Debug {
/**
* WP_Live_Debug constructor.
*
* @uses WP_Live_Debug::init()
*
* @return void
*/
public function __construct() {
$this->init();
}
/**
* Plugin initialization.
*
* @uses add_action()
*
* @return void
*/
public function init() {
add_action( 'init', array( 'WP_Live_Debug', 'create_menus' ) );
add_action( 'admin_enqueue_scripts', array( 'WP_Live_Debug', 'enqueue_scripts_styles' ) );
add_action( 'wp_ajax_wp-live-debug-accept-risk', array( 'WP_Live_Debug', 'accept_risk' ) );
}
/**
* Accept Risk Popup.
*
* @uses update_option()
* @uses esc_html__()
* @uses wp_send_json_success()
*
* @return string json success with the response.
*/
public static function accept_risk() {
update_option( 'wp_live_debug_risk', 'yes' );
$response = array(
'message' => esc_html__( 'risk accepted.', 'wp-live-debug' ),
);
wp_send_json_success( $response );
}
/**
* Activation Hook.
*
* @uses get_site_url()
* @uses update_option()
* @uses WP_Live_Debug_Helper::create_debug_log()
*
* @return void
*/
public static function on_activate() {
$host = str_replace( array( 'http://', 'https://' ), '', get_site_url() );
update_option( 'wp_live_debug_ssl_domain', $host );
WP_Live_Debug_Helper::create_debug_log();
WP_Live_Debug_Helper::get_first_backup();
}
/**
* Deactivation Hook.
*
* @uses delete_option()
*
* @return void
*/
public static function on_deactivate() {
delete_option( 'wp_live_debug_risk' );
delete_option( 'wp_live_debug_ssl_domain' );
delete_option( 'wp_live_debug_log_file' );
WP_Live_Debug_Helper::clear_manual_backup();
}
/**
* Create the Admin Menus.
*
* @uses is_multisite()
* @uses add_action()
*
* @return void
*/
public static function create_menus() {
if ( ! is_multisite() ) {
add_action( 'admin_menu', array( 'WP_Live_Debug', 'populate_admin_menu' ) );
} else {
add_action( 'network_admin_menu', array( 'WP_Live_Debug', 'populate_admin_menu' ) );
}
}
/**
* Populate the Admin menu.
*
* @uses add_menu_page()
* @uses esc_html__()
*
* @return void
*/
public static function populate_admin_menu() {
add_menu_page(
esc_html__( 'WP Live Debug', 'wp-live-debug' ),
esc_html__( 'WP Live Debug', 'wp-live-debug' ),
'manage_options',
'wp-live-debug',
array( 'WP_Live_Debug', 'create_page' ),
'dashicons-media-code'
);
}
/**
* Enqueue scripts and styles.
*
* @param string $hook WordPress generated class for the current page.
*
* @uses wp_enqueue_style()
* @uses plugin_dir_url()
* @uses add_filter()
*
* @return void
*/
public static function enqueue_scripts_styles( $hook ) {
if ( 'toplevel_page_wp-live-debug' === $hook ) {
wp_enqueue_style(
'wphb-wpmudev-sui',
plugin_dir_url( __FILE__ ) . 'assets/sui/css/shared-ui.min.css',
'2.2.10'
);
wp_enqueue_script(
'wphb-wpmudev-sui',
plugin_dir_url( __FILE__ ) . 'assets/sui/js/shared-ui.min.js',
array( 'jquery' ),
'2.2.10',
true
);
wp_enqueue_style(
'wp-live-debug',
plugin_dir_url( __FILE__ ) . 'assets/styles.css',
array( 'wphb-wpmudev-sui' ),
WP_LIVE_DEBUG_VERSION
);
wp_enqueue_script(
'wp-live-debug',
plugin_dir_url( __FILE__ ) . 'assets/scripts.js',
array( 'wphb-wpmudev-sui' ),
WP_LIVE_DEBUG_VERSION,
true
);
add_filter( 'admin_body_class', array( 'WP_Live_Debug', 'admin_body_classes' ) );
}
}
/**
* Add Shared UI Classes to body.
*
* @param string $classes Maybe existing classes.
*
* @return string $classes Updated classes list including the Shared-UI classes.
*/
public static function admin_body_classes( $classes ) {
$classes .= ' sui-2-2-10 ';
return $classes;
}
/**
* Create the WP Live Debug page.
*
* @uses get_option()
* @uses esc_attr()
* @uses esc_html_e()
* @uses _e()
* @uses WP_Live_Debug_WordPress_Info::create_page()
* @uses WP_Live_Debug_Server_Info::create_page();
* @uses WP_Live_Debug_Cronjob_Info::create_page();
* @uses WP_Live_Debug_Tools::create_page();
* @uses WP_Live_Debug_WPMUDEV::create_page();
* @uses WP_Live_Debug_Live_Debug::create_page();
* @uses WP_Live_Debug_Live_Debug::create_page();
*
* @return string html The html of the page viewed.
*/
public static function create_page() {
if ( ! empty( $_GET['subpage'] ) ) {
$subpage = esc_attr( $_GET['subpage'] );
}
?>
<div class="sui-wrap">
<div class="sui-header">
<h1 class="sui-header-title">WP Live Debug</h1>
</div>
<div class="sui-row-with-sidenav">
<div class="sui-sidenav">
<ul class="sui-vertical-tabs sui-sidenav-hide-md">
<li class="sui-vertical-tab <?php echo ( empty( $subpage ) ) ? 'current' : ''; ?>">
<a href="?page=wp-live-debug"><?php esc_html_e( 'Live Debug', 'wp-live-debug' ); ?></a>
</li>
<li class="sui-vertical-tab <?php echo ( ! empty( $subpage ) && 'WordPress' === $subpage ) ? 'current' : ''; ?>">
<a href="?page=wp-live-debug&subpage=WordPress"><?php esc_html_e( 'WordPress', 'wp-live-debug' ); ?></a>
</li>
<li class="sui-vertical-tab <?php echo ( ! empty( $subpage ) && 'Server' === $subpage ) ? 'current' : ''; ?>">
<a href="?page=wp-live-debug&subpage=Server"><?php esc_html_e( 'Server', 'wp-live-debug' ); ?></a>
</li>
<li class="sui-vertical-tab <?php echo ( ! empty( $subpage ) && 'Cron' === $subpage ) ? 'current' : ''; ?>">
<a href="?page=wp-live-debug&subpage=Cron"><?php esc_html_e( 'Scheduled Events', 'wp-live-debug' ); ?></a>
</li>
<li class="sui-vertical-tab <?php echo ( ! empty( $subpage ) && 'Tools' === $subpage ) ? 'current' : ''; ?>">
<a href="?page=wp-live-debug&subpage=Tools"><?php esc_html_e( 'Tools', 'wp-live-debug' ); ?></a>
</li>
<li class="sui-vertical-tab <?php echo ( ! empty( $subpage ) && 'WPMUDEV' === $subpage ) ? 'current' : ''; ?>">
<a href="?page=wp-live-debug&subpage=WPMUDEV"><?php esc_html_e( 'WPMU DEV', 'wp-live-debug' ); ?></a>
</li>
</ul>
<div class="sui-sidenav-hide-lg">
<select class="sui-mobile-nav" style="display: none;" onchange="location = this.value;">
<option value="?page=wp-live-debug" <?php echo ( empty( $subpage ) ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Live Debug', 'wp-live-debug' ); ?></option>
<option value="?page=wp-live-debug&subpage=WordPress" <?php echo ( ! empty( $subpage ) && 'WordPress' === $subpage ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'WordPress', 'wp-live-debug' ); ?></option>
<option value="?page=wp-live-debug&subpage=Server" <?php echo ( ! empty( $subpage ) && 'Server' === $subpage ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Server', 'wp-live-debug' ); ?></option>
<option value="?page=wp-live-debug&subpage=Cron" <?php echo ( ! empty( $subpage ) && 'Cron' === $subpage ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Scheduled Events', 'wp-live-debug' ); ?></option>
<option value="?page=wp-live-debug&subpage=Tools" <?php echo ( ! empty( $subpage ) && 'Tools' === $subpage ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Tools', 'wp-live-debug' ); ?></option>
<option value="?page=wp-live-debug&subpage=WPMUDEV" <?php echo ( ! empty( $subpage ) && 'WPMUDEV' === $subpage ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'WPMU DEV', 'wp-live-debug' ); ?></option>
</select>
</div>
</div>
<?php
if ( ! empty( $subpage ) ) {
switch ( $subpage ) {
case 'WordPress':
WP_Live_Debug_WordPress_Info::create_page();
break;
case 'Server':
WP_Live_Debug_Server_Info::create_page();
break;
case 'Cron':
WP_Live_Debug_Cronjob_Info::create_page();
break;
case 'Tools':
WP_Live_Debug_Tools::create_page();
break;
case 'WPMUDEV':
WP_Live_Debug_WPMUDEV::create_page();
break;
default:
WP_Live_Debug_Live_Debug::create_page();
}
} else {
WP_Live_Debug_Live_Debug::create_page();
}
?>
</div>
<?php
$first_time_running = get_option( 'wp_live_debug_risk' );
if ( empty( $first_time_running ) ) {
?>
<div class="sui-dialog sui-dialog-sm" aria-hidden="true" tabindex="-1" id="safety-popup">
<div class="sui-dialog-overlay" data-a11y-dialog-hide></div>
<div class="sui-dialog-content" aria-labelledby="dialogTitle" aria-describedby="dialogDescription" role="dialog">
<div class="sui-box" role="document">
<div class="sui-box-header">
<h3 class="sui-box-title">Safety First!</h3>
</div>
<div class="sui-box-body">
<p>
<?php
_e( 'WP LIVE DEBUG enables debugging, checks files and runs various tests to gather information about your installation.', 'wp-live-debug' );
?>
</p>
<p>
<?php
_e( 'Make sure to have a <strong>full backup</strong> first before proceeding with any of the tools.', 'wp-live-debug' );
?>
</p>
</div>
<div class="sui-box-footer">
<a href="?page=wp-live-debug&wplddlwpconfig=true" class="sui-modal-close sui-button sui-button-green"><?php esc_html_e( 'Download wp-config', 'wp-live-debug' ); ?></a>
<button id="riskaccept" class="sui-modal-close sui-button sui-button-blue"><?php esc_html_e( 'I understand', 'wp-live-debug' ); ?></button>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<?php
}
}
// Activation Hook
register_activation_hook( __FILE__, array( 'WP_Live_Debug', 'on_activate' ) );
// Deactivation Hook
register_deactivation_hook( __FILE__, array( 'WP_Live_Debug', 'on_deactivate' ) );
// Require extra files
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-live-debug.php';
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-wordpress-info.php';
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-server-info.php';
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-cronjob-info.php';
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-tools.php';
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-wpmudev.php';
require_once plugin_dir_path( __FILE__ ) . '/classes/class-wp-live-debug-helper.php';
// Initialize Classes.
new WP_Live_Debug();
new WP_Live_Debug_Live_Debug();
new WP_Live_Debug_WordPress_Info();
new WP_Live_Debug_Server_Info();
new WP_Live_Debug_Cronjob_Info();
new WP_Live_Debug_Tools();
new WP_Live_Debug_WPMUDEV();
new WP_Live_Debug_Helper();
}