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