Automattic\WooCommerce\Internal\Admin\Settings
Utils::normalize_plugin_slug
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.
Method of the class: Utils{}
No Hooks.
Returns
String. The normalized plugin slug.
Usage
$result = Utils::normalize_plugin_slug( $slug ): string;
- $slug(string) (required)
- The plugin slug.
Utils::normalize_plugin_slug() Utils::normalize plugin slug code WC 10.6.2
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;
}