Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
- Add function blacklist for TLD
  • Loading branch information
UVLabs authored Jun 30, 2023
2 parents dc14d61 + 8a00741 commit defb764
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
68 changes: 66 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '';

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

0 comments on commit defb764

Please sign in to comment.