PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 4.0.7
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v4.0.7
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / admin / controllers / class-review-controller.php
superb-blocks / src / admin / controllers Last commit date
wizard 4 days ago class-dashboard-controller.php 4 days ago class-license-resolve-controller.php 4 days ago class-newsletter-signup-controller.php 4 days ago class-notice-controller.php 4 days ago class-plugin-reset-controller.php 4 days ago class-review-controller.php 4 days ago class-rewrite-check-controller.php 4 days ago class-settings-controller.php 4 days ago class-troubleshooting-controller.php 4 days ago
class-review-controller.php
139 lines
1 <?php
2
3 namespace SuperbAddons\Admin\Controllers;
4
5 defined('ABSPATH') || exit();
6
7 use SuperbAddons\Config\Capabilities;
8 use SuperbAddons\Data\Controllers\KeyController;
9 use SuperbAddons\Data\Utils\Engagement;
10
11 /**
12 * - A dismissible admin notice
13 * - A "rate us" star line in the admin footer of Superb Addons
14 * screens.
15 */
16 class ReviewController
17 {
18 const MIN_AGE_DAYS = 14;
19
20 public function __construct()
21 {
22 add_filter('admin_footer_text', array($this, 'AdminFooterText'), 100);
23 }
24
25 /**
26 * Direct link to leave a review on WordPress.org.
27 *
28 * @return string
29 */
30 public static function GetReviewUrl()
31 {
32 return add_query_arg(
33 array('filter' => 5),
34 'https://wordpress.org/support/plugin/superb-blocks/reviews/#new-post'
35 );
36 }
37
38 /**
39 * Whether the review notice is eligible to register for the current user.
40 *
41 * @return bool
42 */
43 public static function ShouldShowReviewNotice()
44 {
45 // Only ask real administrators (the person who would leave a review).
46 if (!current_user_can(Capabilities::ADMIN)) {
47 return false;
48 }
49
50 // Site must have been installed for at least MIN_AGE_DAYS days.
51 if ((self::GetInstallTimestamp() + (self::MIN_AGE_DAYS * DAY_IN_SECONDS)) > time()) {
52 return false;
53 }
54
55 // Site must have actually used a feature.
56 if (!Engagement::HasEngaged()) {
57 return false;
58 }
59
60 // Free users: wait until the notice has been dismissed so we
61 // never stack two of our notices.
62 if (!KeyController::HasValidPremiumKey() && !self::UpsellNoticeDismissed()) {
63 return false;
64 }
65
66 return true;
67 }
68
69 private static function GetInstallTimestamp()
70 {
71 $pre_activation = get_option('superbaddons_pre_activation');
72 if (!$pre_activation) {
73 $pre_activation = time();
74 add_option('superbaddons_pre_activation', $pre_activation, '', false);
75 }
76 return intval($pre_activation);
77 }
78
79 /**
80 * Whether the current user has dismissed the free-user notice.
81 *
82 * @return bool
83 */
84 private static function UpsellNoticeDismissed()
85 {
86 return (bool) get_user_meta(
87 get_current_user_id(),
88 AdminNoticeController::PREFIX . DashboardController::NOTICE_ID_UPSELL,
89 true
90 );
91 }
92
93 /**
94 * Persistent admin footer "rate us" line on Superb Addons screens.
95 *
96 * @param string|mixed $text
97 * @return string
98 */
99 public function AdminFooterText($text)
100 {
101 if (!self::IsSuperbAdminScreen()) {
102 return is_string($text) ? $text : '';
103 }
104
105 $url = esc_url(self::GetReviewUrl());
106
107 return sprintf(
108 wp_kses(
109 /* translators: 1: plugin name, 2: review link (stars), 3: review link (WordPress.org). */
110 __('Please rate %1$s <a href="%2$s" target="_blank" rel="noopener noreferrer">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%3$s" target="_blank" rel="noopener noreferrer">WordPress.org</a> to help us spread the word.', 'superb-blocks'),
111 array(
112 'a' => array(
113 'href' => array(),
114 'target' => array(),
115 'rel' => array(),
116 ),
117 )
118 ),
119 '<strong>Superb Addons</strong>',
120 $url,
121 $url
122 );
123 }
124
125 /**
126 * Whether the current admin screen belongs to Superb Addons.
127 *
128 * @return bool
129 */
130 private static function IsSuperbAdminScreen()
131 {
132 if (!function_exists('get_current_screen')) {
133 return false;
134 }
135 $screen = get_current_screen();
136 return $screen && !empty($screen->id) && strpos($screen->id, 'superbaddons') !== false;
137 }
138 }
139