Implemented includes shortening in backtrace.
This commit is contained in:
1 parent
30db67c055
commit
1e3195ffc8
1 file changed
+40
-2
@@ -13,12 +13,30 @@ class Backtrace_Formatter {
|
||||
'wp-load.php',
|
||||
'wp-config.php',
|
||||
'admin.php',
|
||||
'template-loader.php',
|
||||
'locate_template',
|
||||
'load_template',
|
||||
'_wp_get_current_user',
|
||||
'WP_Hook',
|
||||
];
|
||||
|
||||
/** @var array $truncate_paths Paths to truncate from includes. */
|
||||
protected $truncate_paths = [];
|
||||
|
||||
/**
|
||||
* Set up object properties.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->truncate_paths = [
|
||||
wp_normalize_path( ABSPATH ),
|
||||
wp_normalize_path( WP_CONTENT_DIR ),
|
||||
'wp-admin/',
|
||||
'themes/',
|
||||
'plugins/',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $backtrace Backtrace input as produced by WP.
|
||||
*
|
||||
@@ -30,9 +48,10 @@ class Backtrace_Formatter {
|
||||
$backtrace = explode( ', ', $backtrace );
|
||||
}
|
||||
|
||||
// TODO shorten includes.
|
||||
|
||||
$backtrace = array_filter( $backtrace, [ $this, 'filter' ] );
|
||||
$backtrace = array_map( [ $this, 'shorten_include' ], $backtrace );
|
||||
|
||||
// TODO compact redunant function sequences, such as transient into option calls.
|
||||
|
||||
return $backtrace;
|
||||
}
|
||||
@@ -52,4 +71,23 @@ class Backtrace_Formatter {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $item Backtrace item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function shorten_include( $item ) {
|
||||
|
||||
if ( 0 === strpos( $item, 'include' ) || 0 === strpos( $item, 'require' ) ) {
|
||||
|
||||
$path = substr( $item, strpos( $item, '(\'' ) + 2, - 2 );
|
||||
$path = wp_normalize_path( $path );
|
||||
$path = ltrim( str_replace( $this->truncate_paths, '', $path ), '/' );
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user