Plugin Directory

Changeset 1338445


Ignore:
Timestamp:
01/28/2016 08:59:11 PM (10 years ago)
Author:
maxwellberkel
Message:

Added new wordpress hooks, support for limiting who can view wp log viewer, updated version to 1.0.4

Location:
wp-log-viewer/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-log-viewer/trunk/libs/Plugin.php

    r1321328 r1338445  
    2828
    2929    /**
     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    /**
    3038     * Initialize plugin
    3139     *
     
    3442    public function init() {
    3543        // 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);
    4045        add_action('template_redirect', [$this, 'add_dynamic_routes'], 1, 1);
    4146
    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'));
    4466    }
    4567
     
    5173     */
    5274    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        }
    76100    }
    77101
     
    83107     */
    84108    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        }
    86112    }
    87113
     
    103129     */
    104130    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) {
    106134            \wp_add_dashboard_widget('wplv-widget', 'WP Log Viewer', [$this, 'display_dashboard_widget']);
    107135        }
     
    125153     */
    126154    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        }
    133165    }
    134166
     
    148180
    149181            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                            }
    167203                        }
     204                    } else {
     205                        echo trim($log->get_contents());
    168206                    }
    169                 } else {
    170                     echo trim($log->get_contents());
     207
     208                    exit();
    171209                }
    172 
    173                 exit();
    174210            }
    175211        }
  • wp-log-viewer/trunk/readme.txt

    r1321328 r1338445  
    66Requires at least: 3.9
    77Tested up to: 4.4
    8 Stable tag: 1.0.1
     8Stable tag: 1.0.2
    99
    1010One click enable/disable debugging, clear debug.log, search, sort, and filter errors.  See new errors automatically without refreshing.
     
    219219All notable changes will be tracked in this change log.
    220220
     221= 1.0.2 =
     222Release 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
    221233= 1.0.1 =
    222234Release date: 2016-01-04
  • wp-log-viewer/trunk/wp-log-viewer.php

    r1321328 r1338445  
    1010 * Plugin URI:  https://github.com/allbitsnbytes/wp-log-viewer
    1111 * Description: Wordpress debug log viewer plugin
    12  * Version:     1.0.1
     12 * Version:     1.0.2
    1313 * Author:      Maxwell Berkel
    1414 * Author URI:  http://allbitsnbytes.com
Note: See TracChangeset for help on using the changeset viewer.