PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.2
4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Basic / Notices / RatingNotice.php
wp-staging / Basic / Notices Last commit date
BasicNotices.php 2 years ago RatingNotice.php 2 years ago
RatingNotice.php
76 lines
1 <?php
2
3 namespace WPStaging\Basic\Notices;
4
5 use DateTime;
6 use Exception;
7
8 class RatingNotice
9 {
10 /** @var string */
11 const OPTION_NAME = 'wpstg_rating';
12
13 /** @var int */
14 const DAYS_TO_SHOW_RATING_NOTICE_AFTER = 7;
15
16 public function shouldShowRatingNotice()
17 {
18 return $this->canShow(self::OPTION_NAME, self::DAYS_TO_SHOW_RATING_NOTICE_AFTER) && $this->getCurrentPage() !== 'page' && $this->getCurrentPage() !== 'post';
19 }
20
21 /**
22 * Check if notice should be shown after certain days of installation or if it is dismissed
23 * @param int $days default 10
24 * @return bool
25 */
26 private function canShow($option, $days = 10)
27 {
28 // Do not show notice
29 if (empty($option)) {
30 return false;
31 }
32
33 $dbOption = get_option($option);
34
35 // Do not show notice
36 if ($dbOption === "no") {
37 return false;
38 }
39
40 $now = new DateTime("now");
41
42 // Check if user clicked on "rate later" button and if there is a valid 'later' date
43 if (wpstg_is_valid_date($dbOption)) {
44 // Do not show before this date
45 $show = new DateTime($dbOption);
46 if ($now < $show) {
47 return false;
48 }
49 }
50
51 // Show X days after installation
52 $installDate = new DateTime(get_option("wpstg_installDate"));
53
54 // get number of days between installation date and today
55 $difference = $now->diff($installDate)->days;
56
57 return $days <= $difference;
58 }
59
60 /**
61 * Get current page.
62 * Note: This can not be moved to wpAdapter class as it is only available very late
63 * at add admin_init and not available most of the time.
64 *
65 * @return string post, page
66 */
67 private function getCurrentPage()
68 {
69 if (function_exists('\get_current_screen')) {
70 return \get_current_screen()->post_type;
71 }
72
73 throw new Exception('Function get_current_screen does not exist. WP < 3.0.1.');
74 }
75 }
76