Automattic\WooCommerce\Internal\Admin\Logging

LogHandlerFileV2::determine_source()protectedWC 1.0

Figures out a source string to use for a log entry based on where the log method was called from.

Метод класса: LogHandlerFileV2{}

Хуков нет.

Возвращает

Строку.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->determine_source(): string;

Код LogHandlerFileV2::determine_source() WC 9.5.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 );
}