public function displayWidgetContents() { $log = Elm_PhpErrorLog::autodetect(); if (is_wp_error($log)) { $this->displayConfigurationHelp($log->get_error_message()); return; } if (isset($_GET['elm-log-cleared']) && !empty($_GET['elm-log-cleared'])) { echo '<p><strong>Log cleared.</strong></p>'; } $lines = $log->readLastLines($this->settings->get('widget_line_count'), true); if (is_wp_error($lines)) { printf('<p>%s</p>', $lines->get_error_message()); } else { if (empty($lines)) { echo '<p>The log file is empty.</p>'; } else { if ($this->settings->get('sort_order') === 'reverse-chronological') { $lines = array_reverse($lines); } echo '<table class="widefat" style="table-layout: fixed; overflow: hidden; box-sizing: border-box;">', '<colgroup><col style="width: 9em;"><col></colgroup>', '<tbody>'; $isOddRow = false; foreach ($lines as $line) { $isOddRow = !$isOddRow; if ($this->settings->get('strip_wordpress_path')) { $line['message'] = $this->plugin->stripWpPath($line['message']); } printf('<tr%s><td style="white-space:nowrap;">%s</td><td>%s</td></tr>', $isOddRow ? ' class="alternate"' : '', !empty($line['timestamp']) ? $this->plugin->formatTimestamp($line['timestamp']) : '', esc_html($line['message'])); } echo '</tbody></table>'; echo '<p>'; printf('Log file: %s (%s) ', esc_html($log->getFilename()), $this->formatByteCount($log->getFileSize(), 2)); printf('<a href="%s" class="button" onclick="return confirm(\'%s\');">%s</a>', wp_nonce_url(admin_url('/index.php?elm-action=clear-log&noheader=1'), 'clear-log'), 'Are you sure you want to clear the error log?', 'Clear Log'); echo '</p>'; } } }
public function displayWidgetContents() { $log = Elm_PhpErrorLog::autodetect(); if (is_wp_error($log)) { $this->displayConfigurationHelp($log->get_error_message()); return; } $doClearLog = isset($_GET['elm-action']) && ($_GET['elm-action'] = 'clear-log') && check_admin_referer('clear-log') && current_user_can($this->requiredCapability); if ($doClearLog) { $log->clear(); echo '<p><strong>Log cleared.</strong></p>'; } $lines = $log->readLastLines($this->settings->get('widget_line_count'), true); if (is_wp_error($lines)) { printf('<p>%s</p>', $lines->get_error_message()); } else { if (empty($lines)) { echo '<p>The log file is empty.</p>'; } else { echo '<table class="widefat"><tbody>'; $isOddRow = false; foreach ($lines as $line) { $isOddRow = !$isOddRow; if ($this->settings->get('strip_wordpress_path')) { $line['message'] = $this->plugin->stripWpPath($line['message']); } printf('<tr%s><td style="white-space:nowrap;">%s</td><td>%s</td></tr>', $isOddRow ? ' class="alternate"' : '', !empty($line['timestamp']) ? $this->plugin->formatTimestamp($line['timestamp']) : '', esc_html($line['message'])); } echo '</tbody></table>'; echo '<p>'; printf('Log file: %s (%s) ', esc_html($log->getFilename()), $this->formatByteCount($log->getFileSize(), 2)); printf('<a href="%s" class="button" onclick="return confirm(\'%s\');">%s</a>', wp_nonce_url(admin_url('/index.php?elm-action=clear-log'), 'clear-log'), 'Are you sure you want to clear the error log?', 'Clear Log'); echo '</p>'; } } }