Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

PaymentGateway::extract_slug_from_pathprivateWC 1.0

Extract the slug from a given path.

It can be a directory or file path. This should be a relative path since the top-level directory or file name will be used as the slug.

Method of the class: PaymentGateway{}

No Hooks.

Returns

String. The slug extracted from the path.

Usage

// private - for code of main (parent) class only
$result = $this->extract_slug_from_path( $path ): string;
$path(string) (required)
The path to extract the slug from.

PaymentGateway::extract_slug_from_path() code WC 10.8.1

private function extract_slug_from_path( string $path ): string {
	$path = trim( $path );
	$path = trim( $path, DIRECTORY_SEPARATOR );

	// If the path is just a file name, use it as the slug.
	if ( false === strpos( $path, DIRECTORY_SEPARATOR ) ) {
		return Utils::trim_php_file_extension( $path );
	}

	$parts = explode( DIRECTORY_SEPARATOR, $path );
	// Bail if we couldn't get the parts.
	if ( ! is_array( $parts ) ) {
		return '';
	}

	return reset( $parts );
}