WC_Log_Handler_DB::get_log_source()protected staticWC 1.0

Get appropriate source based on file name.

Try to provide an appropriate source in case none is provided.

Method of the class: WC_Log_Handler_DB{}

No Hooks.

Return

String. Text to use as log source. "" (empty string) if none is found.

Usage

$result = WC_Log_Handler_DB::get_log_source();

WC_Log_Handler_DB::get_log_source() code WC 8.6.1

protected static function get_log_source() {
	static $ignore_files = array( 'class-wc-log-handler-db', 'class-wc-logger' );

	/**
	 * PHP < 5.3.6 correct behavior
	 *
	 * @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters
	 */
	if ( Constants::is_defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) {
		$debug_backtrace_arg = DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:ignore PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound
	} else {
		$debug_backtrace_arg = false;
	}

	$trace = debug_backtrace( $debug_backtrace_arg ); // @codingStandardsIgnoreLine.
	foreach ( $trace as $t ) {
		if ( isset( $t['file'] ) ) {
			$filename = pathinfo( $t['file'], PATHINFO_FILENAME );
			if ( ! in_array( $filename, $ignore_files, true ) ) {
				return $filename;
			}
		}
	}

	return '';
}