Example #1
0
 function error_handler($type, $message, $file, $line)
 {
     $_key = md5($file . ':' . $line . ':' . $message);
     switch ($type) {
         case E_WARNING:
         case E_USER_WARNING:
             $this->warnings[$_key] = array($file . ':' . $line, $message, wp_debug_backtrace_summary(__CLASS__));
             break;
         case E_NOTICE:
         case E_USER_NOTICE:
             $this->notices[$_key] = array($file . ':' . $line, $message, wp_debug_backtrace_summary(__CLASS__));
             break;
         case E_STRICT:
             // TODO
             break;
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
             // TODO
             break;
         case 0:
             // TODO
             break;
     }
     if (null != $this->real_error_handler) {
         return call_user_func($this->real_error_handler, $type, $message, $file, $line);
     } else {
         return false;
     }
 }
 public function start($false, $args, $url)
 {
     $log = array('url' => $url, 'method' => !empty($args['method']) ? $args['method'] : '', 'start' => microtime(true), 'backtrace' => wp_debug_backtrace_summary(__CLASS__));
     if (isset($_GET['dbrr_full'])) {
         $log['args'] = $args;
     }
     $this->log[] = $log;
     return $false;
 }
Example #3
0
 static function log_error($message = '', $data = null)
 {
     $function = self::get_print_function();
     $error = array('message' => $message, 'data' => $data, 'backtrace' => function_exists('wp_debug_backtrace_summary') ? wp_debug_backtrace_summary(null, 3) : '');
     if (!in_array($error, self::$errors)) {
         self::$errors[] = $error;
     }
     if (class_exists("GFLogging")) {
         GFLogging::include_logger();
         GFLogging::log_message('gravityview', $function($message, true) . $function($data, true), KLogger::ERROR);
     }
 }
Example #4
0
 /**
  * Log
  * Writes to PHP error logs if DEBUG is enabled.
  *
  * @param  string $subject short title
  * @param  array  $data    data
  * @return null
  */
 public static function log($subject = '', $data = array())
 {
     if (self::DEBUG) {
         error_log('+++' . $subject . ' +++++++++++++++++++++');
         if (!empty($data)) {
             error_log(print_r($data, true));
             error_log('backtrace: ' . print_r(wp_debug_backtrace_summary(null, 0, false), true));
             error_log('--------------------- ' . $subject . ' END ---------------------');
         }
     }
     if (self::$record_logs) {
         if (function_exists('wp_get_current_user')) {
             self::record_log($subject, $data);
         } else {
             self::$recorded_logs[$subject] = $data;
         }
     }
 }
 /**
  * Used to suspend cache invalidation, if a term is being edited
  */
 public function edited_term_taxonomy_action($tt_id, $taxonomy)
 {
     global $wpdb, $_wp_suspend_cache_invalidation;
     $this->was_suspended = $_wp_suspend_cache_invalidation;
     // If cache is already disabled, then we don't need to do so again
     if ($this->was_suspended) {
         return;
     }
     $objects = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tt_id));
     //no action needed if there is less that $limimt number of objects to purge
     if (intval($objects) < $this->limit) {
         return;
     }
     // Make sure we're in `wp_update_term` - the only place we want this to happen
     $backtrace = wp_debug_backtrace_summary(null, null, false);
     if (!in_array('wp_update_term', $backtrace)) {
         return;
     }
     wp_suspend_cache_invalidation(true);
     //schedule WP Cron event for purging the cache
     wp_schedule_single_event(time(), 'wpcom_vip_clean_tax_relations_cache', array($tt_id, $taxonomy));
 }
