Automattic\WooCommerce\Internal\Admin\Logging

Settings::get_log_directory()public staticWC 1.0

Get the directory for storing log files.

The wp_upload_dir function takes into account the possibility of multisite, and handles changing the directory if the context is switched to a different site in the network mid-request.

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

Хуки из метода

Возвращает

Строку. The full directory path, with trailing slash.

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

$result = Settings::get_log_directory( $create_dir ): string;
$create_dir(true|false)
True to attempt to create the log directory if it doesn't exist.
По умолчанию: true

Код Settings::get_log_directory() WC 9.7.1

public static function get_log_directory( bool $create_dir = true ): string {
	if ( true === Constants::get_constant( 'WC_LOG_DIR_CUSTOM' ) ) {
		$dir = Constants::get_constant( 'WC_LOG_DIR' );
	} else {
		$upload_dir = wc_get_container()->get( LegacyProxy::class )->call_function( 'wp_upload_dir', null, $create_dir );

		/**
		 * Filter to change the directory for storing WooCommerce's log files.
		 *
		 * @param string $dir The full directory path, with trailing slash.
		 *
		 * @since 8.8.0
		 */
		$dir = apply_filters( 'woocommerce_log_directory', $upload_dir['basedir'] . '/wc-logs/' );
	}

	$dir = trailingslashit( $dir );

	if ( true === $create_dir ) {
		$realpath = realpath( $dir );
		if ( false === $realpath ) {
			$result = wp_mkdir_p( $dir );

			if ( true === $result ) {
				// Create infrastructure to prevent listing contents of the logs directory.
				try {
					$filesystem = FilesystemUtil::get_wp_filesystem();
					$filesystem->put_contents( $dir . '.htaccess', 'deny from all' );
					$filesystem->put_contents( $dir . 'index.html', '' );
				} catch ( Exception $exception ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
					// Creation failed.
				}
			}
		}
	}

	return $dir;
}