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 +145 -35 1.8.42.3.1 View file →
@@ -40,11 +40,17 @@
40 40 * Initialize plugin functionalities
41 41 */
42 42 private function __construct() {
43 43
44 + global $pagenow;
45 +
44 46 // Register admin menu and subsequently the main admin page
45 47 add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
46 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 +
47 53 // Add action links
48 54 add_filter( 'plugin_action_links_'.DLM_SLUG.'/'.DLM_SLUG.'.php', [ $this, 'action_links' ] );
49 55
50 56 if ( is_admin() ) {
@@ -52,9 +58,13 @@
52 58 if ( $this->is_dlm() ) {
53 59
54 60 // Update footer text
55 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 );
56 65
66 +
57 67 // Enqueue admin scripts and styles only on the plugin's main page
58 68 add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
59 69
60 70 }
@@ -60,8 +70,18 @@
60 70 }
61 71
62 72 }
63 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 +
64 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.
65 85
66 86 $default_value = array(
67 87 'status' => 'disabled',
@@ -78,11 +98,10 @@
78 98
79 99 }
80 100
81 101 // Add dashboard widget
102 + add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
82 103
83 - add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
84 -
85 104 // Add inline CSS for the admin bar icon (menu item)
86 105 add_action( 'admin_enqueue_scripts', [ $this, 'admin_bar_icon_css' ] );
87 106 add_action( 'wp_enqueue_scripts', [ $this, 'admin_bar_icon_css' ] );
88 107
@@ -95,11 +114,12 @@
95 114 add_action( 'wp_ajax_toggle_debugging', [ $this->debug_log, 'toggle_debugging' ] );
96 115 add_action( 'wp_ajax_toggle_autorefresh', [ $this->debug_log, 'toggle_autorefresh' ] );
97 116 add_action( 'wp_ajax_get_latest_entries', [ $this->debug_log, 'get_latest_entries' ] );
98 117 add_action( 'wp_ajax_clear_log', [ $this->debug_log, 'clear_log' ] );
118 + add_action( 'wp_ajax_disable_wp_file_editor', [ $this->debug_log, 'disable_wp_file_editor' ] );
99 119 add_action( 'wp_ajax_log_js_errors', [ $this->debug_log, 'log_js_errors' ] );
100 120 add_action( 'wp_ajax_nopriv_log_js_errors', [ $this->debug_log, 'log_js_errors' ] );
101 -
121 +
102 122 }
103 123
104 124 /**
105 125 * Check if current screen is this plugin's main page
@@ -157,11 +177,20 @@
157 177 * @since 1.0.0
158 178 */
159 179 public function footer_text() {
160 180 ?>
161 - <a href="https://wordpress.org/plugins/debug-log-manager/" target="_blank"><?php esc_html_e( 'Debug Log Manager', 'debug-log-manager' ); ?></a> (<a href="https://github.com/qriouslad/debug-log-manager" target="_blank">github</a>) <?php esc_html_e( 'is built using', 'debug-log-manager' ); ?> <a href="https://datatables.net/" target="_blank">DataTables.js</a>, <a href="https://github.com/AndrewHenderson/jSticky" target="_blank">jSticky</a> <?php esc_html_e( 'and', 'debug-log-manager' ); ?> <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>
162 182 <?php
163 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 + }
164 193
165 194 /**
166 195 * Add debug icon in the admin bar
167 196 *
@@ -168,22 +197,29 @@
168 197 * @since 1.6.0
169 198 */
170 199 public function admin_bar_icon( WP_Admin_Bar $wp_admin_bar ) {
171 200
172 - // https://developer.wordpress.org/reference/classes/wp_admin_bar/add_menu/
173 - // https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/ for more examples
174 - $wp_admin_bar->add_menu( array(
175 - 'id' => DLM_SLUG,
176 - 'parent' => 'top-secondary',
177 - 'group' => null,
178 - 'title' => '<span class="dashicons dashicons-warning"></span>',
179 - 'href' => admin_url( 'tools.php?page=' . DLM_SLUG ),
180 - 'meta' => array(
181 - 'class' => 'dlm-admin-bar-icon',
182 - 'title' => esc_attr__( 'Error logging is enabled. Click to access the Debug Log Manager.', 'debug-log-manager' )
183 - ),
184 - ) );
201 + $current_user = wp_get_current_user();
202 + $current_user_roles = array_values( $current_user->roles ); // indexed array
185 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 +
186 222 }
187 223
188 224 /**
189 225 * Create the main admin page of the plugin
@@ -200,15 +236,14 @@
200 236
201 237 <div class="wrap dlm-main-page">
202 238 <div id="dlm-header" class="dlm-header">
203 239 <div class="dlm-header-left">
204 - <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" 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>
205 241 </div>
206 242 <div class="dlm-header-right">
207 - <a href="https://wordpress.org/plugins/debug-log-manager/" target="_blank" class="dlm-header-action"><span>&#8505;</span> <?php esc_html_e( 'Info', 'debug-log-manager' ); ?></a>
208 - <a href="https://wordpress.org/plugins/debug-log-manager/#reviews" target="_blank" class="dlm-header-action"><span>★</span> <?php esc_html_e( 'Review', 'debug-log-manager' ); ?></a>
209 - <a href="https://wordpress.org/support/plugin/debug-log-manager/" target="_blank" class="dlm-header-action">✚ <?php esc_html_e( 'Feedback', 'debug-log-manager' ); ?></a>
210 - <a href="https://paypal.me/qriouslad" target="_blank" class="dlm-header-action">&#10084; <?php esc_html_e( 'Donate', 'debug-log-manager' ); ?></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>
211 246 </div>
212 247 </div>
213 248 <div class="dlm-body">
214 249 <div class="dlm-log-management">
@@ -229,13 +264,16 @@
229 264 $this->debug_log->get_entries_datatable();
230 265 ?>
231 266 </div>
232 267 <div class="dlm-footer">
233 - <div class="dlm-log-file">
268 + <div id="dlm-log-file-location-section" class="dlm-footer-section">
234 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>
235 - <button id="dlm-log-clear" class="button button-small button-secondary dlm-log-clear"><?php esc_html_e( 'Clear Log', 'debug-log-manager' ); ?></button>
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>
236 271 </div>
237 - <hr />
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>
238 276 <?php
239 277 echo $this->wp_config->wpconfig_file( 'status' );
240 278 ?>
241 279 </div>
@@ -245,8 +283,44 @@
245 283
246 284 }
247 285
248 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 + /**
249 323 * Add dashboard widget with latest errors
250 324 *
251 325 * @since 1.8.0
252 326 */
@@ -251,15 +325,20 @@
251 325 * @since 1.8.0
252 326 */
253 327 public function add_dashboard_widget() {
254 328
255 - wp_add_dashboard_widget(
256 - 'debug_log_manager_widget', // widget ID
257 - __( 'Debug Log | Latest Errors', 'debug-log-manager' ), // widget title
258 - array( $this, 'get_dashboard_widget_entries' ) // callback #1 to display entries
259 - // array( $this, 'dashboard_widget_settings' ) // callback #2 for configuration
260 - );
329 + $user = wp_get_current_user();
330 + $roles = array_values( $user->roles );
261 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 +
262 341 }
263 342
264 343 /**
265 344 * Load latest errors for dashboard widget
@@ -281,10 +360,10 @@
281 360
282 361 wp_enqueue_style( 'dlm-admin', DLM_URL . 'assets/css/admin.css', array(), DLM_VERSION );
283 362 wp_enqueue_style( 'dlm-datatables', DLM_URL . 'assets/css/datatables.min.css', array(), DLM_VERSION );
284 363 wp_enqueue_style( 'dlm-toast', DLM_URL . 'assets/css/jquery.toast.min.css', array(), DLM_VERSION );
285 - wp_enqueue_script( 'dlm-app', DLM_URL . 'assets/js/app.js', array(), DLM_VERSION, false );
286 - 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 );
287 366 wp_enqueue_script( 'dlm-datatables', DLM_URL . 'assets/js/datatables.min.js', array( 'jquery' ), DLM_VERSION, false );
288 367 wp_enqueue_script( 'dlm-toast', DLM_URL . 'assets/js/jquery.toast.min.js', array( 'jquery' ), DLM_VERSION, false );
289 368
290 369 // Pass on data from PHP to JS
@@ -302,8 +381,10 @@
302 381 } else {
303 382 $autorefresh_status = 'disabled';
304 383 update_option( 'debug_log_manager_autorefresh', $autorefresh_status, false );
305 384 }
385 +
386 + $nonce = wp_create_nonce( 'dlm-app' . get_current_user_id() );
306 387
307 388 wp_localize_script(
308 389 'dlm-app',
309 390 'dlmVars',
@@ -309,8 +390,9 @@
309 390 'dlmVars',
310 391 array(
311 392 'logStatus' => $log_status,
312 393 'autorefreshStatus' => $autorefresh_status,
394 + 'nonce' => $nonce,
313 395 'jsErrorLogging' => array(
314 396 'status' => '',
315 397 'url' => admin_url( 'admin-ajax.php' ),
316 398 'nonce' => wp_create_nonce( DLM_SLUG ),
@@ -319,8 +401,9 @@
319 401 'toastMessage' => array(
320 402 'toggleDebugSuccess' => __( 'Error logging has been enabled and the latest entries have been loaded.', 'debug-log-manager' ),
321 403 'copySuccess' => __( 'Entries have been copied from an existing debug.log file.', 'debug-log-manager' ),
322 404 'logFileCleared' => __( 'Log file has been cleared.', 'debug-log-manager' ),
405 + 'editoDisabled' => __( 'WordPress plugin/theme editor has been disabled. ', 'debug-log-manager' ),
323 406 'paginationActive' => __( 'Pagination is active. Auto-refresh has been disabled.', 'debug-log-manager' ),
324 407 ),
325 408 'dataTable' => array(
326 409 'emptyTable' => __( 'No data available in table', 'debug-log-manager' ),
@@ -342,8 +425,32 @@
342 425
343 426 }
344 427
345 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 + /**
346 453 * Admin bar icon's inline css
347 454 *
348 455 * @since 1.6.0
349 456 */
@@ -383,10 +490,13 @@
383 490 *
384 491 * @since 1.4.0
385 492 */
386 493 public function public_scripts() {
387 -
388 - wp_enqueue_script( 'dlm-public', DLM_URL . 'assets/js/public.js', array( 'jquery' ), DLM_VERSION, false );
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 + }
389 499
390 500 $default_value = array(
391 501 'status' => 'disabled',
392 502 'on' => date( 'Y-m-d H:i:s' ),