Example #6
0
 /**
  * Retrieve the name of the function that called wpdb.
  *
  * Searches up the list of functions until it reaches
  * the one that would most logically had called this method.
  *
  * @since 2.5.0
  *
  * @return string|array The name of the calling function
  */
 public function get_caller()
 {
     return wp_debug_backtrace_summary(__CLASS__);
 }
 function log_http_request_result($response, $context, $transport, $args, $url)
 {
     if ('response' != $context) {
         return;
     }
     if (!isset($this->total_time)) {
         $this->total_time = 0;
     }
     // We don't have an easy way to match exact requests initiated with those completed since $args can be changed before it gets to us here
     if (isset($this->current_request['url']) && $url == $this->current_request['url']) {
         $time_elapsed = microtime(true) - $this->current_request['start'];
     } else {
         $time_elapsed = -1;
         // hm, some other request got in the way
     }
     // clear the values
     $this->current_request = array();
     if (!$response || is_wp_error($response)) {
         $message = is_wp_error($response) ? $response->get_error_message() : 'Something clearly went very wrong...';
         $status = 'fail';
     } else {
         $message = $response['response']['message'];
         $status = $response['response']['code'];
     }
     $this->requests[$url][] = array('message' => $message, 'status' => $status, 'time' => $time_elapsed, 'backtrace' => wp_debug_backtrace_summary());
     if (-1 < $time_elapsed) {
         $this->total_time += $time_elapsed;
     }
     // Prevent debug notice if no request counts exist yet
     if (empty($this->status_counts['Total Requests'])) {
         $this->status_counts['Total Requests'] = 0;
     }
     $this->status_counts['Total Requests']++;
     switch (substr($status, 0, 1)) {
         case 1:
             $this->status_counts['Informational (1xx)']++;
         case 2:
             $this->status_counts['Success (2xx)']++;
             break;
         case 3:
             $this->status_counts['Multiple Choices (3xx)']++;
             break;
         case 4:
             $this->status_counts['Client Error (4xx)']++;
             break;
         case 5:
             $this->status_counts['Server Error (5xx)']++;
             break;
         default:
             $this->status_counts['Unknown']++;
             break;
     }
 }
	function _nullify_current_user() {
		// Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog()
		$function_stack = wp_debug_backtrace_summary( null, 0, false );
		if ( in_array( 'restore_current_blog', $function_stack ) ) {
			return;
		}
		$GLOBALS['current_user'] = null;
	}
Example #9
0
 function wp_trim_words($text = '', $num_words = 110, $more = '', $original_text = '')
 {
     if ('characters' != _x('words', 'word count: words or characters?')) {
         return $text;
     }
     // If the caller is wp_dashboard_recent_drafts()
     if (false !== $this->conf['patch_dashboard_recent_drafts'] && 10 === $num_words && is_admin() && strpos(wp_debug_backtrace_summary(), 'wp_dashboard_recent_drafts')) {
         $num_words = $this->conf['dashboard_recent_drafts_mblength'];
     }
     $text = $original_text;
     $text = wp_strip_all_tags($text);
     $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');
     if (mb_strlen($text, $this->blog_encoding) > $num_words) {
         $text = mb_substr($text, 0, $num_words, $this->blog_encoding) . $more;
     }
     return $text;
 }
Example #10
0
 static function PrintDebugTrace($tag = "")
 {
     if (!empty($_GET['debug'])) {
         wpfb_loadclass('Output');
         $ms = self::GetMemStats();
         echo "<!-- [{$tag}] (MEM: " . WPFB_Output::FormatFilesize($ms['used']) . " / {$ms['limit']}) BACKTRACE:\n";
         echo esc_html(print_r(wp_debug_backtrace_summary(), true));
         echo "\nEND -->";
         self::UpdateMemBar();
     }
 }
 /**
  * Get the name of the function that called wpdb()
  *
  * @return string the name of the calling function
  */
 public function get_caller()
 {
     if (function_exists('wp_debug_backtrace_summary')) {
         return wp_debug_backtrace_summary(__CLASS__);
     }
     // requires PHP 4.3+
     if (!is_callable('debug_backtrace')) {
         return '';
     }
     $bt = debug_backtrace(false);
     $caller = '';
     foreach ((array) $bt as $trace) {
         if (isset($trace['class']) && is_a($this, $trace['class'])) {
             continue;
         } elseif (!isset($trace['function'])) {
             continue;
         } elseif (strtolower($trace['function']) === 'call_user_func_array') {
             continue;
         } elseif (strtolower($trace['function']) === 'apply_filters') {
             continue;
         } elseif (strtolower($trace['function']) === 'do_action') {
             continue;
         }
         if (isset($trace['class'])) {
             $caller = $trace['class'] . '::' . $trace['function'];
         } else {
             $caller = $trace['function'];
         }
         break;
     }
     return $caller;
 }
