PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.2.3
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.2.3
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / includes / feedback-hub / notice.php

notice.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.2.3, at includes/feedback-hub/notice.php

316 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 if (!class_exists('RC_Reviews_Collector')) {
8 class RC_Reviews_Collector {
9
10 public $version = '1.0.0';
11
12 public $rc_name;
13 public $rc_allow_name;
14 public $rc_date_name;
15 public $rc_count_name;
16 public $nonce;
17 public $params;
18 public $review_url;
19
20 private static $instance = null;
21
22 /**
23 * Get Instance
24 *
25 * @since 0.0.0
26 */
27 public static function get_instance($params) {
28 if (!isset(self::$instance)) {
29 self::$instance = new self($params);
30 }
31
32 return self::$instance;
33 }
34
35 /**
36 * Insights SDK Version
37 * param array $params
38 * @return void
39 */
40 public function __construct($params) {
41 $this->params = $params;
42 $this->review_url = isset($params['review_url']) ? $params['review_url'] : false;
43
44 // add_action( 'admin_enqueue_scripts', array( $this, 'rc_enqueue_scripts' ) );
45 add_action('wp_ajax_rc_sdk_insights', array($this, 'rc_sdk_insights'));
46 add_action('wp_ajax_rc_sdk_dismiss_notice', array($this, 'rc_sdk_dismiss_notice'));
47
48 $security_key = md5($params['plugin_name']);
49 $this->rc_name = 'rc_' . str_replace('-', '_', sanitize_title($params['plugin_name']) . '_' . $security_key);
50 $this->rc_allow_name = 'rc_allow_' . $this->rc_name;
51 $this->rc_date_name = 'rc_date_' . $this->rc_name;
52 $rc_count_name = 'rc_attempt_count_' . $this->rc_name;
53 $rc_status_db = get_option($this->rc_allow_name, false);
54
55 $this->nonce = wp_create_nonce($this->rc_allow_name);
56
57 /**
58 * Show Notice after 3 days
59 * Now 5 minutes
60 */
61 $installed = get_option($this->rc_date_name . '_installed', false);
62
63 if (!$installed) {
64 update_option($this->rc_date_name . '_installed', time());
65 }
66
67 $installed = get_option($this->rc_date_name . '_installed', false);
68
69 // if ( $installed && ( time() - $installed ) < 1 * MINUTE_IN_SECONDS ) {
70 if ($installed && (time() - $installed) < 3 * DAY_IN_SECONDS) {
71 return;
72 }
73
74 /**
75 * Show Notice
76 */
77 if (!$rc_status_db) {
78 $this->display_notice();
79 return;
80 }
81
82 /**
83 * If Disallow
84 */
85 if ('disallow' == $rc_status_db) {
86 return;
87 }
88
89 /**
90 * Skip & Date Not Expired
91 * Show Notice
92 */
93 if ('skip' == $rc_status_db && true == $this->check_date()) {
94 $this->display_notice();
95 return;
96 }
97
98 /**
99 * Allowed & Date not Expired
100 * No need send data to server
101 * Else Send Data to Server
102 */
103 if (!$this->check_date()) {
104 return;
105 }
106
107 /**
108 * Count attempt every time
109 */
110 $rc_attempt = get_option($rc_count_name, 0);
111
112 if (!$rc_attempt) {
113 update_option($rc_count_name, 1);
114 }
115 update_option($rc_count_name, $rc_attempt + 1);
116 }
117
118 /**
119 * Notice Modal
120 *
121 * @return void
122 */
123 public function display_notice() {
124 add_action('admin_enqueue_scripts', array($this, 'rc_enqueue_scripts'));
125
126 if (!get_transient('dismissed_notice_' . $this->rc_name)) {
127 add_action('admin_notices', array($this, 'display_global_notice'));
128 }
129 }
130
131 /**
132 * If date is expired immidiate action
133 *
134 * @return boolean
135 */
136 public function check_date() {
137 $current_date = strtotime(gmdate('Y-m-d'));
138 $rc_status_date = strtotime(get_option($this->rc_date_name, false));
139
140 if (!$rc_status_date) {
141 return true;
142 }
143
144 if ($rc_status_date && $current_date >= $rc_status_date) {
145 return true;
146 }
147 return false;
148 }
149
150 /**
151 * Reset Options Settings
152 * @return void
153 */
154 public function reset_settings() {
155 delete_option($this->rc_allow_name);
156 delete_option($this->rc_date_name);
157 }
158
159 /**
160 * Ajax callback
161 */
162 public function rc_sdk_insights() {
163 $sanitized_status = isset($_POST['button_val']) ? sanitize_text_field($_POST['button_val']) : '';
164 $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : '';
165 $allow_name = isset($_POST['allow_name']) ? sanitize_text_field($_POST['allow_name']) : '';
166 $date_name = isset($_POST['date_name']) ? sanitize_text_field($_POST['date_name']) : '';
167
168 if (!wp_verify_nonce($nonce, 'rc_sdk')) {
169 wp_send_json(array(
170 'status' => 'error',
171 'title' => 'Error',
172 'message' => 'Nonce verification failed',
173 ));
174 wp_die();
175 }
176
177 if (!current_user_can('manage_options')) {
178 wp_send_json(array(
179 'status' => 'error',
180 'title' => 'Error',
181 'message' => 'Denied, you don\'t have right permission',
182 ));
183 wp_die();
184 }
185
186 if ('disallow' == $sanitized_status) {
187 update_option($allow_name, 'disallow');
188 }
189
190 if ($sanitized_status == 'skip') {
191 update_option($allow_name, 'skip');
192 /**
193 * Next schedule date for attempt
194 */
195 update_option($date_name, gmdate('Y-m-d', strtotime("+1 month")));
196 } elseif ($sanitized_status == 'yes') {
197 update_option($allow_name, 'yes');
198 }
199
200 wp_send_json(array(
201 'status' => 'success',
202 'title' => 'Success',
203 'message' => 'Success.',
204 'action' => $sanitized_status,
205 ));
206 wp_die();
207 }
208
209 /**
210 * Enqueue scripts and styles.
211 *
212 * @since 1.0.0
213 */
214 public function rc_enqueue_scripts() {
215 wp_enqueue_style('rc-sdk', plugins_url('assets/rc.css', __FILE__), array(), '1.0.0');
216 wp_enqueue_script('rc-sdk', plugins_url('assets/rc.js', __FILE__), array('jquery'), '1.0.0', true);
217
218 // Add inline style to hide all but the first notice on page load
219 $inline_css = '.rc-global-notice { display: none; }';
220 wp_add_inline_style( 'rc-sdk', $inline_css );
221 }
222
223 /**
224 * Display Global Notice
225 *
226 * @return void
227 */
228 public function display_global_notice() {
229 $plugin_title = isset($this->params['plugin_title']) ? $this->params['plugin_title'] : '';
230 $plugin_msg = isset($this->params['plugin_msg']) ? $this->params['plugin_msg'] : '';
231 $plugin_icon = isset($this->params['plugin_icon']) ? $this->params['plugin_icon'] : '';
232
233 ?>
234 <div class="rc-global-notice notice notice-success is-dismissible <?php echo esc_attr(substr($this->rc_name, 0, -33)); ?>">
235 <div class="rc-global-header">
236 <?php if (!empty($plugin_icon)) : ?>
237 <div class="bdt-notice-rc-logo">
238 <img src="<?php echo esc_url($plugin_icon); ?>" alt="icon">
239 </div>
240 <?php endif; ?>
241
242 <div class="bdt-notice-rc-content">
243 <h3>
244 <?php printf(wp_kses_post($plugin_title)); ?>
245 </h3>
246 <?php printf(wp_kses_post($plugin_msg)); ?>
247 <input type="hidden" name="rc_name" value="<?php echo esc_html($this->rc_name); ?>">
248 <input type="hidden" name="nonce" value="<?php echo esc_html(wp_create_nonce('rc_sdk')); ?>">
249 <div class="bdt-notice-rc-buttons">
250 <button data-rc_name="<?php echo esc_html($this->rc_name); ?>" data-date_name="<?php echo esc_html($this->rc_date_name); ?>" data-allow_name="<?php echo esc_html($this->rc_allow_name); ?>" data-nonce="<?php echo esc_html(wp_create_nonce('rc_sdk')); ?>" data-review_url="<?php echo esc_html($this->review_url); ?>" name="rc_allow_status" value="yes" class="rc-button-allow">
251 <span class="dashicons dashicons-star-filled" style="margin-top: 3px;"></span> Give us your Review
252 </button>
253 <button data-rc_name="<?php echo esc_html($this->rc_name); ?>" data-date_name="<?php echo esc_html($this->rc_date_name); ?>" data-allow_name="<?php echo esc_html($this->rc_allow_name); ?>" data-nonce="<?php echo esc_html(wp_create_nonce('rc_sdk')); ?>" data-review_url="<?php echo esc_html($this->review_url); ?>" name="rc_allow_status" value="skip" class="rc-button-skip">
254 I'll skip for now
255 </button>
256 <button data-rc_name="<?php echo esc_html($this->rc_name); ?>" data-date_name="<?php echo esc_html($this->rc_date_name); ?>" data-allow_name="<?php echo esc_html($this->rc_allow_name); ?>" data-nonce="<?php echo esc_html(wp_create_nonce('rc_sdk')); ?>" data-review_url="<?php echo esc_html($this->review_url); ?>" name="rc_allow_status" value="disallow" class="rc-button-disallow rc-button-danger">
257 Hide and Don't show again
258 </button>
259 </div>
260 </div>
261 </div>
262 </div>
263 <?php
264 }
265
266 /**
267 * Dismiss Notice
268 *
269 * @return void
270 */
271 public function rc_sdk_dismiss_notice() {
272 $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : '';
273 $rc_name = isset($_POST['rc_name']) ? sanitize_text_field($_POST['rc_name']) : '';
274
275 if (!wp_verify_nonce($nonce, 'rc_sdk')) {
276 wp_send_json(array(
277 'status' => 'error',
278 'title' => 'Error',
279 'message' => 'Nonce verification failed',
280 ));
281 wp_die();
282 }
283
284 if (!current_user_can('manage_options')) {
285 wp_send_json(array(
286 'status' => 'error',
287 'title' => 'Error',
288 'message' => 'Denied, you don\'t have right permission',
289 ));
290 wp_die();
291 }
292
293 set_transient('dismissed_notice_' . $rc_name, true, 30 * DAY_IN_SECONDS);
294
295 wp_send_json(array(
296 'status' => 'success',
297 'title' => 'Success',
298 'message' => 'Success.',
299 ));
300 wp_die();
301 }
302 }
303 }
304
305 /**
306 * Main Insights Function
307 */
308 if (!function_exists('rc_sdk_automate')) {
309 function rc_sdk_automate($params) {
310 if (class_exists('RC_Reviews_Collector')) {
311 // RC_Reviews_Collector::get_instance( $params );
312 new RC_Reviews_Collector($params);
313 }
314 }
315 }
316