-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add function blacklist for TLD
- Loading branch information
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,8 @@ function init(ServerRequestInterface $request): string | |
return 'no user data'; | ||
} | ||
|
||
$user_data['is_premium'] = $body['objects']['install']['is_premium'] ?? false; // Using this to decide how to tag contacts. | ||
$install = $body['objects']['install'] ?? array(); | ||
$user_data['is_premium'] = $install['is_premium'] ?? false; // Using this to decide how to tag contacts. | ||
|
||
$plugin_id = $body['plugin_id'] ?? ''; | ||
|
||
|
@@ -55,7 +56,15 @@ function init(ServerRequestInterface $request): string | |
*/ | ||
$user_email = $user_data['email'] ?? ''; | ||
if (in_array($user_email, excludedEmails()) || empty($user_email)) { | ||
return 'excluded'; | ||
return 'excluded email'; | ||
} | ||
|
||
/** | ||
* Bail if TLD is excluded. | ||
*/ | ||
$domain = $install['url'] ?? ''; | ||
if (isExcludedTLD($domain)) { | ||
return "development domain"; | ||
} | ||
|
||
$contactCreate = new CreateContact($plugin_id); | ||
|
@@ -238,3 +247,58 @@ function excludedEmails(): array | |
'[email protected]', | ||
); | ||
} | ||
|
||
/** | ||
* List of excluded domains. | ||
* | ||
* Sites with these domains should not be processed. These are typically development sites so we shouldn't be updating | ||
* user tags or processing those webhooks. | ||
* | ||
* @return array | ||
* @since 1.1.1 | ||
*/ | ||
function excludedTLDs(): array | ||
{ | ||
return array( | ||
'local', | ||
'dev', | ||
'instawp.xyz', | ||
'instawp.co', | ||
'instawp.link', | ||
'dev.cc', | ||
'test', | ||
'staging', | ||
'example', | ||
'invalid', | ||
'myftpupload.com', | ||
'cloudwaysapps.com', | ||
'wpsandbox.pro', | ||
'ngrok.io', | ||
'mystagingwebsite.com', | ||
'tempurl.host', | ||
'wpmudev.host', | ||
'websitepro-staging.com', | ||
'websitepro.hosting', | ||
'wpengine.com', | ||
'pantheonsite.io', | ||
'kinsta.com', | ||
'kinsta.cloud' | ||
); | ||
} | ||
|
||
/** | ||
* Check if a TLD is excluded. | ||
* | ||
* @param string $url | ||
* @return bool | ||
* @since 1.1.1 | ||
*/ | ||
function isExcludedTLD(string $url): bool | ||
{ | ||
$excluded_tlds = excludedTLDs(); | ||
|
||
$parts = explode('.', $url, 2); | ||
$tld = $parts[1] ?? array(); | ||
|
||
return in_array($tld, $excluded_tlds, true); | ||
} |