From d26137fe1db88761bbe20754966cb12ad1f3bd22 Mon Sep 17 00:00:00 2001 From: UVLabs Date: Fri, 30 Jun 2023 19:08:39 -0400 Subject: [PATCH 1/3] chore: bail if TLD is in excluded list --- index.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 3578305..d4bb9ba 100644 --- a/index.php +++ b/index.php @@ -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); @@ -235,6 +244,57 @@ function contactTags(): array function excludedEmails(): array { return array( - 'plugins@soaringleads.com', + // 'plugins@soaringleads.com', + ); +} + +/** + * 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', ); } + +/** + * 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); +} From 70cbaa0259a91da82d1feac782256de29a2e9bc1 Mon Sep 17 00:00:00 2001 From: UVLabs Date: Fri, 30 Jun 2023 19:12:35 -0400 Subject: [PATCH 2/3] chore: add more blacklisted domains --- index.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.php b/index.php index d4bb9ba..f6124c1 100644 --- a/index.php +++ b/index.php @@ -279,6 +279,10 @@ function excludedTLDs(): array 'wpmudev.host', 'websitepro-staging.com', 'websitepro.hosting', + 'wpengine.com', + 'pantheonsite.io', + 'kinsta.com', + 'kinsta.cloud' ); } From 8a00741da93f3053739ac57d700854ded6da9f77 Mon Sep 17 00:00:00 2001 From: UVLabs Date: Fri, 30 Jun 2023 19:20:46 -0400 Subject: [PATCH 3/3] chore: new version --- README.md | 2 ++ index.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 889f28b..3c1020c 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ The following functions inside `index.php` should be edited to match your plugin - customContactDataMappings() - contactSegments() - contactTags() +- excludedTLDs() +- isExcludedTLD() Comments have been added to help explain how these functions should be edited. If comments can be made better then feel free to submit a pull request! diff --git a/index.php b/index.php index f6124c1..ddd2cff 100644 --- a/index.php +++ b/index.php @@ -244,7 +244,7 @@ function contactTags(): array function excludedEmails(): array { return array( - // 'plugins@soaringleads.com', + 'plugins@soaringleads.com', ); }