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