wp_debug_backtrace_summary

函数
wp_debug_backtrace_summary ( $ignore_class = null, $skip_frames = 0, $pretty = true )
参数
  • (string) $ignore_class Optional. A class to ignore all function calls within - useful when you want to just give info about the callee. Default null.
    Required:
    Default: null
  • (int) $skip_frames Optional. A number of stack frames to skip - useful for unwinding back to the source of the issue. Default 0.
    Required:
  • (bool) $pretty Optional. Whether you want a comma separated string instead of the raw array returned. Default true.
    Required:
    Default: true
返回值
  • (string|array) Either a string containing a reversed comma separated trace or an array of individual calls.
相关
  • https://core.trac.wordpress.org/ticket/19589
定义位置
相关方法
wp_default_packageswp_default_packages_scriptswp_default_packages_vendorwp_extract_urlswpmu_activate_signup
引入
3.4.0
弃用
-

wp_debug_backtrace_summary:此函数用于显示调试回溯信息的摘要。它可以用来帮助调试站点的问题。

返回一个以逗号分隔的字符串或函数数组,这些函数已经被调用以达到代码中的当前点。

function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
	static $truncate_paths;

	$trace       = debug_backtrace( false );
	$caller      = array();
	$check_class = ! is_null( $ignore_class );
	$skip_frames++; // Skip this function.

	if ( ! isset( $truncate_paths ) ) {
		$truncate_paths = array(
			wp_normalize_path( WP_CONTENT_DIR ),
			wp_normalize_path( ABSPATH ),
		);
	}

	foreach ( $trace as $call ) {
		if ( $skip_frames > 0 ) {
			$skip_frames--;
		} elseif ( isset( $call['class'] ) ) {
			if ( $check_class && $ignore_class == $call['class'] ) {
				continue; // Filter out calls.
			}

			$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
		} else {
			if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ), true ) ) {
				$caller[] = "{$call['function']}('{$call['args'][0]}')";
			} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
				$filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
				$caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
			} else {
				$caller[] = $call['function'];
			}
		}
	}
	if ( $pretty ) {
		return implode( ', ', array_reverse( $caller ) );
	} else {
		return $caller;
	}
}

常见问题

FAQs
查看更多 >