Skip to content

Instantly share code, notes, and snippets.

@rilwis
Created December 19, 2024 02:17
Show Gist options
  • Save rilwis/fbd5e24297e5b7a5007f0c74e27214d1 to your computer and use it in GitHub Desktop.
Save rilwis/fbd5e24297e5b7a5007f0c74e27214d1 to your computer and use it in GitHub Desktop.
Detecting dev or staging domains
<?php
public static function is_dev_domain( string $domain ): bool {
$prefixes = [
'test.',
'dev.',
'demo.',
'staging.',
];
$suffixes = [
'.test',
'.local',
'.docksal',
'.docksal.site',
'.dev.cc',
'.lndo.site',
'.kinsta.com',
'.kinsta.cloud',
'.instawp.xyz',
'.instawp.co',
'.wpengine.com',
'.wpenginepowered.com',
'.cloudwaysapps.com',
'.pantheonsite.io',
// nexcess.net & liquidweb.
'.nxcli.net',
'.nxcli.io',
'-liquidwebsites.com',
'.onyx-sites.io',
'.wpstage.net',
'.wpdns.site',
'.flywheelsites.com',
'.flywheelstaging.com',
'.azurewebsites.net',
'.wpserveur.net',
'.myftpupload.com',
'.dream.press',
'.sg-host.com',
'.platformsh.site',
'.bigscoots-staging.com',
'.wpsc.site',
'.runcloud.link',
'.onrocket.site',
'.singlestaging.com',
'.myraidbox.de',
'.dev.onpressidium.com',
'.temp-site.link',
];
$patterns = [
'.staging.',
];
if ( in_array( $domain, [ 'localhost', '127.0.0.1' ], true ) ) {
return true;
}
foreach ( $prefixes as $prefix ) {
if ( str_starts_with( $domain, $prefix ) ) {
return true;
}
}
foreach ( $suffixes as $suffix ) {
if ( str_ends_with( $domain, $suffix ) ) {
return true;
}
}
foreach ( $patterns as $pattern ) {
if ( str_contains( $domain, $pattern ) ) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment