Automattic\WooCommerce\Internal\Admin\Logging
LogHandlerFileV2::determine_source
Figures out a source string to use for a log entry based on where the log method was called from.
Method of the class: LogHandlerFileV2{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->determine_source(): string;
LogHandlerFileV2::determine_source() LogHandlerFileV2::determine source code WC 10.8.1
protected function determine_source(): string {
$source_roots = array(
'mu-plugin' => trailingslashit( Constants::get_constant( 'WPMU_PLUGIN_DIR' ) ),
'plugin' => trailingslashit( Constants::get_constant( 'WP_PLUGIN_DIR' ) ),
'theme' => trailingslashit( get_theme_root() ),
);
$source = '';
$backtrace = static::get_backtrace();
foreach ( $backtrace as $frame ) {
if ( ! isset( $frame['file'] ) ) {
continue;
}
foreach ( $source_roots as $type => $path ) {
if ( 0 === strpos( $frame['file'], $path ) ) {
$relative_path = trim( substr( $frame['file'], strlen( $path ) ), DIRECTORY_SEPARATOR );
if ( 'mu-plugin' === $type ) {
$info = pathinfo( $relative_path );
if ( '.' === $info['dirname'] ) {
$source = "$type-" . $info['filename'];
} else {
$source = "$type-" . $info['dirname'];
}
break 2;
}
$segments = explode( DIRECTORY_SEPARATOR, $relative_path );
if ( is_array( $segments ) ) {
$source = "$type-" . reset( $segments );
}
break 2;
}
}
}
if ( ! $source ) {
$source = 'log';
}
return sanitize_title( $source );
}