PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
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 0.7.0 All 126 releases
extendify / app / Notifications / Triggers.php

Triggers.php in Extendify 3.1.5, at app/Notifications/Triggers.php

49 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Extendify\Notifications;
4
5 defined('ABSPATH') || die('No direct access.');
6
7 use Extendify\PartnerData;
8
9 /**
10 * The site conditions a notification can ask to be gated on, each mapped to the
11 * predicate that answers it. A notification without a trigger is unconditional.
12 */
13 class Triggers
14 {
15 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility
16 const PREDICATES = [
17 'staging-domain' => 'onStagingDomain',
18 ];
19
20 public static function passes($trigger)
21 {
22 if ($trigger === null || $trigger === '') {
23 return true;
24 }
25
26 if (!is_string($trigger) || !isset(self::PREDICATES[$trigger])) {
27 return false;
28 }
29
30 return call_user_func([self::class, self::PREDICATES[$trigger]]);
31 }
32
33 // Substring match, mirroring the domain-suggestion matcher in src/Assist/lib/domains.js.
34 private static function onStagingDomain()
35 {
36 $host = strtolower((string) \wp_parse_url(\home_url(), PHP_URL_HOST));
37 $sites = (array) PartnerData::setting('stagingSites');
38
39 foreach (array_filter($sites, 'is_string') as $site) {
40 $site = strtolower(trim($site));
41 if ($site !== '' && str_contains($host, $site)) {
42 return true;
43 }
44 }
45
46 return false;
47 }
48 }
49