| @@ -20,11 +20,8 @@ | ||
| 20 | 20 | |
| 21 | 21 | // For the wp-config object |
| 22 | 22 | private $wp_config; |
| 23 | 23 | |
| 24 | - // For the log trimmer object | |
| 25 | - private $log_trimmer; | |
| 26 | - | |
| 27 | 24 | /** |
| 28 | 25 | * Creates or returns a single instance of this class |
| 29 | 26 | * |
| 30 | 27 | * @return Debug_Log_Manager a single instance of this class. |
| @@ -53,9 +50,9 @@ | ||
| 53 | 50 | add_action( 'admin_notices', [ $this, 'suppress_admin_notices' ], 0 ); |
| 54 | 51 | add_action( 'all_admin_notices', [ $this, 'suppress_generic_notices' ], 0 ); |
| 55 | 52 | |
| 56 | 53 | // Add action links |
| 57 | - add_filter( 'plugin_action_links_'.DLM__SLUG.'/'.DLM__SLUG.'.php', [ $this, 'action_links' ] ); | |
| 54 | + add_filter( 'plugin_action_links_'.DLM_SLUG.'/'.DLM_SLUG.'.php', [ $this, 'action_links' ] ); | |
| 58 | 55 | |
| 59 | 56 | if ( is_admin() ) { |
| 60 | 57 | |
| 61 | 58 | if ( $this->is_dlm() ) { |
| @@ -96,9 +93,9 @@ | ||
| 96 | 93 | |
| 97 | 94 | if ( ( $logging_status == 'enabled' ) && ! $this->is_dlm() ) { |
| 98 | 95 | |
| 99 | 96 | // https://developer.wordpress.org/reference/hooks/admin_bar_menu/ |
| 100 | - add_action( 'admin_bar_menu', [ $this, 'admin_bar_icon' ], 100 ); | |
| 97 | + add_action( 'admin_bar_menu', [ $this, 'admin_bar_icon' ] ); | |
| 101 | 98 | |
| 102 | 99 | } |
| 103 | 100 | |
| 104 | 101 | // Add dashboard widget |
| @@ -110,16 +107,8 @@ | ||
| 110 | 107 | |
| 111 | 108 | // Enqueue public scripts and styles |
| 112 | 109 | add_action( 'wp_enqueue_scripts', [ $this, 'public_scripts' ] ); |
| 113 | 110 | |
| 114 | - // Schedule log trim cron for existing installs upgraded without re-activation. | |
| 115 | - if ( ! wp_next_scheduled( 'dlm_trim_debug_log' ) ) { | |
| 116 | - wp_schedule_event( time(), 'hourly', 'dlm_trim_debug_log' ); | |
| 117 | - } | |
| 118 | - | |
| 119 | - $this->log_trimmer = new DLM\Classes\Log_Trimmer; | |
| 120 | - add_action( 'dlm_trim_debug_log', [ $this->log_trimmer, 'maybe_trim_log' ] ); | |
| 121 | - | |
| 122 | 111 | // Register ajax calls |
| 123 | 112 | $this->debug_log = new DLM\Classes\Debug_Log; |
| 124 | 113 | $this->wp_config = new DLM\Classes\WP_Config_Transformer; |
| 125 | 114 | add_action( 'wp_ajax_toggle_debugging', [ $this->debug_log, 'toggle_debugging' ] ); |
| @@ -126,11 +115,8 @@ | ||
| 126 | 115 | add_action( 'wp_ajax_toggle_autorefresh', [ $this->debug_log, 'toggle_autorefresh' ] ); |
| 127 | 116 | add_action( 'wp_ajax_get_latest_entries', [ $this->debug_log, 'get_latest_entries' ] ); |
| 128 | 117 | add_action( 'wp_ajax_clear_log', [ $this->debug_log, 'clear_log' ] ); |
| 129 | 118 | add_action( 'wp_ajax_disable_wp_file_editor', [ $this->debug_log, 'disable_wp_file_editor' ] ); |
| 130 | - add_action( 'wp_ajax_toggle_js_error_logging', [ $this->debug_log, 'toggle_js_error_logging' ] ); | |
| 131 | - add_action( 'wp_ajax_toggle_script_debug_modification_status', [ $this->debug_log, 'toggle_script_debug_modification_status' ] ); | |
| 132 | - add_action( 'wp_ajax_toggle_process_non_utc_timezones_status', [ $this->debug_log, 'toggle_process_non_utc_timezones_status' ] ); | |
| 133 | 119 | add_action( 'wp_ajax_log_js_errors', [ $this->debug_log, 'log_js_errors' ] ); |
| 134 | 120 | add_action( 'wp_ajax_nopriv_log_js_errors', [ $this->debug_log, 'log_js_errors' ] ); |
| 135 | 121 | |
| 136 | 122 | } |
| @@ -143,9 +129,9 @@ | ||
| 143 | 129 | public function is_dlm() { |
| 144 | 130 | |
| 145 | 131 | $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug |
| 146 | 132 | |
| 147 | - if ( strpos( $request_uri, 'tools.php?page=' . DLM__SLUG ) !== false ) { | |
| 133 | + if ( strpos( $request_uri, 'tools.php?page=' . DLM_SLUG ) !== false ) { | |
| 148 | 134 | return true; // Yes, this is the plugin's main page |
| 149 | 135 | } else { |
| 150 | 136 | return false; // Nope, this is NOT the plugin's page |
| 151 | 137 | } |
| @@ -176,9 +162,9 @@ | ||
| 176 | 162 | * @since 1.0.0 |
| 177 | 163 | */ |
| 178 | 164 | public function action_links( $links ) { |
| 179 | 165 | |
| 180 | - $settings_link = '<a href="tools.php?page='.DLM__SLUG.'">' . esc_html__( 'View Debug Log', 'debug-log-manager' ) . '</a>'; | |
| 166 | + $settings_link = '<a href="tools.php?page='.DLM_SLUG.'">' . esc_html__( 'View Debug Log', 'debug-log-manager' ) . '</a>'; | |
| 181 | 167 | |
| 182 | 168 | array_unshift($links, $settings_link); |
| 183 | 169 | |
| 184 | 170 | return $links; |
| @@ -219,13 +205,13 @@ | ||
| 219 | 205 | |
| 220 | 206 | // https://developer.wordpress.org/reference/classes/wp_admin_bar/add_menu/ |
| 221 | 207 | // https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/ for more examples |
| 222 | 208 | $wp_admin_bar->add_menu( array( |
| 223 | - 'id' => DLM__SLUG, | |
| 209 | + 'id' => DLM_SLUG, | |
| 224 | 210 | 'parent' => 'top-secondary', |
| 225 | 211 | 'group' => null, |
| 226 | 212 | 'title' => '<span class="dashicons dashicons-warning"></span>', |
| 227 | - 'href' => admin_url( 'tools.php?page=' . DLM__SLUG ), | |
| 213 | + 'href' => admin_url( 'tools.php?page=' . DLM_SLUG ), | |
| 228 | 214 | 'meta' => array( |
| 229 | 215 | 'class' => 'dlm-admin-bar-icon', |
| 230 | 216 | 'title' => esc_attr__( 'Error logging is enabled. Click to access the Debug Log Manager.', 'debug-log-manager' ) |
| 231 | 217 | ), |
| @@ -264,20 +250,18 @@ | ||
| 264 | 250 | <div class="dlm-logging-status"> |
| 265 | 251 | <div class="dlm-log-status-toggle"> |
| 266 | 252 | <input type="checkbox" id="debug-log-checkbox" class="inset-3 debug-log-checkbox"><label for="debug-log-checkbox" class="green debug-log-switcher"></label> |
| 267 | 253 | </div> |
| 268 | - <?php echo wp_kses_post( $this->debug_log->get_status() ); ?> | |
| 254 | + <?php echo $this->debug_log->get_status(); ?> | |
| 269 | 255 | </div> |
| 270 | 256 | <div class="dlm-autorefresh-status"> |
| 271 | 257 | <div class="dlm-log-autorefresh-toggle"> |
| 272 | 258 | <input type="checkbox" id="debug-autorefresh-checkbox" class="inset-3 debug-autorefresh-checkbox"><label for="debug-autorefresh-checkbox" class="green debug-autorefresh-switcher"></label> |
| 273 | 259 | </div> |
| 274 | - <?php echo wp_kses_post( $this->debug_log->get_autorefresh_status() ); ?> | |
| 260 | + <?php echo $this->debug_log->get_autorefresh_status(); ?> | |
| 275 | 261 | </div> |
| 276 | 262 | </div> |
| 277 | 263 | <?php |
| 278 | - // Ref: https://docs.wpvip.com/vip-code-analysis-bot/customize-phpcs/ | |
| 279 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already late-escaped before output here | |
| 280 | 264 | $this->debug_log->get_entries_datatable(); |
| 281 | 265 | ?> |
| 282 | 266 | </div> |
| 283 | 267 | <div class="dlm-footer"> |
| @@ -288,36 +272,10 @@ | ||
| 288 | 272 | <div id="dlm-disable-wp-file-editor-section" class="dlm-footer-section dlm-top-border" style="display:none;"> |
| 289 | 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> |
| 290 | 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> |
| 291 | 275 | </div> |
| 292 | - <div id="dlm-extra-settings" class="dlm-footer-section dlm-top-border"> | |
| 293 | - <div class="dlm-extra-setting"> | |
| 294 | - <div class="dlm-js-error-logging-status-toggle"> | |
| 295 | - <input type="checkbox" id="js-error-logging-checkbox" class="inset-3 js-error-logging-checkbox"><label for="js-error-logging-checkbox" class="green js-error-logging-switcher"></label> | |
| 296 | - </div> | |
| 297 | - <div class="dlm-extra-setting-label"> | |
| 298 | - <?php echo esc_html__( 'Do not log javascript errors', 'debug-log-manager' ); ?> | |
| 299 | - </div> | |
| 300 | - </div> | |
| 301 | - <div class="dlm-extra-setting"> | |
| 302 | - <div class="dlm-script-debug-mod-status-toggle"> | |
| 303 | - <input type="checkbox" id="script-debug-mod-checkbox" class="inset-3 script-debug-mod-checkbox"><label for="script-debug-mod-checkbox" class="green script-debug-mod-switcher"></label> | |
| 304 | - </div> | |
| 305 | - <div class="dlm-extra-setting-label"> | |
| 306 | - <?php echo esc_html__( 'Do not modify SCRIPT_DEBUG value in wp-config.php', 'debug-log-manager' ); ?> | |
| 307 | - </div> | |
| 308 | - </div> | |
| 309 | - <div class="dlm-extra-setting"> | |
| 310 | - <div class="dlm-process-non-utc-timezones-status-toggle"> | |
| 311 | - <input type="checkbox" id="process-non-utc-timezones-checkbox" class="inset-3 process-non-utc-timezones-checkbox"><label for="process-non-utc-timezones-checkbox" class="green process-non-utc-timezones-switcher"></label> | |
| 312 | - </div> | |
| 313 | - <div class="dlm-extra-setting-label"> | |
| 314 | - <?php echo esc_html__( 'Do not process entries with non-UTC timezones, which can be resource-intensive when log file size is significantly large.', 'debug-log-manager' ); ?> | |
| 315 | - </div> | |
| 316 | - </div> | |
| 317 | - </div> | |
| 318 | 276 | <?php |
| 319 | - echo wp_kses_post( $this->wp_config->wpconfig_file( 'status' ) ); | |
| 277 | + echo $this->wp_config->wpconfig_file( 'status' ); | |
| 320 | 278 | ?> |
| 321 | 279 | </div> |
| 322 | 280 | </div> |
| 323 | 281 | |
| @@ -335,9 +293,9 @@ | ||
| 335 | 293 | public function suppress_admin_notices() { |
| 336 | 294 | |
| 337 | 295 | global $plugin_page; |
| 338 | 296 | |
| 339 | - if ( DLM__SLUG === $plugin_page ) { | |
| 297 | + if ( DLM_SLUG === $plugin_page ) { | |
| 340 | 298 | remove_all_actions( 'admin_notices' ); |
| 341 | 299 | } |
| 342 | 300 | |
| 343 | 301 | } |
| @@ -352,9 +310,9 @@ | ||
| 352 | 310 | global $plugin_page; |
| 353 | 311 | |
| 354 | 312 | // Suppress all notices |
| 355 | 313 | |
| 356 | - if ( DLM__SLUG === $plugin_page ) { | |
| 314 | + if ( DLM_SLUG === $plugin_page ) { | |
| 357 | 315 | |
| 358 | 316 | remove_all_actions( 'all_admin_notices' ); |
| 359 | 317 | |
| 360 | 318 | } |
| @@ -399,15 +357,15 @@ | ||
| 399 | 357 | * @since 1.0.0 |
| 400 | 358 | */ |
| 401 | 359 | public function admin_scripts() { |
| 402 | 360 | |
| 403 | - wp_enqueue_style( 'dlm-admin', DLM__URL . 'assets/css/admin.css', array(), DLM__VERSION ); | |
| 404 | - wp_enqueue_style( 'dlm-datatables', DLM__URL . 'assets/css/datatables.min.css', array(), DLM__VERSION ); | |
| 405 | - wp_enqueue_style( 'dlm-toast', DLM__URL . 'assets/css/jquery.toast.min.css', array(), DLM__VERSION ); | |
| 406 | - wp_enqueue_script( 'dlm-app', DLM__URL . 'assets/js/admin.js', array(), DLM__VERSION, false ); | |
| 407 | - wp_enqueue_script( 'dlm-jsticky', DLM__URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), DLM__VERSION, false ); | |
| 408 | - wp_enqueue_script( 'dlm-datatables', DLM__URL . 'assets/js/datatables.min.js', array( 'jquery' ), DLM__VERSION, false ); | |
| 409 | - wp_enqueue_script( 'dlm-toast', DLM__URL . 'assets/js/jquery.toast.min.js', array( 'jquery' ), DLM__VERSION, false ); | |
| 361 | + wp_enqueue_style( 'dlm-admin', DLM_URL . 'assets/css/admin.css', array(), DLM_VERSION ); | |
| 362 | + wp_enqueue_style( 'dlm-datatables', DLM_URL . 'assets/css/datatables.min.css', array(), DLM_VERSION ); | |
| 363 | + wp_enqueue_style( 'dlm-toast', DLM_URL . 'assets/css/jquery.toast.min.css', array(), DLM_VERSION ); | |
| 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 ); | |
| 366 | + wp_enqueue_script( 'dlm-datatables', DLM_URL . 'assets/js/datatables.min.js', array( 'jquery' ), DLM_VERSION, false ); | |
| 367 | + wp_enqueue_script( 'dlm-toast', DLM_URL . 'assets/js/jquery.toast.min.js', array( 'jquery' ), DLM_VERSION, false ); | |
| 410 | 368 | |
| 411 | 369 | // Pass on data from PHP to JS |
| 412 | 370 | |
| 413 | 371 | $default_value = array( |
| @@ -423,15 +381,9 @@ | ||
| 423 | 381 | } else { |
| 424 | 382 | $autorefresh_status = 'disabled'; |
| 425 | 383 | update_option( 'debug_log_manager_autorefresh', $autorefresh_status, false ); |
| 426 | 384 | } |
| 427 | - | |
| 428 | - $js_error_logging_status = get_option( 'debug_log_manager_js_error_logging', 'enabled' ); | |
| 429 | - $modify_script_debug_status = get_option( 'debug_log_manager_modify_script_debug', 'enabled' ); | |
| 430 | - $process_non_utc_timezones_status = get_option( 'debug_log_manager_process_non_utc_timezones', 'enabled' ); | |
| 431 | 385 | |
| 432 | - $title_of_column_to_filter = __( 'Type', 'debug-log-manager' ); | |
| 433 | - | |
| 434 | 386 | $nonce = wp_create_nonce( 'dlm-app' . get_current_user_id() ); |
| 435 | 387 | |
| 436 | 388 | wp_localize_script( |
| 437 | 389 | 'dlm-app', |
| @@ -436,19 +388,15 @@ | ||
| 436 | 388 | wp_localize_script( |
| 437 | 389 | 'dlm-app', |
| 438 | 390 | 'dlmVars', |
| 439 | 391 | array( |
| 440 | - 'logStatus' => $log_status, | |
| 441 | - 'autorefreshStatus' => $autorefresh_status, | |
| 442 | - 'jsErrorLoggingStatus' => $js_error_logging_status, | |
| 443 | - 'modifyScriptDebugStatus' => $modify_script_debug_status, | |
| 444 | - 'processNonUtcTimezonesStatus' => $process_non_utc_timezones_status, | |
| 445 | - 'titleOfColumnToFilter' => $title_of_column_to_filter, | |
| 392 | + 'logStatus' => $log_status, | |
| 393 | + 'autorefreshStatus' => $autorefresh_status, | |
| 446 | 394 | 'nonce' => $nonce, |
| 447 | 395 | 'jsErrorLogging' => array( |
| 448 | 396 | 'status' => '', |
| 449 | 397 | 'url' => admin_url( 'admin-ajax.php' ), |
| 450 | - 'nonce' => wp_create_nonce( DLM__SLUG ), | |
| 398 | + 'nonce' => wp_create_nonce( DLM_SLUG ), | |
| 451 | 399 | 'action' => 'log_js_errors', |
| 452 | 400 | ), |
| 453 | 401 | 'toastMessage' => array( |
| 454 | 402 | 'toggleDebugSuccess' => __( 'Error logging has been enabled and the latest entries have been loaded.', 'debug-log-manager' ), |
| @@ -483,10 +431,10 @@ | ||
| 483 | 431 | * @since 2.0.0 |
| 484 | 432 | */ |
| 485 | 433 | public function plugin_editor_scripts() { |
| 486 | 434 | |
| 487 | - wp_enqueue_style( 'dlm-plugin-theme-editor', DLM__URL . 'assets/css/plugin-theme-editor.css', array(), DLM__VERSION ); | |
| 488 | - wp_enqueue_script( 'dlm-plugin-editor', DLM__URL . 'assets/js/plugin-editor.js', array( 'jquery', 'wp-theme-plugin-editor' ), DLM__VERSION, false ); | |
| 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 ); | |
| 489 | 437 | |
| 490 | 438 | } |
| 491 | 439 | |
| 492 | 440 | /** |
| @@ -495,10 +443,10 @@ | ||
| 495 | 443 | * @since 2.0.0 |
| 496 | 444 | */ |
| 497 | 445 | public function theme_editor_scripts() { |
| 498 | 446 | |
| 499 | - wp_enqueue_style( 'dlm-plugin-theme-editor', DLM__URL . 'assets/css/plugin-theme-editor.css', array(), DLM__VERSION ); | |
| 500 | - wp_enqueue_script( 'dlm-theme-editor', DLM__URL . 'assets/js/theme-editor.js', array( 'jquery', 'wp-theme-plugin-editor' ), DLM__VERSION, false ); | |
| 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 ); | |
| 501 | 449 | |
| 502 | 450 | } |
| 503 | 451 | |
| 504 | 452 | /** |
| @@ -542,36 +490,36 @@ | ||
| 542 | 490 | * |
| 543 | 491 | * @since 1.4.0 |
| 544 | 492 | */ |
| 545 | 493 | public function public_scripts() { |
| 546 | - $log_info_default_value = array( | |
| 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( | |
| 547 | 501 | 'status' => 'disabled', |
| 548 | 502 | 'on' => date( 'Y-m-d H:i:s' ), |
| 549 | 503 | ); |
| 550 | 504 | |
| 551 | - $log_info = get_option( 'debug_log_manager', $log_info_default_value ); | |
| 505 | + $log_info = get_option( 'debug_log_manager', $default_value ); | |
| 552 | 506 | $log_status = $log_info['status']; // WP_DEBUG log status: enabled / disabled |
| 553 | 507 | |
| 554 | - $js_error_logging_status = get_option( 'debug_log_manager_js_error_logging', 'enabled' ); // enabled | disabled | |
| 555 | - | |
| 556 | - if ( 'enabled' == $log_status && 'enabled' == $js_error_logging_status ) { | |
| 557 | - wp_enqueue_script( 'dlm-public', DLM__URL . 'assets/js/public.js', array( 'jquery' ), DLM__VERSION, false ); | |
| 558 | - | |
| 559 | - wp_localize_script( | |
| 560 | - 'dlm-public', | |
| 561 | - 'dlmVars', | |
| 562 | - array( | |
| 563 | - 'logStatus' => $log_status, | |
| 564 | - 'jsErrorLogging' => array( | |
| 565 | - 'status' => '', | |
| 566 | - 'url' => admin_url( 'admin-ajax.php' ), | |
| 567 | - 'nonce' => wp_create_nonce( DLM__SLUG ), | |
| 568 | - 'action' => 'log_js_errors', | |
| 569 | - ), | |
| 570 | - ) | |
| 571 | - ); | |
| 572 | - } | |
| 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 | + ); | |
| 573 | 521 | } |
| 574 | 522 | |
| 575 | 523 | } |
| 576 | 524 | |
| 577 | 525 | Debug_Log_Manager::get_instance(); |