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