/**
 * Helper function for vip_contrib_add_upload_cap() to change the user roles
 *
 * @link http://vip.wordpress.com/documentation/allow-contributors-to-upload-images/ Allow Contributors to Upload Images
 * @see vip_contrib_add_upload_cap()
 */
function _vip_contrib_add_upload_cap()
{
    if (!is_admin() && !defined('XMLRPC_REQUEST')) {
        return;
    }
    if (function_exists('wpcom_vip_add_role_caps')) {
        wpcom_vip_add_role_caps('contributor', array('upload_files'));
    } else {
        // Temp debug to track down broken themes
        if (function_exists('send_vip_team_irc_alert')) {
            send_vip_team_irc_alert('[vip-helper fatal] ' . site_url() . ' add_role_cap no exist for _vip_contrib_add_upload_cap: ' . wp_debug_backtrace_summary());
        }
    }
}
Example #13
0
 public function test_print_log($message = '', $data = null)
 {
     $error = array('message' => $message, 'data' => $data, 'backtrace' => function_exists('wp_debug_backtrace_summary') ? wp_debug_backtrace_summary(null, 3) : '');
     fwrite(STDERR, print_r($error, true));
 }
 /**
  * @since 2.5.2
  */
 public function init()
 {
     /**
      * Fires before Simple History does it's init stuff
      *
      * @since 2.0
      *
      * @param SimpleHistory $SimpleHistory This class.
      */
     do_action("simple_history/before_init", $this);
     $this->setup_variables();
     // Actions and filters, ordered by order specified in codex: http://codex.wordpress.org/Plugin_API/Action_Reference
     add_action('after_setup_theme', array($this, 'load_plugin_textdomain'));
     add_action('after_setup_theme', array($this, 'add_default_settings_tabs'));
     // Plugins and dropins are loaded using the "after_setup_theme" filter so
     // themes can use filters to modify the loading of them.
     // The drawback with this is that for example logouts done when plugins like
     // iThemes Security is installed is not logged, because those plugins fire wp_logout()
     // using filter "plugins_loaded", i.e. before simple history has loaded its filters.
     add_action('after_setup_theme', array($this, 'load_loggers'));
     add_action('after_setup_theme', array($this, 'load_dropins'));
     // Run before loading of loggers and before menu items are added
     add_action('after_setup_theme', array($this, 'check_for_upgrade'), 5);
     add_action('after_setup_theme', array($this, 'setup_cron'));
     // Filters and actions not called during regular boot
     add_filter("gettext", array($this, 'filter_gettext'), 20, 3);
     add_filter("gettext_with_context", array($this, 'filter_gettext_with_context'), 20, 4);
     add_filter('gettext', array($this, "filter_gettext_storeLatestTranslations"), 10, 3);
     add_action('admin_bar_menu', array($this, 'add_admin_bar_network_menu_item'), 40);
     add_action('admin_bar_menu', array($this, 'add_admin_bar_menu_item'), 40);
     /**
      * Filter that is used to log things, without the need to check that simple history is available
      * i.e. you can have simple history acivated and log things and then you can disable the plugin
      * and no errors will occur
      *
      * Usage:
      * apply_filters("simple_history_log", "This is the log message");
      * apply_filters("simple_history_log", "This is the log message with some extra data/info", ["extraThing1" => $variableWIihThing]);
      * apply_filters("simple_history_log", "This is the log message with severity debug", null, "debug");
      * apply_filters("simple_history_log", "This is the log message with severity debug and with some extra info/data logged", ["userData" => $userData, "shoppingCartDebugData" => $shopDebugData], "debug",);
      *
      * @since 2.13
      */
     add_filter('simple_history_log', array($this, "on_filter_simple_history_log"), 10, 3);
     if (is_admin()) {
         $this->add_admin_actions();
     }
     /**
      * Fires after Simple History has done it's init stuff
      *
      * @since 2.0
      *
      * @param SimpleHistory $SimpleHistory This class.
      */
     do_action("simple_history/after_init", $this);
     // Add some extra info to each logged context when SIMPLE_HISTORY_LOG_DEBUG is set and true
     if (defined("SIMPLE_HISTORY_LOG_DEBUG") && SIMPLE_HISTORY_LOG_DEBUG) {
         add_filter("simple_history/log_argument/context", function ($context, $level, $message, $logger) {
             $sh = SimpleHistory::get_instance();
             $context["_debug_get"] = $sh->json_encode($_GET);
             $context["_debug_post"] = $sh->json_encode($_POST);
             $context["_debug_server"] = $sh->json_encode($_SERVER);
             $context["_debug_files"] = $sh->json_encode($_FILES);
             $context["_debug_php_sapi_name"] = php_sapi_name();
             global $argv;
             $context["_debug_argv"] = $sh->json_encode($argv);
             $consts = get_defined_constants(true);
             $consts = $consts["user"];
             $context["_debug_user_constants"] = $sh->json_encode($consts);
             $postdata = file_get_contents("php://input");
             $context["_debug_http_raw_post_data"] = $sh->json_encode($postdata);
             $context["_debug_wp_debug_backtrace_summary"] = wp_debug_backtrace_summary();
             $context["_debug_is_admin"] = json_encode(is_admin());
             $context["_debug_is_doing_cron"] = json_encode(defined('DOING_CRON') && DOING_CRON);
             return $context;
         }, 10, 4);
     }
 }
 /**
  * Wrapper around esc_html__
  * @param  string $string
  * @return
  */
 public static function esc_html_e($string)
 {
     if (self::DEBUG) {
         error_log('backtrace: ' . print_r(wp_debug_backtrace_summary(null, 0, false), true));
         _deprecated_function(__CLASS__ . '::' . __FUNCTION__, '9.0', '__');
     }
     return esc_html_e($string, self::TEXT_DOMAIN);
 }
 function deprecated_argument_run($function, $message, $version)
 {
     $backtrace = debug_backtrace(false);
     if ($function === 'define()') {
         $this->deprecated_functions[] = array($message, '');
         return;
     }
     $bt = 4;
     if (!isset($backtrace[4]['file']) && 'call_user_func_array' == $backtrace[5]['function']) {
         $bt = 6;
     }
     $file = $backtrace[$bt]['file'];
     $line = $backtrace[$bt]['line'];
     $this->deprecated_functions[$file . ':' . $line] = array($message, wp_debug_backtrace_summary(null, $bt));
 }
 function wpbt()
 {
     error_log('backtrace: ' . print_r(wp_debug_backtrace_summary(null, 0, false), true));
 }
 /**
  * Determine if current request is a call to `wp_unschedule_event()`
  */
 private function is_unscheduling()
 {
     return false !== array_search('wp_unschedule_event', wp_debug_backtrace_summary(__CLASS__, null, false));
 }
Example #19
0
 public function backtrace()
 {
     $version = get_bloginfo('version');
     if ($version >= 3.4) {
         $debug = '<h3>' . __('Backtrace Summary', 'debug-this') . '</h3>';
         $debug .= print_r(explode(', ', wp_debug_backtrace_summary()), true);
     }
     $debug .= '<h3>' . __('debug_backtrace()', 'debug-this') . '</h3>';
     $debug .= htmlentities(print_r(debug_backtrace(), true));
     return $debug;
 }