PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.8.8
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.8.8
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / Admin / Notice / Review.php
the-post-grid / app / Controllers / Admin / Notice Last commit date
BlackFriday.php 8 months ago EidSpecial.php 8 months ago LoadResourceType.php 8 months ago Review.php 8 months ago SummerSale.php 8 months ago
Review.php
350 lines
1 <?php
2 /**
3 * Notice Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers\Admin\Notice;
9
10 // Do not allow directly accessing this file.
11 use RT\ThePostGrid\Helpers\Fns;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 'This script cannot be accessed directly.' );
15 }
16
17 /**
18 * Review class.
19 */
20 class Review {
21
22 /**
23 * Review notice.
24 *
25 * @return void
26 */
27 public function __construct() {
28 if ( Fns::is_black_friday_active() ) {
29 return;
30 }
31 add_action( 'admin_notices', [ $this, 'render_review_notice' ] );
32 add_action( 'admin_init', [ __CLASS__, 'update_notice_status' ] );
33 add_action( 'admin_head', [ __CLASS__, 'admin_scripts' ] );
34 }
35
36 /**
37 * Check if review notice should be shown or not
38 *
39 * @return void
40 */
41
42 public function render_review_notice() {
43 $spare_me = get_option( 'rttpg_spare_me', '0' );
44 $install_date = (int) get_option( 'rttpg_plugin_activation_time' );
45 $remind_time = (int) get_option( 'rttpg_remind_me' );
46 $now = time();
47
48 // Early exit if user opted out permanently or already rated.
49 if ( in_array( $spare_me, [ '1', '3' ], true ) ) {
50 return;
51 }
52
53 // Calculate date thresholds.
54 $ten_days_after_install = $install_date + ( 10 * DAY_IN_SECONDS );
55 $remind_due = $remind_time + ( 15 * DAY_IN_SECONDS );
56 $should_show_reminder = $remind_time && ( $now >= $remind_due ); //15 days later from reminding
57 $should_show_after_install = $install_date && ( $now >= $ten_days_after_install ) && $spare_me !== '2';
58
59 if ( $should_show_reminder || $should_show_after_install ) {
60 $this->rttpg_display_admin_notice();
61 }
62 }
63
64 /**
65 * Display Admin Notice, asking for a review
66 *
67 * @return void
68 */
69 public function rttpg_display_admin_notice() {
70 global $pagenow;
71
72 $exclude_pages = [
73 'themes.php',
74 'users.php',
75 'tools.php',
76 'options-general.php',
77 'options-writing.php',
78 'options-reading.php',
79 'options-discussion.php',
80 'options-media.php',
81 'options-permalink.php',
82 'options-privacy.php',
83 'edit-comments.php',
84 'upload.php',
85 'media-new.php',
86 'admin.php',
87 'import.php',
88 'export.php',
89 'site-health.php',
90 'export-personal-data.php',
91 'erase-personal-data.php',
92 ];
93
94 if ( in_array( $pagenow, $exclude_pages, true ) ) {
95 return;
96 }
97
98 $nonce = wp_create_nonce( 'rttpg_notice_nonce' );
99 $current_url = self::rttpg_current_admin_url();
100 $dont_disturb = add_query_arg( [ '_wpnonce' => $nonce, 'rttpg_spare_me' => '1' ], $current_url );
101 $remind_me = add_query_arg( [ '_wpnonce' => $nonce, 'rttpg_remind_me' => '1' ], $current_url );
102 $rated = add_query_arg( [ '_wpnonce' => $nonce, 'rttpg_rated' => '1' ], $current_url );
103 $review_url = 'https://wordpress.org/support/plugin/the-post-grid/reviews/?filter=5#new-post';
104 $plugin_name = 'The Post Grid';
105 $download_link = 'https://www.radiustheme.com/downloads/the-post-grid-pro-for-wordpress/';
106 $image_url = rtTPG()->get_assets_uri( 'images/post-grid-gif.gif' );
107 ?>
108 <div class="notice rttpg-review-notice rttpg-review-notice--extended">
109 <div class="rttpg-review-notice_content" style="display: flex; gap: 15px;">
110 <a href="<?php echo esc_url( $download_link ); ?>" target="_blank">
111 <img alt="<?php echo esc_attr( $plugin_name ); ?>"
112 src="<?php echo esc_url( $image_url ); ?>"
113 width="50" height="50"
114 style="transform: translateY(2px)"/>
115 </a>
116 <div>
117 <p>
118 <strong><?php echo esc_html( "Thank you for choosing $plugin_name." ); ?></strong>
119 <?php echo esc_html( "If you have found our plugin useful and makes you smile, please consider giving us a 5-star rating on WordPress.org. It will help us to grow." ); ?>
120 </p>
121 <div class="rttpg-review-notice_actions">
122 <a href="<?php echo esc_url( $review_url ); ?>" class="rttpg-review-button rttpg-review-button--cta" target="_blank">
123 <span></span><span>Yes, You Deserve It!</span>
124 </a>
125 <a href="<?php echo esc_url( $rated ); ?>" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--outline">
126 <span>😀</span><span>Already Rated!</span>
127 </a>
128 <a href="<?php echo esc_url( $remind_me ); ?>" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--outline">
129 <span>🔔</span><span>Remind Me Later</span>
130 </a>
131 <a href="<?php echo esc_url( $dont_disturb ); ?>" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--error rttpg-review-button--outline">
132 <span>😐</span><span>No Thanks</span>
133 </a>
134 </div>
135 </div>
136 </div>
137 </div>
138
139 <?php
140 }
141
142 /**
143 * Current admin URL.
144 *
145 * @return string
146 */
147 protected static function rttpg_current_admin_url() {
148 $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
149 $uri = preg_replace( '|^.*/wp-admin/|i', '', $uri ?? '' );
150
151 if ( ! $uri ) {
152 return '';
153 }
154
155 return remove_query_arg(
156 [
157 '_wpnonce',
158 '_wc_notice_nonce',
159 'wc_db_update',
160 'wc_db_update_nonce',
161 'wc-hide-notice',
162 ],
163 admin_url( $uri )
164 );
165 }
166
167 /**
168 * Remove the notice for the user if review already done
169 *
170 * @return void
171 */
172 public static function update_notice_status() {
173 // Verify nonce
174 if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'rttpg_notice_nonce' ) ) {
175 return;
176 }
177
178 // Map GET parameters to update callbacks
179 $actions = [
180 'rttpg_spare_me' => function () {
181 update_option( 'rttpg_spare_me', '1' );
182 },
183 'rttpg_remind_me' => function () {
184 $now = time();
185 update_option( 'rttpg_remind_me', $now );
186 update_option( 'rttpg_spare_me', '2' );
187 },
188 'rttpg_rated' => function () {
189 update_option( 'rttpg_rated', 'yes' );
190 update_option( 'rttpg_spare_me', '3' );
191 },
192 ];
193
194 // Loop through actions and execute if GET parameter exists and equals 1
195 foreach ( $actions as $key => $callback ) {
196 if ( isset( $_GET[ $key ] ) && absint( $_GET[ $key ] ) === 1 ) {
197 $callback();
198 }
199 }
200 }
201
202
203 /**
204 * Admin Scripts
205 * @return void
206 */
207 public static function admin_scripts() {
208 ?>
209 <style>
210 .rttpg-review-button--cta {
211 --e-button-context-color: #4C6FFF;
212 --e-button-context-color-dark: #4C6FFF;
213 --e-button-context-tint: rgb(75 47 157/4%);
214 --e-focus-color: rgb(75 47 157/40%);
215 }
216
217 .rttpg-review-notice {
218 position: relative;
219 margin: 5px 20px 5px 2px;
220 border: 1px solid #ccd0d4;
221 background: #fff;
222 box-shadow: none;
223 font-family: Roboto, Arial, Helvetica, Verdana, sans-serif;
224 border-inline-start-width: 4px;
225 }
226
227 .rttpg-review-notice.notice {
228 padding: 0;
229 }
230
231 .rttpg-review-notice:before {
232 position: absolute;
233 top: -1px;
234 bottom: -1px;
235 left: -4px;
236 display: block;
237 width: 4px;
238 background: -webkit-linear-gradient(bottom, #4C6FFF 0%, #6939c6 100%);
239 background: linear-gradient(0deg, #4C6FFF 0%, #6939c6 100%);
240 content: "";
241 }
242
243 .rttpg-review-notice_content img {
244 width: 50px;
245 height: 50px;
246 }
247
248 .rttpg-review-notice_content {
249 padding: 10px;
250 }
251
252 .rttpg-review-notice_actions > * + * {
253 margin-inline-start: 8px;
254 -webkit-margin-start: 8px;
255 -moz-margin-start: 8px;
256 }
257
258 .rttpg-review-notice p {
259 margin: 0;
260 padding: 0;
261 line-height: 1.5;
262 }
263
264 p + .rttpg-review-notice_actions {
265 margin-top: 5px;
266 }
267
268 .rttpg-review-notice h3 {
269 margin: 0;
270 font-size: 1.0625rem;
271 line-height: 1.2;
272 }
273
274 .rttpg-review-notice h3 + p {
275 margin-top: 2px;
276 }
277
278 .rttpg-review-button span {
279 display: flex;
280 }
281
282 .rttpg-review-button {
283 display: inline-flex;
284 align-items: center;
285 gap: 5px;
286 padding: 4px 10px;
287 border: 0;
288 border-radius: 3px;;
289 background: var(--e-button-context-color);
290 color: #fff;
291 vertical-align: middle;
292 text-align: center;
293 text-decoration: none;
294 white-space: nowrap;
295 font-size: 13px
296 font-weight: normal;
297 }
298
299 .rttpg-review-button:active {
300 background: var(--e-button-context-color-dark);
301 color: #fff;
302 text-decoration: none;
303 }
304
305 .rttpg-review-button:focus {
306 outline: 0;
307 background: var(--e-button-context-color-dark);
308 box-shadow: 0 0 0 2px var(--e-focus-color);
309 color: #fff;
310 text-decoration: none;
311 }
312
313 .rttpg-review-button:hover {
314 background: var(--e-button-context-color-dark);
315 color: #fff;
316 text-decoration: none;
317 }
318
319 .rttpg-review-button.focus {
320 outline: 0;
321 box-shadow: 0 0 0 2px var(--e-focus-color);
322 }
323
324 .rttpg-review-button--error {
325 --e-button-context-color: #d72b3f;
326 --e-button-context-color-dark: #ae2131;
327 --e-button-context-tint: rgba(215, 43, 63, 0.04);
328 --e-focus-color: rgba(215, 43, 63, 0.4);
329 }
330
331 .rttpg-review-button.rttpg-review-button--outline {
332 border: 1px solid;
333 background: 0 0;
334 color: #212121;
335 }
336
337 .rttpg-review-button.rttpg-review-button--outline:focus {
338 background: var(--e-button-context-tint);
339 color: var(--e-button-context-color-dark);
340 }
341
342 .rttpg-review-button.rttpg-review-button--outline:hover {
343 background: var(--e-button-context-tint);
344 color: var(--e-button-context-color-dark);
345 }
346 </style>
347 <?php
348 }
349
350 }