Automattic\WooCommerce\Internal\Admin\Settings

Utils::normalize_plugin_slugpublic staticWC 1.0

Normalize a plugin slug to a standard/official slug.

This is a best-effort approach. It will remove beta testing suffixes and lowercase the slug. It will NOT convert plugin titles to slugs or sanitize the slug like sanitize_title() does.

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

Хуков нет.

Возвращает

Строку. The normalized plugin slug.

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

$result = Utils::normalize_plugin_slug( $slug ): string;
$slug(строка) (обязательный)
The plugin slug.

Код Utils::normalize_plugin_slug() WC 10.3.4

public static function normalize_plugin_slug( string $slug ): string {
	// If the slug is empty or contains anything other than alphanumeric and dash characters, it will be left as is.
	if ( empty( $slug ) || ! preg_match( '/^[\w-]+$/', $slug, $matches ) ) {
		return $slug;
	}

	// Lowercase the slug.
	$slug = strtolower( $slug );
	// Remove testing suffixes.
	foreach ( self::get_testing_plugin_slug_suffixes() as $suffix ) {
		$slug = str_ends_with( $slug, $suffix ) ? substr( $slug, 0, -strlen( $suffix ) ) : $slug;
	}

	return $slug;
}