/** * Store log data. * * @param bool $override Whether to override the text domain. Default false. * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @param string $mofile Path to the MO file. * @return bool */ public function log_file_load($override, $domain, $mofile) { $trace = new QM_Backtrace(); $filtered = $trace->get_filtered_trace(); $caller = array(); foreach ($filtered as $i => $item) { if (in_array($item['function'], array('load_plugin_textdomain', 'load_theme_textdomain', 'load_default_textdomain'), true)) { $caller = $item; $display = $i + 1; if (isset($filtered[$display])) { $caller['display'] = $filtered[$display]['display']; } break; } } if (empty($caller)) { if (isset($filtered[1])) { $caller = $filtered[1]; } else { $caller = $filtered[0]; } } if (!isset($caller['file']) && isset($filtered[0]['file']) && isset($filtered[0]['line'])) { $caller['file'] = $filtered[0]['file']; $caller['line'] = $filtered[0]['line']; } $this->data['languages'][] = array('caller' => $caller, 'domain' => $domain, 'mofile' => $mofile, 'found' => file_exists($mofile) ? filesize($mofile) : false); return $override; }
public function error_handler($errno, $message, $file = null, $line = null) { switch ($errno) { case E_WARNING: case E_USER_WARNING: $type = 'warning'; break; case E_NOTICE: case E_USER_NOTICE: $type = 'notice'; break; case E_STRICT: $type = 'strict'; break; case QM_E_DEPRECATED: case QM_E_USER_DEPRECATED: $type = 'deprecated'; break; default: return false; break; } if (!class_exists('QM_Backtrace')) { return false; } if (!isset(self::$unexpected_error)) { // These strings are from core. They're passed through `__()` as variables so they get translated at runtime // but do not get seen by GlotPress when it populates its database of translatable strings for QM. $unexpected_error = 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'; $wordpress_couldnt = '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'; self::$unexpected_error = __($unexpected_error); self::$wordpress_couldnt = __($wordpress_couldnt); } // Intentionally skip reporting these core warnings. They're a distraction when developing offline. // The failed HTTP request will still appear in QM's output so it's not a big problem hiding these warnings. if (self::$unexpected_error === $message) { return false; } if (self::$unexpected_error . ' ' . self::$wordpress_couldnt === $message) { return false; } $trace = new QM_Backtrace(array('ignore_current_filter' => false)); $caller = $trace->get_caller(); $key = md5($message . $file . $line . $caller['id']); $filename = QM_Util::standard_dir($file, ''); if (isset($this->data['errors'][$type][$key])) { $this->data['errors'][$type][$key]->calls++; } else { $this->data['errors'][$type][$key] = (object) array('errno' => $errno, 'type' => $type, 'message' => $message, 'file' => $file, 'filename' => $filename, 'line' => $line, 'trace' => $trace, 'calls' => 1); } return apply_filters('qm/collect/php_errors_return_value', false); }
public function error_handler($errno, $message, $file = null, $line = null) { #if ( !( error_reporting() & $errno ) ) # return false; switch ($errno) { case E_WARNING: case E_USER_WARNING: $type = 'warning'; break; case E_NOTICE: case E_USER_NOTICE: $type = 'notice'; break; case E_STRICT: $type = 'strict'; break; case QM_E_DEPRECATED: case QM_E_USER_DEPRECATED: $type = 'deprecated'; break; default: return false; break; } if (error_reporting() > 0) { if (!class_exists('QM_Backtrace')) { return false; } $trace = new QM_Backtrace(array('ignore_current_filter' => false)); $caller = $trace->get_caller(); $key = md5($message . $file . $line . $caller['id']); $filename = QM_Util::standard_dir($file, ''); if (isset($this->data['errors'][$type][$key])) { $this->data['errors'][$type][$key]->calls++; } else { $this->data['errors'][$type][$key] = (object) array('errno' => $errno, 'type' => $type, 'message' => $message, 'file' => $file, 'filename' => $filename, 'line' => $line, 'trace' => $trace, 'calls' => 1); } } return apply_filters('qm/collect/php_errors_return_value', false); }
public function filter_trace(array $trace) { if (!self::$filtered and function_exists('did_action') and did_action('plugins_loaded')) { # Only run apply_filters on these once self::$ignore_class = apply_filters('qm/trace/ignore_class', self::$ignore_class); self::$ignore_method = apply_filters('qm/trace/ignore_method', self::$ignore_method); self::$ignore_func = apply_filters('qm/trace/ignore_func', self::$ignore_func); self::$show_args = apply_filters('qm/trace/show_args', self::$show_args); self::$filtered = true; } $return = $trace; if (isset($trace['class'])) { if (isset(self::$ignore_class[$trace['class']])) { $return = null; } else { if (isset(self::$ignore_method[$trace['class']][$trace['function']])) { $return = null; } else { if (0 === strpos($trace['class'], 'QM_')) { $return = null; } else { $return['id'] = $trace['class'] . $trace['type'] . $trace['function'] . '()'; $return['display'] = $trace['class'] . $trace['type'] . $trace['function'] . '()'; } } } } else { if (isset(self::$ignore_func[$trace['function']])) { $return = null; } else { if (isset(self::$show_args[$trace['function']])) { $show = self::$show_args[$trace['function']]; if ('dir' === $show) { if (isset($trace['args'][0])) { $arg = QM_Util::standard_dir($trace['args'][0], '~/'); $return['id'] = $trace['function'] . '()'; $return['display'] = $trace['function'] . "('{$arg}')"; } } else { $args = array(); for ($i = 0; $i < $show; $i++) { if (isset($trace['args'][$i])) { $args[] = '\'' . $trace['args'][$i] . '\''; } } $return['id'] = $trace['function'] . '()'; $return['display'] = $trace['function'] . '(' . implode(',', $args) . ')'; } } else { $return['id'] = $trace['function'] . '()'; $return['display'] = $trace['function'] . '()'; } } } if ($return) { $return['calling_file'] = $this->calling_file; $return['calling_line'] = $this->calling_line; } if (isset($trace['line'])) { $this->calling_line = $trace['line']; } if (isset($trace['file'])) { $this->calling_file = $trace['file']; } return $return; }