PluginProbe ʕ •ᴥ•ʔ
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping / 6.12.0
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping v6.12.0
6.12.1 6.12.0 6.11.0 6.10.0 6.9.1 6.9.0 6.8.1 6.8.0 6.7.4 6.7.3 6.7.2 6.7.0 4.21.7 4.22.0 4.22.1 4.23.0 4.23.1 4.23.2 4.23.3 4.24.0 4.24.1 4.24.10 4.24.11 4.24.12 4.24.13 4.24.14 4.24.15 4.24.16 4.24.17 4.24.18 4.24.19 4.24.2 4.24.4 4.24.6 4.24.7 4.24.8 4.24.9 4.25.0 4.25.1 4.25.2 4.25.4 4.25.5 4.25.6 4.25.7 4.25.8 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 4.8.0 4.8.1 4.8.3 4.8.4 4.8.5 4.9.0 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.2.0 5.3.0 5.3.1 5.3.3 5.3.4 5.3.5 6.0.0 6.1.0 6.1.1 6.1.2 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.3.0 trunk 6.4.0 1.4 6.4.1 1.4.1 6.4.2 1.5 6.4.3 1.6 6.4.5 1.6.1 6.5.0 1.6.2 6.5.1 1.7 6.5.2 1.8 6.5.3 1.9 6.5.4 1.9.1 6.5.5 1.9.10 6.5.6 1.9.11 6.5.7 1.9.12 6.5.8 1.9.2 6.6.0 1.9.3 6.6.1 1.9.4 6.6.2 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.1 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.6 3.0.7 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.11.4 3.12.0 3.13.0 3.14.0 3.14.1 3.14.2 3.14.3 3.14.4 3.15.0 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.2.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.8.0 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.9 4.0.0 4.0.1 4.0.10 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.11.0 4.11.1 4.11.2 4.11.3 4.11.4 4.11.5 4.11.6 4.11.7 4.11.8 4.11.9 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.14.0 4.14.1 4.14.2 4.15.0 4.16.0 4.16.1 4.16.2 4.17.0 4.18.0 4.18.1 4.18.2 4.18.3 4.18.4 4.18.5 4.18.6 4.19.0 4.19.1 4.2.0 4.20.0 4.20.1 4.20.2 4.20.3 4.21.0 4.21.1 4.21.2 4.21.3 4.21.4 4.21.5
flexible-shipping / vendor_prefixed / wpdesk / wp-wpdesk-tracker / src / class-wpdesk-tracker.php
flexible-shipping / vendor_prefixed / wpdesk / wp-wpdesk-tracker / src Last commit date
Tracker 1 week ago assets 1 week ago data_provider 1 week ago persistence 1 week ago sender 1 week ago views 1 week ago class-wpdesk-tracker-factory-prefixed.php 1 week ago class-wpdesk-tracker-interface.php 1 week ago class-wpdesk-tracker.php 1 week ago
class-wpdesk-tracker.php
559 lines
1 <?php
2
3 namespace FSVendor;
4
5 /**
6 * WP Desk Tracker
7 *
8 * @class WPDESK_Tracker
9 * @version 1.3.2
10 * @package WPDESK/Helper
11 * @category Class
12 * @author WP Desk
13 */
14 if (!\defined('ABSPATH')) {
15 exit;
16 }
17 if (!\class_exists('FSVendor\WPDesk_Tracker')) {
18 /**
19 * Class WPDESK_Tracker
20 */
21 class WPDesk_Tracker implements \WPDesk_Tracker_Interface
22 {
23 public const ADMIN_HANDLER = 'wpdesk-helper-tracker';
24 public const ADMIN_LOCALIZE = 'wpdesk_tracker_localize';
25 public const ADMIN_NOTICE_HANDLER = 'wpdesk-helper-tracker-notice';
26 public const ADMIN_NOTICE_LOCALIZE = 'wpdesk_tracker_notice_localize';
27 public const ADMIN_PLUGINS_HANDLER = 'wpdesk-helper-plugins-notice';
28 public const ADMIN_PLUGINS_LOCALIZE = 'wpdesk_tracker_plugins_localize';
29 public const AJAX_ACTION = 'wpdesk_tracker_deactivation_handler';
30 public const AJAX_NONCE = 'nonce_wpdesk_tracker_deactivation_handler';
31 public const AJAX_NOTICE_ACTION = 'wpdesk_tracker_notice_handler';
32 public const WPDESK_TRACKER_NOTICE = 'wpdesk-tracker-notice';
33 public const WPDESK_TRACKER_DEACTIVATION = 'wpdesk-tracker-deactivation';
34 private const WPDESK_TRACKER_ACTION = 'wpdesk_tracker_action';
35 private const WPDESK_TRACKER_NONCE = 'nonce';
36 private const LEGACY_TRACKER_BUCKET = 'wpdesk';
37 /**
38 * Whether the global tracking notice has already been rendered for this request.
39 *
40 * @var bool
41 */
42 private static $global_notice_rendered = \false;
43 /**
44 * @var string
45 */
46 private $script_version = '11';
47 /**
48 * @var string
49 */
50 private $plugin_basename = '';
51 /**
52 * @var string
53 */
54 private $tracker_bucket;
55 /**
56 * @var string
57 */
58 private $message_version = '4';
59 /**
60 * @var WPDesk_Tracker_Data_Provider[]
61 */
62 private $providers = [];
63 /**
64 * @var WPDesk_Tracker_Sender
65 */
66 private $sender;
67 /**
68 * @deprecated do not use. This is for backward compatibility only.
69 */
70 public static function init($foo = null)
71 {
72 }
73 public function __construct($plugin_basename, \WPDesk_Tracker_Sender $sender, ?string $tracker_bucket = self::LEGACY_TRACKER_BUCKET)
74 {
75 $this->plugin_basename = $plugin_basename;
76 $this->tracker_bucket = $tracker_bucket ?: self::LEGACY_TRACKER_BUCKET;
77 $this->set_sender($sender);
78 }
79 /**
80 * Setter for object that sends data.
81 *
82 * @param WPDesk_Tracker_Sender $sender Object that can send payloads.
83 */
84 public function set_sender(\WPDesk_Tracker_Sender $sender)
85 {
86 $this->sender = $sender;
87 }
88 /**
89 * Hook into cron event.
90 */
91 public function init_hooks()
92 {
93 \add_action('admin_init', [$this, 'init_schedule']);
94 \add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts'], 100);
95 \add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_notice_scripts'], 100);
96 \add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_plugins_scripts'], 100);
97 \add_action('wpdesk_tracker_send_event', [$this, 'send_tracking_data']);
98 \add_action('admin_menu', [$this, 'admin_menu']);
99 \add_action('admin_init', [$this, 'admin_init']);
100 \add_action('admin_notices', [$this, 'admin_notices']);
101 \add_action('wp_ajax_wpdesk_tracker_notice_handler', [$this, 'wp_ajax_wpdesk_tracker_notice_handler']);
102 \add_action('wp_ajax_wpdesk_tracker_deactivation_handler', [$this, 'wp_ajax_wpdesk_tracker_deactivation_handler']);
103 \add_action('update_option_wpdesk_helper_options', [$this, 'update_option_wpdesk_helper_options'], 10, 3);
104 \add_filter('option_wpdesk_helper_options', [$this, 'option_wpdesk_helper_options'], 10, 2);
105 \add_filter('default_option_wpdesk_helper_options', [$this, 'default_option_wpdesk_helper_options'], 10, 3);
106 $this->init_payload_hooks();
107 \add_action('admin_bar_menu', [$this, 'admin_bar_menu'], 999);
108 }
109 /**
110 * Registers hooks required to format the tracking payload.
111 *
112 * @return void
113 */
114 public function init_payload_hooks()
115 {
116 \add_filter('wpdesk_tracker_data', [$this, 'wpdesk_tracker_message_version']);
117 }
118 public function add_data_provider(\WPDesk_Tracker_Data_Provider $provider)
119 {
120 $this->providers[] = $provider;
121 }
122 /**
123 * @param WP_Admin_Bar $wp_admin_bar
124 */
125 public function admin_bar_menu($wp_admin_bar)
126 {
127 if (\apply_filters('wpdesk_tracker_use_testdata', \false) && \apply_filters('wpdesk_tracker_show_testdata', \false)) {
128 $args = ['id' => 'my_page', 'title' => 'WP Desk Test!', 'meta' => ['class' => 'wpdesk-tracker-test']];
129 $wp_admin_bar->add_node($args);
130 }
131 }
132 public function init_schedule()
133 {
134 self::schedule();
135 }
136 /**
137 * Register or remove the global tracker schedule based on consent.
138 *
139 * @return void
140 */
141 public static function schedule()
142 {
143 $options = \get_option('wpdesk_helper_options');
144 if (!\is_array($options)) {
145 $options = [];
146 }
147 if (empty($options['wpdesk_tracker_agree'])) {
148 $options['wpdesk_tracker_agree'] = '0';
149 }
150 $wpdesk_tracker_agree = $options['wpdesk_tracker_agree'];
151 $wp_next_scheduled = \wp_next_scheduled('wpdesk_tracker_send_event');
152 if ($wpdesk_tracker_agree == '1' && !$wp_next_scheduled) {
153 \wp_schedule_event(\time(), 'daily', 'wpdesk_tracker_send_event');
154 }
155 if ($wpdesk_tracker_agree == '0' && $wp_next_scheduled) {
156 \wp_clear_scheduled_hook('wpdesk_tracker_send_event');
157 }
158 }
159 /**
160 * @return bool
161 */
162 private function should_enable_wpdesk_tracker()
163 {
164 return \apply_filters('wpdesk_tracker_enabled', \true);
165 }
166 public function admin_enqueue_plugins_scripts(): void
167 {
168 global $pagenow;
169 if ('plugins.php' === $pagenow && !\is_network_admin() && $this->should_enable_wpdesk_tracker() && !\apply_filters('wpdesk_tracker_do_not_ask', \false)) {
170 \wp_register_script(self::ADMIN_PLUGINS_HANDLER, \plugin_dir_url(__FILE__) . 'assets/js/admin_plugins.js', [], $this->script_version);
171 \wp_enqueue_script(self::ADMIN_PLUGINS_HANDLER);
172 $plugins = ['wpdesk-helper/wpdesk-helper.php' => 'wpdesk-helper/wpdesk-helper.php'];
173 $plugins = \apply_filters('wpdesk_track_plugin_deactivation', $plugins);
174 \wp_localize_script(self::ADMIN_PLUGINS_HANDLER, self::ADMIN_PLUGINS_LOCALIZE, ['plugins' => \wp_json_encode($plugins), 'base_url' => \esc_url_raw(\wp_nonce_url(\admin_url("admin.php?page=wpdesk_tracker_deactivate"), self::WPDESK_TRACKER_ACTION, self::WPDESK_TRACKER_NONCE))]);
175 }
176 }
177 public function admin_enqueue_scripts(): void
178 {
179 $screen = \get_current_screen();
180 if ($screen->id === 'admin_page_wpdesk_tracker' || $screen->id === 'admin_page_wpdesk_tracker_deactivate') {
181 \wp_register_style(self::ADMIN_HANDLER, \plugin_dir_url(__FILE__) . 'assets/css/tracker.css', [], $this->script_version, 'all');
182 \wp_enqueue_style(self::ADMIN_HANDLER);
183 \wp_register_script(self::ADMIN_HANDLER, \plugin_dir_url(__FILE__) . 'assets/js/admin.js', [], $this->script_version);
184 \wp_enqueue_script(self::ADMIN_HANDLER);
185 $plugin = '';
186 $plugin_name = '';
187 if (\current_user_can('activate_plugins') && \false !== \check_ajax_referer(self::WPDESK_TRACKER_ACTION, self::WPDESK_TRACKER_NONCE, \false)) {
188 $plugin = \sanitize_text_field(\wp_unslash($_GET['plugin'] ?? ''));
189 $active_plugins = \get_plugins();
190 $plugin_name = $active_plugins[$plugin]['Name'] ?? '';
191 }
192 $deactivation_plugins = ['wpdesk-helper/wpdesk-helper.php' => 'wpdesk-helper/wpdesk-helper.php'];
193 $deactivation_plugins = \apply_filters('wpdesk_track_plugin_deactivation', $deactivation_plugins);
194 \wp_localize_script(self::ADMIN_HANDLER, self::ADMIN_LOCALIZE, ['action' => \esc_attr(self::AJAX_ACTION), 'nonce' => \wp_create_nonce(self::AJAX_NONCE), 'ajax_url' => \esc_url_raw(\admin_url('admin-ajax.php')), 'tracker_page' => \esc_url_raw(\str_replace("&amp;", "&", \admin_url(\wp_nonce_url("plugins.php?action=deactivate&plugin=" . $plugin . "&plugin_status=all&", "deactivate-plugin_" . $plugin)))), 'plugin' => \esc_attr($plugin), 'plugin_name' => \esc_attr($plugin_name), 'submit_txt' => \esc_html__("Submit &amp; Deactivate", "flexible-shipping"), 'deactivation_plugins' => \wp_json_encode($deactivation_plugins)]);
195 }
196 }
197 private function is_notices_enabled(): bool
198 {
199 if (!$this->should_enable_wpdesk_tracker()) {
200 return \false;
201 }
202 if (!\current_user_can('activate_plugins')) {
203 return \false;
204 }
205 if (\get_option('wpdesk_tracker_notice', '0') != 'dismiss_all') {
206 $options = \get_option('wpdesk_helper_options', []);
207 if (!\is_array($options)) {
208 $options = [];
209 }
210 if (empty($options['wpdesk_tracker_agree']) || $options['wpdesk_tracker_agree'] == '0') {
211 if ($this->can_display_notice()) {
212 return \true;
213 }
214 }
215 }
216 return \false;
217 }
218 public function admin_enqueue_notice_scripts(): void
219 {
220 if ($this->is_notices_enabled()) {
221 \wp_register_script(self::ADMIN_NOTICE_HANDLER, \plugin_dir_url(__FILE__) . 'assets/js/admin_notices.js', [], $this->script_version);
222 \wp_enqueue_script(self::ADMIN_NOTICE_HANDLER);
223 \wp_localize_script(self::ADMIN_NOTICE_HANDLER, self::ADMIN_NOTICE_LOCALIZE, ['action' => \esc_attr(self::AJAX_NOTICE_ACTION), 'nonce' => \wp_create_nonce(self::WPDESK_TRACKER_NOTICE), 'ajax_url' => \esc_url_raw(\admin_url('admin-ajax.php')), 'plugin' => \esc_attr($this->plugin_basename)]);
224 }
225 }
226 public function admin_menu()
227 {
228 \add_submenu_page('wpdesk_tracker', 'WP Desk Tracker', 'WP Desk Tracker', 'manage_options', 'wpdesk_tracker', [$this, 'wpdesk_tracker_page']);
229 \add_submenu_page('wpdesk_tracker', 'Deactivate plugin', 'Deactivate plugin', 'manage_options', 'wpdesk_tracker_deactivate', [$this, 'wpdesk_tracker_deactivate']);
230 }
231 public function wp_ajax_wpdesk_tracker_deactivation_handler()
232 {
233 \check_ajax_referer(self::WPDESK_TRACKER_DEACTIVATION, 'security');
234 if (!\current_user_can('activate_plugins')) {
235 die;
236 }
237 $this->send_deactivation_data();
238 }
239 public function wp_ajax_wpdesk_tracker_notice_handler()
240 {
241 \check_ajax_referer(self::WPDESK_TRACKER_NOTICE, 'security');
242 if (!\current_user_can('activate_plugins')) {
243 die;
244 }
245 $option = \get_option('wpdesk_helper_options');
246 if (!$option) {
247 \add_option('wpdesk_helper_options', []);
248 }
249 $type = '';
250 if (isset($_REQUEST['type'])) {
251 $type = \sanitize_key($_REQUEST['type']);
252 }
253 if ($type === 'allow') {
254 $options = \get_option('wpdesk_helper_options', []);
255 if (!\is_array($options)) {
256 $options = [];
257 }
258 \update_option('wpdesk_helper_options', $options);
259 \delete_option('wpdesk_tracker_notice');
260 $options['wpdesk_tracker_agree'] = '1';
261 \update_option('wpdesk_helper_options', $options);
262 }
263 if ($type === 'dismiss') {
264 $options = \get_option('wpdesk_helper_options', []);
265 if (!\is_array($options)) {
266 $options = [];
267 }
268 \update_option('wpdesk_tracker_notice', 'dismiss_all');
269 $options['wpdesk_tracker_agree'] = '0';
270 \update_option('wpdesk_helper_options', $options);
271 }
272 }
273 public function update_option_wpdesk_helper_options($old_value, $value, $option)
274 {
275 if (empty($old_value)) {
276 $old_value = ['wpdesk_tracker_agree' => '-1'];
277 }
278 if (!isset($old_value['wpdesk_tracker_agree'])) {
279 $old_value['wpdesk_tracker_agree'] = '-1';
280 }
281 if (empty($value)) {
282 $value = ['wpdesk_tracker_agree' => '-1'];
283 }
284 if (!isset($value['wpdesk_tracker_agree'])) {
285 $value['wpdesk_tracker_agree'] = '-1';
286 }
287 if ($old_value['wpdesk_tracker_agree'] != '1') {
288 if ($value['wpdesk_tracker_agree'] == '1') {
289 $this->send_tracking_data(\true, 'agree', $this->read_context_from_request());
290 }
291 }
292 if ($old_value['wpdesk_tracker_agree'] != '0') {
293 if ($value['wpdesk_tracker_agree'] == '0') {
294 $this->send_tracking_data(\true, 'no', $this->read_context_from_request());
295 \update_option('wpdesk_tracker_notice', 'dismiss_all');
296 }
297 }
298 }
299 public function option_wpdesk_helper_options($value, $option)
300 {
301 if (\apply_filters('wpdesk_tracker_do_not_ask', \false)) {
302 if (!\is_array($value)) {
303 $value = [];
304 }
305 $value['wpdesk_tracker_agree'] = 1;
306 }
307 return $value;
308 }
309 public function default_option_wpdesk_helper_options($default, $option = null, $passed_default = null)
310 {
311 if (\apply_filters('wpdesk_tracker_do_not_ask', \false)) {
312 $default = [];
313 $default['wpdesk_tracker_agree'] = 1;
314 }
315 return $default;
316 }
317 public function admin_notices()
318 {
319 if ($this->is_notices_enabled() && !self::$global_notice_rendered) {
320 self::$global_notice_rendered = \true;
321 $user = \wp_get_current_user();
322 $username = $user->first_name ? $user->first_name : $user->user_login;
323 $terms_url = \get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/dane-uzytkowania/' : 'https://www.wpdesk.net/usage-tracking/';
324 include 'views/tracker-notice.php';
325 }
326 if (isset($_GET['wpdesk_tracker_opt_out']) && \current_user_can('activate_plugins') && $this->should_enable_wpdesk_tracker()) {
327 $options = \get_option('wpdesk_helper_options', []);
328 if (!\is_array($options)) {
329 $options = [];
330 }
331 \delete_option('wpdesk_tracker_notice');
332 $options['wpdesk_tracker_agree'] = '0';
333 \update_option('wpdesk_helper_options', $options);
334 include 'views/tracker-opt-out-notice.php';
335 }
336 }
337 public function wpdesk_tracker_page()
338 {
339 $nonce = \wp_create_nonce(self::WPDESK_TRACKER_ACTION);
340 $user = \wp_get_current_user();
341 $username = $user->first_name ? $user->first_name : $user->user_login;
342 $allow_url = \admin_url('admin.php?page=wpdesk_tracker');
343 $allow_url = \add_query_arg('plugin', \sanitize_text_field(\wp_unslash($_GET['plugin'] ?? '')), $allow_url);
344 $allow_url = \add_query_arg(self::WPDESK_TRACKER_NONCE, $nonce, $allow_url);
345 $skip_url = $allow_url;
346 $allow_url = \add_query_arg('allow', '1', $allow_url);
347 $skip_url = \add_query_arg('allow', '0', $skip_url);
348 $terms_url = \get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/dane-uzytkowania/' : 'https://www.wpdesk.net/usage-tracking/';
349 include 'views/tracker-connect.php';
350 }
351 public function wpdesk_tracker_deactivate()
352 {
353 if (!\current_user_can('activate_plugins') || \false === \check_ajax_referer(self::WPDESK_TRACKER_ACTION, self::WPDESK_TRACKER_NONCE)) {
354 die;
355 }
356 if (!$this->applies_to_current_plugin()) {
357 return;
358 }
359 $user = \wp_get_current_user();
360 $username = $user->first_name;
361 $plugin = \sanitize_text_field(\wp_unslash($_GET['plugin'] ?? ''));
362 $active_plugins = \get_plugins();
363 $plugin_name = $active_plugins[$plugin]['Name'];
364 include 'views/tracker-deactivate.php';
365 }
366 public function admin_init()
367 {
368 if (isset($_GET['page']) && $_GET['page'] === 'wpdesk_tracker') {
369 if (isset($_GET['plugin']) && isset($_GET['allow'])) {
370 if (!\current_user_can('activate_plugins') || \false === \check_ajax_referer(self::WPDESK_TRACKER_ACTION, self::WPDESK_TRACKER_NONCE)) {
371 die;
372 }
373 $options = \get_option('wpdesk_helper_options', []);
374 if (!\is_array($options)) {
375 $options = [];
376 }
377 if ($_GET['allow'] == '0') {
378 \remove_action('update_option_wpdesk_helper_options', [$this, 'update_option_wpdesk_helper_options'], 10);
379 unset($options['wpdesk_tracker_agree']);
380 \update_option('wpdesk_helper_options', $options);
381 \add_action('update_option_wpdesk_helper_options', [$this, 'update_option_wpdesk_helper_options'], 10, 3);
382 $options['wpdesk_tracker_agree'] = '0';
383 \update_option('wpdesk_helper_options', $options);
384 \update_option('wpdesk_tracker_notice', '1');
385 } else {
386 \remove_action('update_option_wpdesk_helper_options', [$this, 'update_option_wpdesk_helper_options'], 10);
387 unset($options['wpdesk_tracker_agree']);
388 \update_option('wpdesk_helper_options', $options);
389 \add_action('update_option_wpdesk_helper_options', [$this, 'update_option_wpdesk_helper_options'], 10, 3);
390 \delete_option('wpdesk_tracker_notice');
391 \update_option('wpdesk_tracker_agree', '1');
392 $options['wpdesk_tracker_agree'] = '1';
393 \update_option('wpdesk_helper_options', $options);
394 }
395 \wp_safe_redirect(\admin_url('plugins.php'));
396 exit;
397 }
398 }
399 }
400 public function wpdesk_tracker_message_version($data)
401 {
402 $data['message_version'] = $this->message_version;
403 return $data;
404 }
405 public function send_deactivation_data()
406 {
407 if (!isset($_REQUEST['plugin'], $_REQUEST['plugin_name'], $_REQUEST['reason'])) {
408 return;
409 }
410 $params = [];
411 $params['click_action'] = 'plugin_deactivation';
412 $params['plugin'] = \sanitize_text_field(\wp_unslash($_REQUEST['plugin']));
413 $params['plugin_name'] = \sanitize_text_field(\wp_unslash($_REQUEST['plugin_name']));
414 $params['reason'] = \sanitize_text_field(\wp_unslash($_REQUEST['reason']));
415 if (!empty($_REQUEST['additional_info'])) {
416 $params['additional_info'] = \sanitize_text_field(\wp_unslash($_REQUEST['additional_info']));
417 }
418 $this->send_payload_to_wpdesk(\apply_filters('wpdesk_tracker_deactivation_data', $params));
419 }
420 /**
421 * Decide whether to send tracking data or not.
422 *
423 * @param boolean $override
424 */
425 public function send_tracking_data($override = \false, $click_action = null, array $additional_data = [])
426 {
427 $options = \get_option('wpdesk_helper_options', []);
428 if (empty($options)) {
429 $options = [];
430 }
431 if (empty($options['wpdesk_tracker_agree'])) {
432 $options['wpdesk_tracker_agree'] = '0';
433 }
434 if (empty($click_action) && $options['wpdesk_tracker_agree'] == '0') {
435 return;
436 }
437 if (!$this->should_enable_wpdesk_tracker()) {
438 return;
439 }
440 if (!\apply_filters('wpdesk_tracker_send_override', $override)) {
441 // Send a maximum of once per week by default.
442 $last_send = $this->get_last_send_time();
443 if ($last_send && $last_send > \apply_filters('wpdesk_tracker_last_send_interval', \strtotime('-1 week'))) {
444 return;
445 }
446 } else {
447 // Make sure there is at least a 1 hour delay between override sends, we dont want duplicate calls due to double clicking links.
448 $last_send = $this->get_last_send_time();
449 if (empty($click_action) && $last_send && $last_send > \strtotime('-1 hours')) {
450 return;
451 }
452 }
453 // Update time first before sending to ensure it is set.
454 \update_option($this->get_last_send_option_name(), \time());
455 if (empty($click_action) || $click_action === 'agree') {
456 $params = $this->get_tracking_data();
457 if (isset($params['active_plugins'])) {
458 foreach ($params['active_plugins'] as $plugin => $plugin_data) {
459 $option_name = 'activation_plugin_' . $plugin;
460 $activation_date = \get_option($option_name, '');
461 if ($activation_date != '') {
462 $params['active_plugins'][$plugin]['activation_date'] = $activation_date;
463 }
464 }
465 }
466 if (!empty($click_action)) {
467 $params['click_action'] = 'agree';
468 }
469 } else {
470 $params = ['click_action' => 'no'];
471 $params['url'] = \home_url();
472 }
473 $params['localhost'] = 'no';
474 if (!empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] === '127.0.0.1') {
475 $params['localhost'] = 'yes';
476 }
477 $this->send_payload_to_wpdesk(\array_merge($params, $additional_data));
478 }
479 /**
480 * Sends payload to WPDesk servers.
481 *
482 * @param array $payload Payload to sent.
483 *
484 * @return bool If sending was successfull.
485 */
486 private function send_payload_to_wpdesk(array $payload)
487 {
488 try {
489 $this->sender->send_payload($payload);
490 return \true;
491 } catch (WPDesk_Tracker_Sender_Exception_WpError $e) {
492 return \false;
493 }
494 }
495 /**
496 * Get the last time tracking data was sent.
497 *
498 * @return int|bool
499 */
500 private function get_last_send_time()
501 {
502 $last_send = \get_option($this->get_last_send_option_name(), \false);
503 if (self::LEGACY_TRACKER_BUCKET === $this->tracker_bucket) {
504 return \apply_filters('wpdesk_tracker_last_send_time', $last_send);
505 }
506 return $last_send;
507 }
508 private function get_last_send_option_name(): string
509 {
510 if (self::LEGACY_TRACKER_BUCKET === $this->tracker_bucket) {
511 return 'wpdesk_tracker_last_send';
512 }
513 return 'wpdesk_tracker_last_send_' . $this->tracker_bucket;
514 }
515 /**
516 * @return array
517 */
518 private function get_data_from_providers()
519 {
520 $data = [];
521 if (!empty($this->providers)) {
522 foreach ($this->providers as $provider) {
523 $data = \array_merge($data, $provider->get_data());
524 }
525 }
526 return $data;
527 }
528 /**
529 * Get all the tracking data.
530 *
531 * @return array
532 */
533 private function get_tracking_data()
534 {
535 $data = $this->get_data_from_providers();
536 return \apply_filters('wpdesk_tracker_data', $data);
537 }
538 private function read_context_from_request(): array
539 {
540 if (isset($_REQUEST['ctx'], $_REQUEST['plugin'])) {
541 return ['source' => ['plugin' => \sanitize_key($_REQUEST['plugin']), 'ctx' => \sanitize_key($_REQUEST['ctx'])]];
542 }
543 return [];
544 }
545 private function can_display_notice(): bool
546 {
547 if (\has_filter('wpdesk_tracker_notice_screens') === \true) {
548 $screen = \get_current_screen();
549 return \in_array($screen->id, \apply_filters('wpdesk_tracker_notice_screens', []), \true);
550 }
551 return \true;
552 }
553 private function applies_to_current_plugin(): bool
554 {
555 return \strpos(\sanitize_text_field(\wp_unslash($_GET['plugin'] ?? '')), $this->plugin_basename);
556 }
557 }
558 }
559