Skip to content

Commit c920d31

Browse files
committed
update
1 parent dfcd64e commit c920d31

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

functions.php

+46
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,52 @@ function wpdb_bulk_insert($table, $rows) {
665665
return $wpdb->query($wpdb->prepare($sql, $data));
666666
}
667667
}
668+
669+
if (!function_exists('mxp_get_error_backtrace')) {
670+
// WordPress PHP 偵錯用的方法
671+
function mxp_get_error_backtrace($last_error_file = __FILE__, $for_irc = false) {
672+
673+
$backtrace = debug_backtrace(0);
674+
$call_path = array();
675+
foreach ($backtrace as $bt_key => $call) {
676+
if (!isset($call['args'])) {
677+
$call['args'] = array('');
678+
}
679+
680+
if (in_array($call['function'], array(__FUNCTION__, 'mxp_get_error_backtrace'))) {
681+
continue;
682+
}
683+
684+
$path = '';
685+
if (!$for_irc) {
686+
$path = isset($call['file']) ? str_replace(ABSPATH, '', $call['file']) : '';
687+
$path .= isset($call['line']) ? ':' . $call['line'] : '';
688+
}
689+
690+
if (isset($call['class'])) {
691+
$call_type = $call['type'] ? $call['type'] : '???';
692+
$path .= " {$call['class']}{$call_type}{$call['function']}()";
693+
} elseif (in_array($call['function'], array('do_action', 'apply_filters'))) {
694+
if (is_object($call['args'][0]) && !method_exists($call['args'][0], '__toString')) {
695+
$path .= " {$call['function']}(Object)";
696+
} elseif (is_array($call['args'][0])) {
697+
$path .= " {$call['function']}(Array)";
698+
} else {
699+
$path .= " {$call['function']}('{$call['args'][0]}')";
700+
}
701+
} elseif (in_array($call['function'], array('include', 'include_once', 'require', 'require_once'))) {
702+
$file = 0 == $bt_key ? $last_error_file : $call['args'][0];
703+
$path .= " {$call['function']}('" . str_replace(ABSPATH, '', $file) . "')";
704+
} else {
705+
$path .= " {$call['function']}()";
706+
}
707+
708+
$call_path[] = trim($path);
709+
}
710+
711+
return implode(', ' . PHP_EOL, $call_path);
712+
}
713+
}
668714
// 關閉後臺的「網站活動」區塊
669715
function mxp_remove_dashboard_widgets() {
670716
remove_meta_box('dashboard_activity', 'dashboard', 'normal');

0 commit comments

Comments
 (0)