wizard
4 days ago
class-addons-template-util.php
4 days ago
class-allowed-template-html-util.php
4 days ago
class-base-exception.php
4 days ago
class-cache-constants.php
4 days ago
class-cache-exception.php
4 days ago
class-engagement.php
4 days ago
class-key-exception.php
4 days ago
class-keytypes.php
4 days ago
class-option-exception.php
4 days ago
class-quiet-skin.php
4 days ago
class-request-exception.php
4 days ago
class-script-translations.php
4 days ago
class-settings-exception.php
4 days ago
class-theme-installer-exception.php
4 days ago
class-theme-installer.php
4 days ago
class-third-party-compatibility-util.php
4 days ago
class-engagement.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Data\Utils; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | /** |
| 8 | * Centralized, per-site engagement marker. |
| 9 | * |
| 10 | * Records the first time each meaningful "used the product" action occurs so |
| 11 | * features like the review prompt can gate on whether the site has actually |
| 12 | * engaged with the plugin. Each feature is written at most once (the first time |
| 13 | * it is used), so repeat calls cost a single cached option read and never write. |
| 14 | */ |
| 15 | class Engagement |
| 16 | { |
| 17 | const OPTION_KEY = 'superbaddons_engagement'; |
| 18 | |
| 19 | const FEATURE_PATTERN = 'pattern'; |
| 20 | const FEATURE_FORM = 'form'; |
| 21 | const FEATURE_POPUP = 'popup'; |
| 22 | const FEATURE_DESIGNER = 'designer'; |
| 23 | const FEATURE_CSS = 'css'; |
| 24 | const FEATURE_ENHANCEMENT = 'enhancement'; |
| 25 | |
| 26 | /** |
| 27 | * Record that a feature has been used. Writes only on the first use of each |
| 28 | * feature, so subsequent calls are a no-op after a single option read. |
| 29 | * |
| 30 | * @param string $feature One of the FEATURE_* constants. |
| 31 | * @return void |
| 32 | */ |
| 33 | public static function MarkUsed($feature) |
| 34 | { |
| 35 | if (empty($feature)) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $engagement = get_option(self::OPTION_KEY, array()); |
| 40 | if (!is_array($engagement)) { |
| 41 | $engagement = array(); |
| 42 | } |
| 43 | |
| 44 | // Already recorded — nothing to write. |
| 45 | if (isset($engagement[$feature])) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | $engagement[$feature] = time(); |
| 50 | update_option(self::OPTION_KEY, $engagement, false); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Whether the site has engaged with at least one plugin feature. |
| 55 | * |
| 56 | * @return bool |
| 57 | */ |
| 58 | public static function HasEngaged() |
| 59 | { |
| 60 | $engagement = get_option(self::OPTION_KEY, array()); |
| 61 | return is_array($engagement) && !empty($engagement); |
| 62 | } |
| 63 | } |
| 64 |