PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | app/Notifications/Triggers.php +30 -0 3.2.03.2.1 View file →
@@ -4,8 +4,10 @@
4 4
5 5 defined('ABSPATH') || die('No direct access.');
6 6
7 7 use Extendify\PartnerData;
8 +use Extendify\SiteVisibility;
9 +use Extendify\SiteSettings;
8 10
9 11 /**
10 12 * The site conditions a notification can ask to be gated on, each mapped to the
11 13 * predicate that answers it. A notification without a trigger is unconditional.
@@ -14,10 +16,15 @@
14 16 {
15 17 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility
16 18 const PREDICATES = [
17 19 'trial-domain' => 'onTrialDomain',
20 + 'unpublished' => 'siteUnpublished',
21 + 'trial-block' => 'onExpiredTrialDomain',
18 22 ];
19 23
24 + // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility
25 + const TRIAL_WINDOW_DAYS = 16;
26 +
20 27 public static function passes($trigger)
21 28 {
22 29 if ($trigger === null || $trigger === '') {
23 30 return true;
@@ -29,8 +36,13 @@
29 36
30 37 return call_user_func([self::class, self::PREDICATES[$trigger]]);
31 38 }
32 39
40 + private static function siteUnpublished()
41 + {
42 + return !SiteVisibility::isPublished();
43 + }
44 +
33 45 // Substring match, mirroring the domain-suggestion matcher in src/Assist/lib/domains.js.
34 46 private static function onTrialDomain()
35 47 {
36 48 $host = strtolower((string) \wp_parse_url(\home_url(), PHP_URL_HOST));
@@ -43,6 +55,24 @@
43 55 }
44 56 }
45 57
46 58 return false;
59 + }
60 +
61 + private static function onExpiredTrialDomain()
62 + {
63 + return self::onTrialDomain() && self::olderThanTrialWindow();
64 + }
65 +
66 + private static function olderThanTrialWindow()
67 + {
68 + $createdAt = SiteSettings::getSiteCreatedAt();
69 + $createdAt = $createdAt === null ? false : strtotime($createdAt);
70 +
71 + // A zero MySQL date parses to a negative timestamp, not false, and must not block.
72 + if ($createdAt === false || $createdAt <= 0) {
73 + return false;
74 + }
75 +
76 + return $createdAt <= (time() - (self::TRIAL_WINDOW_DAYS * DAY_IN_SECONDS));
47 77 }
48 78 }