Track.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Tracking\Helpers; |
| 4 | |
| 5 | use Give\Tracking\Repositories\Settings; |
| 6 | |
| 7 | /** |
| 8 | * Class Track |
| 9 | * |
| 10 | * This class contains helpers functions related to tracks |
| 11 | * |
| 12 | * @package Give\Tracking\Helpers |
| 13 | * @since 2.10.0 |
| 14 | */ |
| 15 | class Track |
| 16 | { |
| 17 | /** |
| 18 | * Return whether or not admin opted in for usage tracking. |
| 19 | * |
| 20 | * @since 2.10.0 |
| 21 | * |
| 22 | * @return bool True when we can track, false when we can't. |
| 23 | */ |
| 24 | public static function isTrackingEnabled() |
| 25 | { |
| 26 | if ( ! self::checkEnvironment()) { |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | // Check if we're allowing tracking. |
| 31 | /* @var Settings $settings */ |
| 32 | $settings = give(Settings::class); |
| 33 | $tracking = $settings->getUsageTrackingOptionValue(); |
| 34 | |
| 35 | return give_is_setting_enabled($tracking); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Return whether or not environment for tracking satisfied. |
| 40 | * |
| 41 | * @return bool |
| 42 | */ |
| 43 | public static function checkEnvironment() |
| 44 | { |
| 45 | // Track data only if website is in production mode. |
| 46 | if (function_exists('wp_get_environment_type') && wp_get_environment_type() !== 'production') { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | // Track data only if give is in live mode. |
| 51 | if (give_is_setting_enabled(give_get_option('test_mode'))) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 |