PluginProbe
Debug Log Manager – Conveniently Monitor and Inspect Errors / 2.3.1
Debug Log Manager – Conveniently Monitor and Inspect Errors v2.3.1
2.5.2 2.5.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.8.0 1.8.2 1.8.3 1.8.4 All 49 releases
← All changes | bootstrap.php +325 -21 1.3.32.3.1 View file →
@@ -17,8 +17,11 @@
17 17
18 18 // For the debug log object
19 19 private $debug_log;
20 20
21 + // For the wp-config object
22 + private $wp_config;
23 +
21 24 /**
22 25 * Creates or returns a single instance of this class
23 26 *
24 27 * @return Debug_Log_Manager a single instance of this class.
@@ -37,31 +40,86 @@
37 40 * Initialize plugin functionalities
38 41 */
39 42 private function __construct() {
40 43
44 + global $pagenow;
45 +
41 46 // Register admin menu and subsequently the main admin page
42 47 add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
43 48
49 + // Do not display any admin notices while viewing logs.
50 + add_action( 'admin_notices', [ $this, 'suppress_admin_notices' ], 0 );
51 + add_action( 'all_admin_notices', [ $this, 'suppress_generic_notices' ], 0 );
52 +
44 53 // Add action links
45 54 add_filter( 'plugin_action_links_'.DLM_SLUG.'/'.DLM_SLUG.'.php', [ $this, 'action_links' ] );
46 55
47 - if ( is_admin() && $this->is_dlm() ) {
56 + if ( is_admin() ) {
48 57
49 - // Update footer text
50 - add_filter( 'admin_footer_text', [ $this, 'footer_text' ] );
58 + if ( $this->is_dlm() ) {
51 59
52 - // Enqueue admin scripts and styles only on the plugin's main page
53 - add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
60 + // Update footer text
61 + add_filter( 'admin_footer_text', [ $this, 'footer_text' ] );
62 +
63 + // Replace WP version text in footer
64 + add_filter( 'update_footer', [ $this, 'footer_version_text' ], 20 );
54 65
66 +
67 + // Enqueue admin scripts and styles only on the plugin's main page
68 + add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
69 +
70 + }
71 +
55 72 }
56 73
74 + // Enqueue admin scripts and styles on plugin editor page
75 + if ( 'plugin-editor.php' === $pagenow ) {
76 + add_action( 'admin_enqueue_scripts', [ $this, 'plugin_editor_scripts' ] );
77 + }
78 +
79 + // Enqueue admin scripts and styles on theme editor page
80 + if ( 'theme-editor.php' === $pagenow ) {
81 + add_action( 'admin_enqueue_scripts', [ $this, 'theme_editor_scripts' ] );
82 + }
83 +
84 + // Add admin bar icon if error logging is enabled and admin URL is not the plugin's main page. It will show on on the front end too (when logged-in), as we're also logging JavaScript errors.
85 +
86 + $default_value = array(
87 + 'status' => 'disabled',
88 + 'on' => date( 'Y-m-d H:i:s' ),
89 + );
90 +
91 + $logging_info = get_option( 'debug_log_manager', $default_value );
92 + $logging_status = $logging_info['status'];
93 +
94 + if ( ( $logging_status == 'enabled' ) && ! $this->is_dlm() ) {
95 +
96 + // https://developer.wordpress.org/reference/hooks/admin_bar_menu/
97 + add_action( 'admin_bar_menu', [ $this, 'admin_bar_icon' ] );
98 +
99 + }
100 +
101 + // Add dashboard widget
102 + add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
103 +
104 + // Add inline CSS for the admin bar icon (menu item)
105 + add_action( 'admin_enqueue_scripts', [ $this, 'admin_bar_icon_css' ] );
106 + add_action( 'wp_enqueue_scripts', [ $this, 'admin_bar_icon_css' ] );
107 +
108 + // Enqueue public scripts and styles
109 + add_action( 'wp_enqueue_scripts', [ $this, 'public_scripts' ] );
110 +
57 111 // Register ajax calls
58 112 $this->debug_log = new DLM\Classes\Debug_Log;
113 + $this->wp_config = new DLM\Classes\WP_Config_Transformer;
59 114 add_action( 'wp_ajax_toggle_debugging', [ $this->debug_log, 'toggle_debugging' ] );
60 115 add_action( 'wp_ajax_toggle_autorefresh', [ $this->debug_log, 'toggle_autorefresh' ] );
61 116 add_action( 'wp_ajax_get_latest_entries', [ $this->debug_log, 'get_latest_entries' ] );
62 117 add_action( 'wp_ajax_clear_log', [ $this->debug_log, 'clear_log' ] );
63 -
118 + add_action( 'wp_ajax_disable_wp_file_editor', [ $this->debug_log, 'disable_wp_file_editor' ] );
119 + add_action( 'wp_ajax_log_js_errors', [ $this->debug_log, 'log_js_errors' ] );
120 + add_action( 'wp_ajax_nopriv_log_js_errors', [ $this->debug_log, 'log_js_errors' ] );
121 +
64 122 }
65 123
66 124 /**
67 125 * Check if current screen is this plugin's main page
@@ -88,10 +146,10 @@
88 146 public function register_admin_menu() {
89 147
90 148 add_submenu_page(
91 149 'tools.php',
92 - 'Debug Log Manager',
93 - 'Debug Log Manager',
150 + __( 'Debug Log Manager', 'debug-log-manager' ),
151 + __( 'Debug Log Manager', 'debug-log-manager' ),
94 152 'manage_options',
95 153 'debug-log-manager',
96 154 [ $this, 'create_main_page' ]
97 155 );
@@ -104,9 +162,9 @@
104 162 * @since 1.0.0
105 163 */
106 164 public function action_links( $links ) {
107 165
108 - $settings_link = '<a href="tools.php?page='.DLM_SLUG.'">View Debug Log</a>';
166 + $settings_link = '<a href="tools.php?page='.DLM_SLUG.'">' . esc_html__( 'View Debug Log', 'debug-log-manager' ) . '</a>';
109 167
110 168 array_unshift($links, $settings_link);
111 169
112 170 return $links;
@@ -119,13 +177,52 @@
119 177 * @since 1.0.0
120 178 */
121 179 public function footer_text() {
122 180 ?>
123 - <a href="https://wordpress.org/plugins/debug-log-manager/" target="_blank">Debug Log Manager</a> (<a href="https://github.com/qriouslad/debug-log-manager" target="_blank">github</a>) is built using <a href="https://datatables.net/" target="_blank">DataTables.js</a>, <a href="https://github.com/AndrewHenderson/jSticky" target="_blank">jSticky</a> and <a href="https://github.com/kamranahmedse/jquery-toast-plugin" target="_blank">jQuery Toast</a>.
181 + <a href="https://bowo.io/dotorg-dlm" target="_blank"><?php esc_html_e( 'Debug Log Manager', 'debug-log-manager' ); ?></a> is on <a href="https://bowo.io/github-dlm" target="_blank">github</a>
124 182 <?php
125 183 }
184 +
185 + /**
186 + * Replace WP version number text in footer
187 + *
188 + * @since 2.1.4
189 + */
190 + public function footer_version_text() {
191 + return 'Also by Bowo &#8594; <a href="https://bowo.io/wpn-dlm" target="_blank">WordPress Newsboard</a>: The latest from 100+ sources';
192 + }
126 193
127 194 /**
195 + * Add debug icon in the admin bar
196 + *
197 + * @since 1.6.0
198 + */
199 + public function admin_bar_icon( WP_Admin_Bar $wp_admin_bar ) {
200 +
201 + $current_user = wp_get_current_user();
202 + $current_user_roles = array_values( $current_user->roles ); // indexed array
203 +
204 + if ( in_array( 'administrator', $current_user_roles ) ) {
205 +
206 + // https://developer.wordpress.org/reference/classes/wp_admin_bar/add_menu/
207 + // https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/ for more examples
208 + $wp_admin_bar->add_menu( array(
209 + 'id' => DLM_SLUG,
210 + 'parent' => 'top-secondary',
211 + 'group' => null,
212 + 'title' => '<span class="dashicons dashicons-warning"></span>',
213 + 'href' => admin_url( 'tools.php?page=' . DLM_SLUG ),
214 + 'meta' => array(
215 + 'class' => 'dlm-admin-bar-icon',
216 + 'title' => esc_attr__( 'Error logging is enabled. Click to access the Debug Log Manager.', 'debug-log-manager' )
217 + ),
218 + ) );
219 +
220 + }
221 +
222 + }
223 +
224 + /**
128 225 * Create the main admin page of the plugin
129 226 *
130 227 * @since 1.0.0
131 228 */
@@ -139,15 +236,14 @@
139 236
140 237 <div class="wrap dlm-main-page">
141 238 <div id="dlm-header" class="dlm-header">
142 239 <div class="dlm-header-left">
143 - <h1 class="dlm-heading">Debug Log Manager <small>by <a href="https://bowo.io" target="_blank">bowo.io</a></small></h1>
240 + <h1 class="dlm-heading"><?php esc_html_e( 'Debug Log Manager', 'debug-log-manager' ); ?> <small><?php esc_html_e( 'by', 'debug-log-manager' ); ?> <a href="https://bowo.io/bowoio-dlm" target="_blank">Bowo</a></small></h1>
144 241 </div>
145 242 <div class="dlm-header-right">
146 - <a href="https://wordpress.org/plugins/debug-log-manager/" target="_blank" class="dlm-header-action"><span>&#8505;</span> Info</a>
147 - <a href="https://wordpress.org/plugins/debug-log-manager/#reviews" target="_blank" class="dlm-header-action"><span>★</span> Review</a>
148 - <a href="https://wordpress.org/support/plugin/debug-log-manager/" target="_blank" class="dlm-header-action">✚ Feedback</a>
149 - <a href="https://paypal.me/qriouslad" target="_blank" class="dlm-header-action">&#10084; Donate</a>
243 + <a href="https://bowo.io/review-dlm" target="_blank" class="dlm-header-action"><span>★</span> <?php esc_html_e( 'Review', 'debug-log-manager' ); ?></a>
244 + <a href="https://bowo.io/feedback-dlm" target="_blank" class="dlm-header-action">✚ <?php esc_html_e( 'Feedback', 'debug-log-manager' ); ?></a>
245 + <a href="https://bowo.io/sponsor-dlm" target="_blank" class="button button-primary plugin-sponsor">&#10084; <?php esc_html_e( 'Sponsor', 'debug-log-manager' ); ?></a>
150 246 </div>
151 247 </div>
152 248 <div class="dlm-body">
153 249 <div class="dlm-log-management">
@@ -168,10 +264,19 @@
168 264 $this->debug_log->get_entries_datatable();
169 265 ?>
170 266 </div>
171 267 <div class="dlm-footer">
172 - <div class="dlm-log-file"><strong>Log file</strong>: <?php echo esc_html( $log_file_shortpath ); ?> (<span id="dlm-log-file-size"><?php echo esc_html( $file_size ); ?></span>)</div>
173 - <button id="dlm-log-clear" class="button button-small button-secondary dlm-log-clear">Clear Log</button>
268 + <div id="dlm-log-file-location-section" class="dlm-footer-section">
269 + <div class="dlm-log-file-location"><strong><?php esc_html_e( 'Log file', 'debug-log-manager' ); ?></strong>: <?php echo esc_html( $log_file_shortpath ); ?> (<span id="dlm-log-file-size"><?php echo esc_html( $file_size ); ?></span>)</div>
270 + <button id="dlm-log-clear" class="button button-small button-secondary dlm-footer-button dlm-log-clear"><?php esc_html_e( 'Clear Log', 'debug-log-manager' ); ?></button>
271 + </div>
272 + <div id="dlm-disable-wp-file-editor-section" class="dlm-footer-section dlm-top-border" style="display:none;">
273 + <div><?php esc_html_e( 'Once error logging is enabled, the core\'s plugin/theme editor stays enabled even if error logging has been disabled later on. This allows for viewing the files where errors occurred even when logging has been disabled. You can optionally disable the editor here once you\'re done debugging.', 'debug-log-manager' ); ?></div>
274 + <button id="dlm-disable-wp-file-editor" class="button button-small button-secondary dlm-footer-button dlm-disable-wp-file-editor"><?php esc_html_e( 'Disable Editor', 'debug-log-manager' ); ?></button>
275 + </div>
276 + <?php
277 + echo $this->wp_config->wpconfig_file( 'status' );
278 + ?>
174 279 </div>
175 280 </div>
176 281
177 282 <?php
@@ -178,8 +283,76 @@
178 283
179 284 }
180 285
181 286 /**
287 + * To stop other plugins' admin notices overlaying in the Debug Log Manager UI, remove them.
288 + *
289 + * @hooked admin_notices
290 + *
291 + * @since 1.8.7
292 + */
293 + public function suppress_admin_notices() {
294 +
295 + global $plugin_page;
296 +
297 + if ( DLM_SLUG === $plugin_page ) {
298 + remove_all_actions( 'admin_notices' );
299 + }
300 +
301 + }
302 +
303 + /**
304 + * Suppress all generic notices on the plugin settings page
305 + *
306 + * @since 1.8.8
307 + */
308 + public function suppress_generic_notices() {
309 +
310 + global $plugin_page;
311 +
312 + // Suppress all notices
313 +
314 + if ( DLM_SLUG === $plugin_page ) {
315 +
316 + remove_all_actions( 'all_admin_notices' );
317 +
318 + }
319 +
320 + }
321 +
322 + /**
323 + * Add dashboard widget with latest errors
324 + *
325 + * @since 1.8.0
326 + */
327 + public function add_dashboard_widget() {
328 +
329 + $user = wp_get_current_user();
330 + $roles = array_values( $user->roles );
331 +
332 + if ( in_array( 'administrator', $roles ) ) {
333 + wp_add_dashboard_widget(
334 + 'debug_log_manager_widget', // widget ID
335 + __( 'Debug Log | Latest Errors', 'debug-log-manager' ), // widget title
336 + array( $this, 'get_dashboard_widget_entries' ) // callback #1 to display entries
337 + // array( $this, 'dashboard_widget_settings' ) // callback #2 for configuration
338 + );
339 + }
340 +
341 + }
342 +
343 + /**
344 + * Load latest errors for dashboard widget
345 + *
346 + * @since 1.8.0
347 + */
348 + public function get_dashboard_widget_entries() {
349 +
350 + $this->debug_log->get_dashboard_widget_entries();
351 +
352 + }
353 +
354 + /**
182 355 * Enqueue admin scripts
183 356 *
184 357 * @since 1.0.0
185 358 */
@@ -187,18 +360,23 @@
187 360
188 361 wp_enqueue_style( 'dlm-admin', DLM_URL . 'assets/css/admin.css', array(), DLM_VERSION );
189 362 wp_enqueue_style( 'dlm-datatables', DLM_URL . 'assets/css/datatables.min.css', array(), DLM_VERSION );
190 363 wp_enqueue_style( 'dlm-toast', DLM_URL . 'assets/css/jquery.toast.min.css', array(), DLM_VERSION );
191 - wp_enqueue_script( 'dlm-app', DLM_URL . 'assets/js/app.js', array(), DLM_VERSION, false );
192 - wp_enqueue_script( 'dlm-jsticky', DLM_URL . 'assets/js/jquery.jsticky.min.js', array( 'jquery' ), DLM_VERSION, false );
364 + wp_enqueue_script( 'dlm-app', DLM_URL . 'assets/js/admin.js', array(), DLM_VERSION, false );
365 + wp_enqueue_script( 'dlm-jsticky', DLM_URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), DLM_VERSION, false );
193 366 wp_enqueue_script( 'dlm-datatables', DLM_URL . 'assets/js/datatables.min.js', array( 'jquery' ), DLM_VERSION, false );
194 367 wp_enqueue_script( 'dlm-toast', DLM_URL . 'assets/js/jquery.toast.min.js', array( 'jquery' ), DLM_VERSION, false );
195 368
196 369 // Pass on data from PHP to JS
197 370
198 - $log_info = get_option( 'debug_log_manager' );
199 - $log_status = $log_info['status'];
371 + $default_value = array(
372 + 'status' => 'disabled',
373 + 'on' => date( 'Y-m-d H:i:s' ),
374 + );
200 375
376 + $log_info = get_option( 'debug_log_manager', $default_value );
377 + $log_status = $log_info['status']; // WP_DEBUG log status: enabled / disabled
378 +
201 379 if ( false !== get_option( 'debug_log_manager_autorefresh' ) ) {
202 380 $autorefresh_status = get_option( 'debug_log_manager_autorefresh' );
203 381 } else {
204 382 $autorefresh_status = 'disabled';
@@ -203,8 +381,10 @@
203 381 } else {
204 382 $autorefresh_status = 'disabled';
205 383 update_option( 'debug_log_manager_autorefresh', $autorefresh_status, false );
206 384 }
385 +
386 + $nonce = wp_create_nonce( 'dlm-app' . get_current_user_id() );
207 387
208 388 wp_localize_script(
209 389 'dlm-app',
210 390 'dlmVars',
@@ -210,12 +390,136 @@
210 390 'dlmVars',
211 391 array(
212 392 'logStatus' => $log_status,
213 393 'autorefreshStatus' => $autorefresh_status,
394 + 'nonce' => $nonce,
395 + 'jsErrorLogging' => array(
396 + 'status' => '',
397 + 'url' => admin_url( 'admin-ajax.php' ),
398 + 'nonce' => wp_create_nonce( DLM_SLUG ),
399 + 'action' => 'log_js_errors',
400 + ),
401 + 'toastMessage' => array(
402 + 'toggleDebugSuccess' => __( 'Error logging has been enabled and the latest entries have been loaded.', 'debug-log-manager' ),
403 + 'copySuccess' => __( 'Entries have been copied from an existing debug.log file.', 'debug-log-manager' ),
404 + 'logFileCleared' => __( 'Log file has been cleared.', 'debug-log-manager' ),
405 + 'editoDisabled' => __( 'WordPress plugin/theme editor has been disabled. ', 'debug-log-manager' ),
406 + 'paginationActive' => __( 'Pagination is active. Auto-refresh has been disabled.', 'debug-log-manager' ),
407 + ),
408 + 'dataTable' => array(
409 + 'emptyTable' => __( 'No data available in table', 'debug-log-manager' ),
410 + 'info' => __( 'Showing _START_ to _END_ of _TOTAL_ entries', 'debug-log-manager' ),
411 + 'infoEmpty' => __( 'Showing 0 to 0 of 0 entries', 'debug-log-manager' ),
412 + 'infoFiltered' => __( '(filtered from _MAX_ total entries)', 'debug-log-manager' ),
413 + 'lengthMenu' => __( 'Show _MENU_ entries', 'debug-log-manager' ),
414 + 'search' => __( 'Search:', 'debug-log-manager' ),
415 + 'zeroRecords' => __( 'No matching records found', 'debug-log-manager' ),
416 + 'paginate' => array(
417 + 'first' => __( 'First', 'debug-log-manager' ),
418 + 'last' => __( 'Last', 'debug-log-manager' ),
419 + 'next' => __( 'Next', 'debug-log-manager' ),
420 + 'previous' => __( 'Previous', 'debug-log-manager' ),
421 + ),
422 + ),
214 423 )
215 424 );
216 425
426 + }
427 +
428 + /**
429 + * Scripts for WP plugin editor page
430 + *
431 + * @since 2.0.0
432 + */
433 + public function plugin_editor_scripts() {
434 +
435 + wp_enqueue_style( 'dlm-plugin-theme-editor', DLM_URL . 'assets/css/plugin-theme-editor.css', array(), DLM_VERSION );
436 + wp_enqueue_script( 'dlm-plugin-editor', DLM_URL . 'assets/js/plugin-editor.js', array( 'jquery', 'wp-theme-plugin-editor' ), DLM_VERSION, false );
437 +
438 + }
439 +
440 + /**
441 + * Scripts for WP theme editor page
442 + *
443 + * @since 2.0.0
444 + */
445 + public function theme_editor_scripts() {
446 +
447 + wp_enqueue_style( 'dlm-plugin-theme-editor', DLM_URL . 'assets/css/plugin-theme-editor.css', array(), DLM_VERSION );
448 + wp_enqueue_script( 'dlm-theme-editor', DLM_URL . 'assets/js/theme-editor.js', array( 'jquery', 'wp-theme-plugin-editor' ), DLM_VERSION, false );
449 +
450 + }
451 +
452 + /**
453 + * Admin bar icon's inline css
454 + *
455 + * @since 1.6.0
456 + */
457 + public function admin_bar_icon_css() {
458 +
459 + // https://developer.wordpress.org/reference/functions/wp_add_inline_style/
460 + wp_add_inline_style( 'admin-bar', '
461 +
462 + #wpadminbar .dlm-admin-bar-icon .dashicons {
463 + font-family: dashicons;
464 + font-size: 20px;
465 + width: 20px;
466 + height: 20px;
467 + line-height: 32px;
468 + }
469 +
470 + #wpadminbar .quicklinks ul li.dlm-admin-bar-icon a {
471 + background: green;
472 + }
473 +
474 + #wpadminbar:not(.mobile) .ab-top-menu>li:hover>.ab-item {
475 + transition: .25s;
476 + }
477 +
478 + #wpadminbar:not(.mobile) .ab-top-menu>li.dlm-admin-bar-icon:hover>.ab-item,
479 + #wpadminbar:not(.mobile) .ab-top-menu>li.dlm-admin-bar-icon>.ab-item:focus {
480 + background: #006600;
481 + color: #fff;
482 + }
483 +
484 + ' );
485 +
486 + }
487 +
488 + /**
489 + * Enqueue public scripts
490 + *
491 + * @since 1.4.0
492 + */
493 + public function public_scripts() {
494 +
495 + $options = get_option( 'debug_log_manager', array() );
496 + if ( $options['status'] == 'enabled' ) {
497 + wp_enqueue_script( 'dlm-public', DLM_URL . 'assets/js/public.js', array( 'jquery' ), DLM_VERSION, false );
498 + }
499 +
500 + $default_value = array(
501 + 'status' => 'disabled',
502 + 'on' => date( 'Y-m-d H:i:s' ),
503 + );
504 +
505 + $log_info = get_option( 'debug_log_manager', $default_value );
506 + $log_status = $log_info['status']; // WP_DEBUG log status: enabled / disabled
507 +
508 + wp_localize_script(
509 + 'dlm-public',
510 + 'dlmVars',
511 + array(
512 + 'logStatus' => $log_status,
513 + 'jsErrorLogging' => array(
514 + 'status' => '',
515 + 'url' => admin_url( 'admin-ajax.php' ),
516 + 'nonce' => wp_create_nonce( DLM_SLUG ),
517 + 'action' => 'log_js_errors',
518 + ),
519 + )
520 + );
217 521 }
218 522
219 523 }
220 524
221 525 Debug_Log_Manager::get_instance();