RatingNotice.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Basic\Notices; |
| 4 | |
| 5 | use DateTime; |
| 6 | |
| 7 | class RatingNotice |
| 8 | { |
| 9 | /** @var string */ |
| 10 | const OPTION_NAME = 'wpstg_rating'; |
| 11 | |
| 12 | /** |
| 13 | * Shared eligibility gate for the success-based review prompt, used by both |
| 14 | * the staging and backup completion modals (views/notices/review-prompt-modal.php). |
| 15 | * |
| 16 | * It only answers "is the user currently allowed to be asked?", i.e. the |
| 17 | * review prompt has not been permanently dismissed and is not inside a snooze |
| 18 | * window. The "value delivered" trigger (a staging site or backup was just |
| 19 | * created) is the caller's responsibility — the prompt is rendered into the |
| 20 | * success modal, never as loose dashboard text. |
| 21 | * |
| 22 | * Because every surface reads and writes the same wpstg_rating state, a |
| 23 | * "Maybe Later" or "Don't Ask Again" in one place silences the prompt |
| 24 | * everywhere, so the user is never asked twice across workflows. |
| 25 | * |
| 26 | * @return bool |
| 27 | */ |
| 28 | public function isReviewPromptEligible(): bool |
| 29 | { |
| 30 | return $this->canShow(self::OPTION_NAME); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Check whether the prompt is currently dismissed or snoozed. |
| 35 | * |
| 36 | * @param string $option |
| 37 | * @return bool |
| 38 | */ |
| 39 | private function canShow($option) |
| 40 | { |
| 41 | if (empty($option)) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | $dbOption = get_option($option); |
| 46 | |
| 47 | // Permanently dismissed via "Don't Ask Again" / "Leave a Review". |
| 48 | if ($dbOption === "no") { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | // Snoozed via "Maybe Later": a valid date means "do not show before then". |
| 53 | if (wpstg_is_valid_date($dbOption)) { |
| 54 | $now = new DateTime("now"); |
| 55 | $show = new DateTime($dbOption); |
| 56 | if ($now < $show) { |
| 57 | return false; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return true; |
| 62 | } |
| 63 | } |
| 64 |