Changeset 1338445
- Timestamp:
- 01/28/2016 08:59:11 PM (10 years ago)
- Location:
- wp-log-viewer/trunk
- Files:
-
- 3 edited
-
libs/Plugin.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
-
wp-log-viewer.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-log-viewer/trunk/libs/Plugin.php
r1321328 r1338445 28 28 29 29 /** 30 * @var boolean Check if current user has permission to access WP Log Viewer 31 * 32 * @since 1.0.1 33 */ 34 var $user_authorized = false; 35 36 37 /** 30 38 * Initialize plugin 31 39 * … … 34 42 public function init() { 35 43 // Register actions 36 add_action('admin_menu', [$this, 'add_navigation']); 37 add_action('admin_enqueue_scripts', [$this, 'load_plugin_css_and_js']); 38 add_action('wp_dashboard_setup', [$this, 'register_dashboard_widgets']); 39 add_action('admin_bar_menu', [$this, 'add_admin_bar_menu'], 900); 44 add_action('admin_init', [$this, 'check_if_authorized'], 1); 40 45 add_action('template_redirect', [$this, 'add_dynamic_routes'], 1, 1); 41 46 42 // Initialize ajax handler 43 Ajax::get_instance(); 47 if (\is_admin()) { 48 add_action('admin_menu', [$this, 'add_navigation']); 49 add_action('admin_enqueue_scripts', [$this, 'load_plugin_css_and_js']); 50 add_action('wp_dashboard_setup', [$this, 'register_dashboard_widgets']); 51 add_action('admin_bar_menu', [$this, 'add_admin_bar_menu'], 900); 52 53 // Initialize ajax handler 54 Ajax::get_instance(); 55 } 56 } 57 58 59 /** 60 * Check if user has permission to access WP Log Viewer 61 * 62 * @since 1.0.1 63 */ 64 public function check_if_authorized() { 65 $this->user_authorized = apply_filters('wplv_user_authorized', \current_user_can('manage_options')); 44 66 } 45 67 … … 51 73 */ 52 74 public function load_plugin_css_and_js() { 53 // $auth = Auth::get_instance(); 54 $settings = Settings::get_instance(); 55 $log = Log::get_instance(); 56 $user_id = \get_current_user_id(); 57 $screen = get_current_screen(); 58 $localized = [ 59 'api' => admin_url('admin-ajax.php'), 60 'debug_enabled' => WP_DEBUG, 61 'debug_toggleable' => $log->is_debug_toggleable() ? 1 : 0, 62 'current_page' => is_object($screen) ? $screen->id : '', 63 'plugin_url' => admin_url('tools.php?page=wp-log-viewer'), 64 'settings' => $settings->get_settings($user_id), 65 'user_id' => $user_id, 66 ]; 67 68 // Stylesheet files 69 wp_enqueue_style('wplogviewer-css', WPLOGVIEWER_URL . 'assets/css/main.min.css'); 70 71 // Javascript files 72 wp_enqueue_script('wplogviewer-js', WPLOGVIEWER_URL . 'assets/js/main.min.js', false, false, true); 73 74 // Localize variables 75 wp_localize_script('wplogviewer-js', 'WPLOGVIEWER', $localized); 75 if ($this->user_authorized) { 76 // $auth = Auth::get_instance(); 77 $settings = Settings::get_instance(); 78 $log = Log::get_instance(); 79 $user_id = \get_current_user_id(); 80 $screen = get_current_screen(); 81 $localized = [ 82 'api' => admin_url('admin-ajax.php'), 83 'debug_enabled' => WP_DEBUG, 84 'debug_toggleable' => $log->is_debug_toggleable() ? 1 : 0, 85 'current_page' => is_object($screen) ? $screen->id : '', 86 'plugin_url' => admin_url('tools.php?page=wp-log-viewer'), 87 'settings' => $settings->get_settings($user_id), 88 'user_id' => $user_id, 89 ]; 90 91 // Stylesheet files 92 wp_enqueue_style('wplogviewer-css', WPLOGVIEWER_URL . 'assets/css/main.min.css'); 93 94 // Javascript files 95 wp_enqueue_script('wplogviewer-js', WPLOGVIEWER_URL . 'assets/js/main.min.js', false, false, true); 96 97 // Localize variables 98 wp_localize_script('wplogviewer-js', 'WPLOGVIEWER', $localized); 99 } 76 100 } 77 101 … … 83 107 */ 84 108 public function add_navigation() { 85 add_management_page('Wordpress Log Viewer', 'Log Viewer', 'manage_options', 'wp-log-viewer', [$this, 'display_viewer_page']); 109 if ($this->user_authorized) { 110 add_management_page('Wordpress Log Viewer', 'Log Viewer', 'manage_options', 'wp-log-viewer', [$this, 'display_viewer_page']); 111 } 86 112 } 87 113 … … 103 129 */ 104 130 public function register_dashboard_widgets() { 105 if (\current_user_can('manage_options')) { 131 $show_dashboard_widget = apply_filters('wplv_show_dashboard_widget', true); 132 133 if ($this->user_authorized && $show_dashboard_widget) { 106 134 \wp_add_dashboard_widget('wplv-widget', 'WP Log Viewer', [$this, 'display_dashboard_widget']); 107 135 } … … 125 153 */ 126 154 public function add_admin_bar_menu($admin_bar) { 127 $admin_bar->add_node([ 128 'id' => 'wplv-menu', 129 'title' => 'Debug Log', 130 'href' => admin_url('tools.php?page=wp-log-viewer'), 131 'meta' => ['class' => 'wplv-admin-bar-node'] 132 ]); 155 $show_adminbar = apply_filters('wplv_show_adminbar_widget', true); 156 157 if ($this->user_authorized && $show_adminbar) { 158 $admin_bar->add_node([ 159 'id' => 'wplv-menu', 160 'title' => 'Debug Log', 161 'href' => admin_url('tools.php?page=wp-log-viewer'), 162 'meta' => ['class' => 'wplv-admin-bar-node'] 163 ]); 164 } 133 165 } 134 166 … … 148 180 149 181 if ($url_path == '/debugging/download/log/') { 150 header('Pragma: PUBLIC'); 151 header('Content-Type: application/octet-stream; charset=utf-8'); 152 header('Content-Disposition: attachment; filename="debug.log"'); 153 header('HTTP/1.1 200 OK'); 154 155 $config = $settings->get_settings($user_id); 156 157 if (isset($config['truncate_download']) && $config['truncate_download']) { 158 $found = []; 159 $entries = $log->get_entries(); 160 161 foreach ($entries as $entry) { 162 $key = md5($entry['message']); 163 164 if (!isset($found[$key])) { 165 $found[$key] = true; 166 echo '[' . $entry['date'] . ' ' . $entry['time'] . ' ' . $entry['timezone'] . '] ' . $entry['message']; 182 $can_download = apply_filters('wplv_can_download_log', \current_user_can('manage_options')); 183 184 if ($can_download) { 185 header('Pragma: PUBLIC'); 186 header('Content-Type: application/octet-stream; charset=utf-8'); 187 header('Content-Disposition: attachment; filename="debug.log"'); 188 header('HTTP/1.1 200 OK'); 189 190 $config = $settings->get_settings($user_id); 191 192 if (isset($config['truncate_download']) && $config['truncate_download']) { 193 $found = []; 194 $entries = $log->get_entries(); 195 196 foreach ($entries as $entry) { 197 $key = md5($entry['message']); 198 199 if (!isset($found[$key])) { 200 $found[$key] = true; 201 echo '[' . $entry['date'] . ' ' . $entry['time'] . ' ' . $entry['timezone'] . '] ' . $entry['message']; 202 } 167 203 } 204 } else { 205 echo trim($log->get_contents()); 168 206 } 169 } else { 170 e cho trim($log->get_contents());207 208 exit(); 171 209 } 172 173 exit();174 210 } 175 211 } -
wp-log-viewer/trunk/readme.txt
r1321328 r1338445 6 6 Requires at least: 3.9 7 7 Tested up to: 4.4 8 Stable tag: 1.0. 18 Stable tag: 1.0.2 9 9 10 10 One click enable/disable debugging, clear debug.log, search, sort, and filter errors. See new errors automatically without refreshing. … … 219 219 All notable changes will be tracked in this change log. 220 220 221 = 1.0.2 = 222 Release date: 2016-01-28 223 224 * Feature 225 * Added ability to limit who can see WP Log Viewer 226 227 * Hook 228 * Added filter wplv_user_authorized 229 * Added filter wplv_can_download_log 230 * Added filter wplv_show_dashboard_widget 231 * Added filter wplv_show_adminbar_widget 232 221 233 = 1.0.1 = 222 234 Release date: 2016-01-04 -
wp-log-viewer/trunk/wp-log-viewer.php
r1321328 r1338445 10 10 * Plugin URI: https://github.com/allbitsnbytes/wp-log-viewer 11 11 * Description: Wordpress debug log viewer plugin 12 * Version: 1.0. 112 * Version: 1.0.2 13 13 * Author: Maxwell Berkel 14 14 * Author URI: http://allbitsnbytes.com
Note: See TracChangeset
for help on using the changeset viewer.