CheckOfferStatus.php
4 years ago
CompleteRestApiEndpoint.php
4 years ago
DisplaySettingsButton.php
4 years ago
EnqueueModal.php
4 years ago
PreventFreshInstallPromotion.php
4 years ago
CheckOfferStatus.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Promotions\FreeAddonModal\Controllers; |
| 4 | |
| 5 | trait CheckOfferStatus |
| 6 | { |
| 7 | /** |
| 8 | * Whether the modal should be displayed. |
| 9 | * |
| 10 | * @return bool |
| 11 | */ |
| 12 | protected function displayModal() |
| 13 | { |
| 14 | if (!$this->displayOffer()) { |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | // Only display if the user did not dismiss or subscribe |
| 19 | $status = get_option('give_free_addon_modal_displayed'); |
| 20 | |
| 21 | if (empty($status)) { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | // The value will be something like rejected:1:1.18.0. The first number is the number of versions the modal has appeared |
| 26 | // in, and the second number is the version number of the plugin at the time of last display. |
| 27 | list($status, $iteration, $version) = explode(':', $status); |
| 28 | |
| 29 | if ($status === 'subscribed') { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // Do not display if this has been displayed more than three times |
| 34 | if ($iteration >= 3) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | // Display if the version has changed since the last display |
| 39 | return GIVE_VERSION !== $version; |
| 40 | } |
| 41 | |
| 42 | protected function displayOffer() |
| 43 | { |
| 44 | // Only display the modal if the user is an admin |
| 45 | if (!current_user_can('manage_options')) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | $licenses = get_option('give_licenses'); |
| 50 | if (!empty($licenses)) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | // Only display if the user did not dismiss or subscribe |
| 55 | $status = get_option('give_free_addon_modal_displayed'); |
| 56 | |
| 57 | if (empty($status)) { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | // The value will be something like rejected:1:1.18.0. The first number is the number of versions the modal has appeared |
| 62 | // in, and the second number is the version number of the plugin at the time of last display. |
| 63 | list($status, $iteration, $version) = explode(':', $status); |
| 64 | |
| 65 | return !in_array($status, ['subscribed', 'prevent'], true); |
| 66 | } |
| 67 | } |
| 68 |