PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.2
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 / NoticeController.php
the-post-grid / app / Controllers / Admin Last commit date
AdminAjaxController.php 3 years ago MetaController.php 3 years ago NoticeController.php 3 years ago PostTypeController.php 3 years ago SettingsController.php 3 years ago UpgradeController.php 3 years ago
NoticeController.php
442 lines
1 <?php
2 /**
3 * Notice Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers\Admin;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 /**
16 * Notice Controller class.
17 */
18 class NoticeController {
19 /**
20 * Class Constructor
21 */
22 public function __construct() {
23 $current = time();
24 $black_friday = mktime( 0, 0, 0, 11, 18, 2022 ) <= $current && $current <= mktime( 0, 0, 0, 1, 6, 2023 );
25
26 if ( $black_friday ) {
27 add_action( 'admin_init', [ $this, 'black_friday_notice' ] );
28 }
29
30 register_activation_hook( RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME, [ $this, 'rttpg_activation_time' ] );
31 add_action( 'admin_init', [ $this, 'rttpg_check_installation_time' ] );
32 add_action( 'admin_init', [ __CLASS__, 'rttpg_spare_me' ], 5 );
33 add_action( 'admin_init', [ __CLASS__, 'rttpg_notice' ] );
34 }
35
36 /**
37 * Notice
38 *
39 * @return void
40 */
41 public static function rttpg_notice() {
42 add_action(
43 'admin_notices',
44 function () {
45 $settings = get_option( 'rt_the_post_grid_settings' );
46 $screen = get_current_screen();
47
48 if ( isset( $settings['tpg_block_type'] ) ) {
49 if ( in_array( $screen->id, [
50 'edit-rttpg',
51 'rttpg'
52 ], true ) && 'elementor' === $settings['tpg_block_type'] ) { ?>
53 <div class="notice notice-for-warning">
54 <p>
55 <?php
56 echo sprintf(
57 '%1$s<a style="color: #fff;" href="%2$s">%3$s</a>',
58 esc_html__( 'You have selected only Elementor method. To use Shortcode Generator please enable shortcode or default from ', 'the-post-grid' ),
59 esc_url( admin_url( 'edit.php?post_type=rttpg&page=rttpg_settings' ) ),
60 esc_html__( 'Settings => Common Settings => Resource Load Type', 'the-post-grid' )
61 );
62 ?>
63 </p>
64 </div>
65 <?php
66 }
67
68 if ( 'edit-tpg_builder' === $screen->id && 'shortcode' === $settings['tpg_block_type'] ) {
69 ?>
70 <div class="notice notice-for-warning">
71 <p>
72 <?php
73 echo sprintf(
74 '%1$s<a style="color: #fff;" href="%2$s">%3$s</a>',
75 esc_html__( 'You have selected only Shortcode Generator method. To use Elementor please enable Elementor or default from ', 'the-post-grid' ),
76 esc_url( admin_url( 'edit.php?post_type=rttpg&page=rttpg_settings&section=common-settings' ) ),
77 esc_html__( 'Settings => Common Settings => Resource Load Type', 'the-post-grid' )
78 );
79 ?>
80 </p>
81 </div>
82 <?php
83 }
84 }
85 }
86 );
87 }
88
89 /**
90 * Black friday notice.
91 *
92 * @return void
93 */
94 public static function black_friday_notice() {
95 if ( get_option( 'rttpg_bf_2022' ) != '1' ) {
96 self::notice();
97 }
98 }
99
100 /**
101 * Black friday notice.
102 *
103 * @return void
104 */
105 public static function notice() {
106 add_action(
107 'admin_enqueue_scripts',
108 function () {
109 wp_enqueue_script( 'jquery' );
110 }
111 );
112
113 add_action(
114 'admin_notices',
115 function () {
116 $plugin_name = 'The Post Grid';
117 $download_link = 'https://www.radiustheme.com/downloads/the-post-grid-pro-for-wordpress/'; ?>
118 <div class="notice notice-info is-dismissible" data-rttpg-dismissable="rttpg_bf_2022"
119 style="display:grid;grid-template-columns: 100px auto;padding-top: 25px; padding-bottom: 22px;">
120 <img alt="<?php echo esc_attr( $plugin_name ); ?>"
121 src="<?php echo esc_url( rtTPG()->get_assets_uri( 'images/post-grid-gif.gif' ) ); ?>"
122 width="74px" height="74px" style="grid-row: 1 / 4; align-self: center;justify-self: center"/>
123 <h3 style="margin:0;"><?php echo sprintf( '%s Cyber Week Deal!!', esc_html( $plugin_name ) ); ?></h3>
124 <p style="margin:0 0 2px;">Don't miss out on our biggest sale of the year! Get your
125 <b><?php echo esc_html( $plugin_name ); ?> plan</b> with <b>UPTO 50% OFF</b>! Limited time offer!!!</p>
126 <p style="margin:0;">
127 <a class="button button-primary" href="<?php echo esc_url( $download_link ); ?>"
128 target="_blank">Buy Now</a>
129 <a class="button button-dismiss" href="#">Dismiss</a>
130 </p>
131 </div>
132 <?php
133 }
134 );
135
136 add_action(
137 'admin_footer',
138 function () {
139 ?>
140 <script type="text/javascript">
141 (function ($) {
142 $(function () {
143 setTimeout(function () {
144 $('div[data-rttpg-dismissable] .notice-dismiss, div[data-rttpg-dismissable] .button-dismiss')
145 .on('click', function (e) {
146 e.preventDefault();
147 $.post(ajaxurl, {
148 'action': 'rttpg_dismiss_admin_notice',
149 'nonce': <?php echo wp_json_encode( wp_create_nonce( 'rttpg-dismissible-notice' ) ); ?>
150 });
151 $(e.target).closest('.is-dismissible').remove();
152 });
153 }, 1000);
154 });
155 })(jQuery);
156 </script>
157 <?php
158 }
159 );
160
161 add_action(
162 'wp_ajax_rttpg_dismiss_admin_notice',
163 function () {
164 check_ajax_referer( 'rttpg-dismissible-notice', 'nonce' );
165
166 update_option( 'rttpg_bf_2022', '1' );
167 wp_die();
168 }
169 );
170 }
171
172 /**
173 * Plugin activation time
174 *
175 * @return void
176 */
177 public static function rttpg_activation_time() {
178 $get_activation_time = strtotime( "now" );
179 add_option( 'rttpg_plugin_activation_time', $get_activation_time );
180 }
181
182 /**
183 * Check if review notice should be shown or not
184 *
185 * @return void
186 */
187 public static function rttpg_check_installation_time() {
188 // Added Lines Start.
189 $nobug = get_option( 'rttpg_spare_me', '0' );
190
191 if ( $nobug == '1' || $nobug == '3' ) {
192 return;
193 }
194
195 $install_date = get_option( 'rttpg_plugin_activation_time' );
196 $past_date = strtotime( '-10 days' );
197
198 $remind_time = get_option( 'rttpg_remind_me' );
199 $remind_due = strtotime( '+15 days', $remind_time );
200 $now = strtotime( 'now' );
201
202 if ( $now >= $remind_due ) {
203 add_action( 'admin_notices', [ __CLASS__, 'rttpg_display_admin_notice' ] );
204 } else if ( ( $past_date >= $install_date ) && '2' !== $nobug ) {
205 add_action( 'admin_notices', [ __CLASS__, 'rttpg_display_admin_notice' ] );
206 }
207 }
208
209 /**
210 * Display Admin Notice, asking for a review
211 *
212 * @return void
213 */
214 public static function rttpg_display_admin_notice() {
215 global $pagenow;
216
217 $exclude = [
218 'themes.php',
219 'users.php',
220 'tools.php',
221 'options-general.php',
222 'options-writing.php',
223 'options-reading.php',
224 'options-discussion.php',
225 'options-media.php',
226 'options-permalink.php',
227 'options-privacy.php',
228 'edit-comments.php',
229 'upload.php',
230 'media-new.php',
231 'admin.php',
232 'import.php',
233 'export.php',
234 'site-health.php',
235 'export-personal-data.php',
236 'erase-personal-data.php',
237 ];
238
239 if ( ! in_array( $pagenow, $exclude ) ) {
240
241 $args = [ '_wpnonce' => wp_create_nonce( 'rttpg_notice_nonce' ) ];
242 $dont_disturb = add_query_arg( $args + [ 'rttpg_spare_me' => '1' ], self::rttpg_current_admin_url() );
243 $remind_me = add_query_arg( $args + [ 'rttpg_remind_me' => '1' ], self::rttpg_current_admin_url() );
244 $rated = add_query_arg( $args + [ 'rttpg_rated' => '1' ], self::rttpg_current_admin_url() );
245 $reviewurl = 'https://wordpress.org/support/plugin/the-post-grid/reviews/?filter=5#new-post';
246
247 printf(
248 '<div class="notice rttpg-review-notice rttpg-review-notice--extended">
249 <div class="rttpg-review-notice_content">
250 <h3>%1$s</h3>
251 <p>%2$s</p>
252 <div class="rttpg-review-notice_actions">
253 <a href="%3$s" class="rttpg-review-button rttpg-review-button--cta" target="_blank"><span>⭐ Yes, You Deserve It!</span></a>
254 <a href="%4$s" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--outline"><span>😀 Already Rated!</span></a>
255 <a href="%5$s" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--outline"><span>🔔 Remind Me Later</span></a>
256 <a href="%6$s" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--error rttpg-review-button--outline"><span>😐 No Thanks</span></a>
257 </div>
258 </div>
259 </div>',
260 esc_html__( 'Enjoying The Post Grid?', 'the-post-grid' ),
261 esc_html__( 'Thank you for choosing The Post Grid. 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.', 'the-post-grid' ),
262 esc_url( $reviewurl ),
263 esc_url( $rated ),
264 esc_url( $remind_me ),
265 esc_url( $dont_disturb )
266 );
267
268 echo '<style>
269 .rttpg-review-button--cta {
270 --e-button-context-color: #4C6FFF;
271 --e-button-context-color-dark: #4C6FFF;
272 --e-button-context-tint: rgb(75 47 157/4%);
273 --e-focus-color: rgb(75 47 157/40%);
274 }
275 .rttpg-review-notice {
276 position: relative;
277 margin: 5px 20px 5px 2px;
278 border: 1px solid #ccd0d4;
279 background: #fff;
280 box-shadow: 0 1px 4px rgba(0,0,0,0.15);
281 font-family: Roboto, Arial, Helvetica, Verdana, sans-serif;
282 border-inline-start-width: 4px;
283 }
284 .rttpg-review-notice.notice {
285 padding: 0;
286 }
287 .rttpg-review-notice:before {
288 position: absolute;
289 top: -1px;
290 bottom: -1px;
291 left: -4px;
292 display: block;
293 width: 4px;
294 background: -webkit-linear-gradient(bottom, #4C6FFF 0%, #6939c6 100%);
295 background: linear-gradient(0deg, #4C6FFF 0%, #6939c6 100%);
296 content: "";
297 }
298 .rttpg-review-notice_content {
299 padding: 20px;
300 }
301 .rttpg-review-notice_actions > * + * {
302 margin-inline-start: 8px;
303 -webkit-margin-start: 8px;
304 -moz-margin-start: 8px;
305 }
306 .rttpg-review-notice p {
307 margin: 0;
308 padding: 0;
309 line-height: 1.5;
310 }
311 p + .rttpg-review-notice_actions {
312 margin-top: 1rem;
313 }
314 .rttpg-review-notice h3 {
315 margin: 0;
316 font-size: 1.0625rem;
317 line-height: 1.2;
318 }
319 .rttpg-review-notice h3 + p {
320 margin-top: 8px;
321 }
322 .rttpg-review-button {
323 display: inline-block;
324 padding: 0.4375rem 0.75rem;
325 border: 0;
326 border-radius: 3px;;
327 background: var(--e-button-context-color);
328 color: #fff;
329 vertical-align: middle;
330 text-align: center;
331 text-decoration: none;
332 white-space: nowrap;
333 }
334 .rttpg-review-button:active {
335 background: var(--e-button-context-color-dark);
336 color: #fff;
337 text-decoration: none;
338 }
339 .rttpg-review-button:focus {
340 outline: 0;
341 background: var(--e-button-context-color-dark);
342 box-shadow: 0 0 0 2px var(--e-focus-color);
343 color: #fff;
344 text-decoration: none;
345 }
346 .rttpg-review-button:hover {
347 background: var(--e-button-context-color-dark);
348 color: #fff;
349 text-decoration: none;
350 }
351 .rttpg-review-button.focus {
352 outline: 0;
353 box-shadow: 0 0 0 2px var(--e-focus-color);
354 }
355 .rttpg-review-button--error {
356 --e-button-context-color: #d72b3f;
357 --e-button-context-color-dark: #ae2131;
358 --e-button-context-tint: rgba(215,43,63,0.04);
359 --e-focus-color: rgba(215,43,63,0.4);
360 }
361 .rttpg-review-button.rttpg-review-button--outline {
362 border: 1px solid;
363 background: 0 0;
364 color: var(--e-button-context-color);
365 }
366 .rttpg-review-button.rttpg-review-button--outline:focus {
367 background: var(--e-button-context-tint);
368 color: var(--e-button-context-color-dark);
369 }
370 .rttpg-review-button.rttpg-review-button--outline:hover {
371 background: var(--e-button-context-tint);
372 color: var(--e-button-context-color-dark);
373 }
374 </style>';
375 }
376 }
377
378 /**
379 * Current admin URL.
380 *
381 * @return string
382 */
383 protected static function rttpg_current_admin_url() {
384 $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
385 $uri = preg_replace( '|^.*/wp-admin/|i', '', $uri );
386
387 if ( ! $uri ) {
388 return '';
389 }
390
391 return remove_query_arg(
392 [
393 '_wpnonce',
394 '_wc_notice_nonce',
395 'wc_db_update',
396 'wc_db_update_nonce',
397 'wc-hide-notice'
398 ],
399 admin_url( $uri )
400 );
401 }
402
403 /**
404 * Remove the notice for the user if review already done
405 *
406 * @return void
407 */
408 public static function rttpg_spare_me() {
409
410 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'rttpg_notice_nonce' ) ) {
411 return;
412 }
413
414 if ( isset( $_GET['rttpg_spare_me'] ) && ! empty( $_GET['rttpg_spare_me'] ) ) {
415 $spare_me = absint( $_GET['rttpg_spare_me'] );
416
417 if ( 1 == $spare_me ) {
418 update_option( 'rttpg_spare_me', '1' );
419 }
420 }
421
422 if ( isset( $_GET['rttpg_remind_me'] ) && ! empty( $_GET['rttpg_remind_me'] ) ) {
423 $remind_me = absint( $_GET['rttpg_remind_me'] );
424
425 if ( 1 == $remind_me ) {
426 $get_activation_time = strtotime( 'now' );
427
428 update_option( 'rttpg_remind_me', $get_activation_time );
429 update_option( 'rttpg_spare_me', '2' );
430 }
431 }
432
433 if ( isset( $_GET['rttpg_rated'] ) && ! empty( $_GET['rttpg_rated'] ) ) {
434 $rttpg_rated = absint( $_GET['rttpg_rated'] );
435
436 if ( 1 == $rttpg_rated ) {
437 update_option( 'rttpg_rated', 'yes' );
438 update_option( 'rttpg_spare_me', '3' );
439 }
440 }
441 }
442 }