PluginProbe
Debug Log Manager – Conveniently Monitor and Inspect Errors / 1.3.3
Debug Log Manager – Conveniently Monitor and Inspect Errors v1.3.3
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
debug-log-manager / bootstrap.php

bootstrap.php in Debug Log Manager – Conveniently Monitor and Inspect Errors 1.3.3, at bootstrap.php

222 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // We're using the singleton design pattern
4 // https://code.tutsplus.com/articles/design-patterns-in-wordpress-the-singleton-pattern--wp-31621
5 // https://carlalexander.ca/singletons-in-wordpress/
6 // https://torquemag.io/2016/11/singletons-wordpress-good-evil/
7
8 /**
9 * Main class of the plugin used to add functionalities
10 *
11 * @since 1.0.0
12 */
13 class Debug_Log_Manager {
14
15 // Refers to a single instance of this class
16 private static $instance = null;
17
18 // For the debug log object
19 private $debug_log;
20
21 /**
22 * Creates or returns a single instance of this class
23 *
24 * @return Debug_Log_Manager a single instance of this class.
25 */
26 public static function get_instance() {
27
28 if ( null == self::$instance ) {
29 self::$instance = new self;
30 }
31
32 return self::$instance;
33
34 }
35
36 /**
37 * Initialize plugin functionalities
38 */
39 private function __construct() {
40
41 // Register admin menu and subsequently the main admin page
42 add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
43
44 // Add action links
45 add_filter( 'plugin_action_links_'.DLM_SLUG.'/'.DLM_SLUG.'.php', [ $this, 'action_links' ] );
46
47 if ( is_admin() && $this->is_dlm() ) {
48
49 // Update footer text
50 add_filter( 'admin_footer_text', [ $this, 'footer_text' ] );
51
52 // Enqueue admin scripts and styles only on the plugin's main page
53 add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
54
55 }
56
57 // Register ajax calls
58 $this->debug_log = new DLM\Classes\Debug_Log;
59 add_action( 'wp_ajax_toggle_debugging', [ $this->debug_log, 'toggle_debugging' ] );
60 add_action( 'wp_ajax_toggle_autorefresh', [ $this->debug_log, 'toggle_autorefresh' ] );
61 add_action( 'wp_ajax_get_latest_entries', [ $this->debug_log, 'get_latest_entries' ] );
62 add_action( 'wp_ajax_clear_log', [ $this->debug_log, 'clear_log' ] );
63
64 }
65
66 /**
67 * Check if current screen is this plugin's main page
68 *
69 * @since 1.0.0
70 */
71 public function is_dlm() {
72
73 $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug
74
75 if ( strpos( $request_uri, 'tools.php?page=' . DLM_SLUG ) !== false ) {
76 return true; // Yes, this is the plugin's main page
77 } else {
78 return false; // Nope, this is NOT the plugin's page
79 }
80
81 }
82
83 /**
84 * Register admin menu
85 *
86 * @since 1.0.0
87 */
88 public function register_admin_menu() {
89
90 add_submenu_page(
91 'tools.php',
92 'Debug Log Manager',
93 'Debug Log Manager',
94 'manage_options',
95 'debug-log-manager',
96 [ $this, 'create_main_page' ]
97 );
98
99 }
100
101 /**
102 * Register action links
103 *
104 * @since 1.0.0
105 */
106 public function action_links( $links ) {
107
108 $settings_link = '<a href="tools.php?page='.DLM_SLUG.'">View Debug Log</a>';
109
110 array_unshift($links, $settings_link);
111
112 return $links;
113
114 }
115
116 /**
117 * Change admin footer text
118 *
119 * @since 1.0.0
120 */
121 public function footer_text() {
122 ?>
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>.
124 <?php
125 }
126
127 /**
128 * Create the main admin page of the plugin
129 *
130 * @since 1.0.0
131 */
132 public function create_main_page() {
133
134 $log_file_path = get_option( 'debug_log_manager_file_path' );
135 $log_file_shortpath = str_replace( sanitize_text_field( $_SERVER['DOCUMENT_ROOT'] ), "", $log_file_path );
136 $file_size = size_format( (int) filesize( $log_file_path ) );
137
138 ?>
139
140 <div class="wrap dlm-main-page">
141 <div id="dlm-header" class="dlm-header">
142 <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>
144 </div>
145 <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>�
148 </span> Review</a>
149 <a href="https://wordpress.org/support/plugin/debug-log-manager/" target="_blank" class="dlm-header-action"> Feedback</a>
150 <a href="https://paypal.me/qriouslad" target="_blank" class="dlm-header-action">&#10084; Donate</a>
151 </div>
152 </div>
153 <div class="dlm-body">
154 <div class="dlm-log-management">
155 <div class="dlm-logging-status">
156 <div class="dlm-log-status-toggle">
157 <input type="checkbox" id="debug-log-checkbox" class="inset-3 debug-log-checkbox"><label for="debug-log-checkbox" class="green debug-log-switcher"></label>
158 </div>
159 <?php echo $this->debug_log->get_status(); ?>
160 </div>
161 <div class="dlm-autorefresh-status">
162 <div class="dlm-log-autorefresh-toggle">
163 <input type="checkbox" id="debug-autorefresh-checkbox" class="inset-3 debug-autorefresh-checkbox"><label for="debug-autorefresh-checkbox" class="green debug-autorefresh-switcher"></label>
164 </div>
165 <?php echo $this->debug_log->get_autorefresh_status(); ?>
166 </div>
167 </div>
168 <?php
169 $this->debug_log->get_entries_datatable();
170 ?>
171 </div>
172 <div class="dlm-footer">
173 <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>
174 <button id="dlm-log-clear" class="button button-small button-secondary dlm-log-clear">Clear Log</button>
175 </div>
176 </div>
177
178 <?php
179
180 }
181
182 /**
183 * Enqueue admin scripts
184 *
185 * @since 1.0.0
186 */
187 public function admin_scripts() {
188
189 wp_enqueue_style( 'dlm-admin', DLM_URL . 'assets/css/admin.css', array(), DLM_VERSION );
190 wp_enqueue_style( 'dlm-datatables', DLM_URL . 'assets/css/datatables.min.css', array(), DLM_VERSION );
191 wp_enqueue_style( 'dlm-toast', DLM_URL . 'assets/css/jquery.toast.min.css', array(), DLM_VERSION );
192 wp_enqueue_script( 'dlm-app', DLM_URL . 'assets/js/app.js', array(), DLM_VERSION, false );
193 wp_enqueue_script( 'dlm-jsticky', DLM_URL . 'assets/js/jquery.jsticky.min.js', array( 'jquery' ), DLM_VERSION, false );
194 wp_enqueue_script( 'dlm-datatables', DLM_URL . 'assets/js/datatables.min.js', array( 'jquery' ), DLM_VERSION, false );
195 wp_enqueue_script( 'dlm-toast', DLM_URL . 'assets/js/jquery.toast.min.js', array( 'jquery' ), DLM_VERSION, false );
196
197 // Pass on data from PHP to JS
198
199 $log_info = get_option( 'debug_log_manager' );
200 $log_status = $log_info['status'];
201
202 if ( false !== get_option( 'debug_log_manager_autorefresh' ) ) {
203 $autorefresh_status = get_option( 'debug_log_manager_autorefresh' );
204 } else {
205 $autorefresh_status = 'disabled';
206 update_option( 'debug_log_manager_autorefresh', $autorefresh_status, false );
207 }
208
209 wp_localize_script(
210 'dlm-app',
211 'dlmVars',
212 array(
213 'logStatus' => $log_status,
214 'autorefreshStatus' => $autorefresh_status,
215 )
216 );
217
218 }
219
220 }
221
222 Debug_Log_Manager::get_instance();