PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.72
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.72
9.1.3 9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 All 222 releases
wpvr / vendor / linno / telemetry / src / Consent.php

Consent.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.72, at vendor/linno/telemetry/src/Consent.php

157 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace LinnoSDK\Telemetry;
3
4 class Consent {
5 /**
6 * Client instance
7 *
8 * @var Client
9 */
10 private Client $client;
11
12 /**
13 * Text domain for i18n
14 *
15 * @var string
16 */
17 private string $textDomain;
18
19 /**
20 * Constructor
21 *
22 * @param Client $client
23 */
24 public function __construct( Client $client ) {
25 $this->client = $client;
26 $this->textDomain = $client->get_text_domain();
27 }
28
29 /**
30 * Initialize the consent functionality
31 *
32 * @return void
33 */
34 public function init(): void {
35 add_action( 'admin_init', array( $this, 'handle_optin_optout' ) );
36 add_action( 'admin_notices', array( $this, 'show_consent_notice' ) );
37 }
38
39 /**
40 * Handle the user's opt-in/opt-out choice
41 *
42 * @return void
43 */
44 public function handle_optin_optout(): void {
45 if ( ! isset( $_GET['action'] ) || ! isset( $_GET['plugin'] ) ) {
46 return;
47 }
48
49 if ( $_GET['plugin'] !== $this->client->get_slug() ) {
50 return;
51 }
52
53 if ( $_GET['action'] === 'optin' ) {
54 $this->client->set_optin_state( 'yes' );
55 $this->dismiss_notice();
56
57 // Explicitly call activate() to ensure table is created and flags are set.
58 // Since we just set optin to 'yes', activate() will now track the 'plugin_activated' event.
59 $this->client->activate();
60 }
61
62 if ( $_GET['action'] === 'optout' ) {
63 $this->client->set_optin_state( 'no' );
64 $this->dismiss_notice();
65 }
66
67 wp_safe_redirect( remove_query_arg( array( 'action', 'plugin' ) ) );
68 exit;
69 }
70
71 /**
72 * Show the consent notice
73 *
74 * @return void
75 */
76 public function show_consent_notice(): void {
77 if ( $this->is_notice_dismissed() ) {
78 return;
79 }
80
81 // Don't show the notice if the user has already opted in or out
82 if ( null !== $this->client->get_optin_state() ) {
83 return;
84 }
85
86 $plugin_name = $this->client->get_plugin_name();
87
88 $optin_url = add_query_arg( array(
89 'action' => 'optin',
90 'plugin' => $this->client->get_slug(),
91 ) );
92
93 $optout_url = add_query_arg( array(
94 'action' => 'optout',
95 'plugin' => $this->client->get_slug(),
96 ) );
97
98 ?>
99 <div class="notice notice-info">
100 <p>
101 <?php
102 $privacy_policy_url = apply_filters(
103 $this->client->get_slug() . '_telemetry_privacy_policy_url',
104 $this->client->get_privacy_url()
105 );
106 $consent_service_name = apply_filters(
107 $this->client->get_slug() . '_telemetry_consent_service_name',
108 $this->client->get_consent_service_name()
109 );
110 $message = apply_filters(
111 $this->client->get_slug() . '_telemetry_consent_message',
112 sprintf(
113 __( 'Help us improve %1$s. With your permission, this plugin sends usage and technical data to %3$s, including: site URL, plugin name and version, event timestamps, anonymous site profile ID, custom event properties, and your current admin profile details (email, first name, last name, and avatar) for identification and product support. Tracking is off by default. <a href="%2$s" target="_blank" rel="noopener noreferrer">Learn more</a>.', $this->textDomain ),
114 '<strong>' . $plugin_name . '</strong>',
115 esc_url( $privacy_policy_url ),
116 esc_html( $consent_service_name )
117 )
118 );
119
120 echo '<p>' . $message . '</p>';
121 ?>
122 <p>
123 <a href="<?php echo esc_url( $optin_url ); ?>" class="button-primary"><?php _e( 'Allow', $this->textDomain ); ?></a>
124 <a href="<?php echo esc_url( $optout_url ); ?>" class="button-secondary"><?php _e( 'Do not allow', $this->textDomain ); ?></a>
125 </p>
126 </div>
127 <?php
128 }
129
130 /**
131 * Check if the notice has been dismissed
132 *
133 * @return bool
134 */
135 private function is_notice_dismissed(): bool {
136 return 'yes' === get_option( $this->get_notice_dismissed_key() );
137 }
138
139 /**
140 * Dismiss the notice
141 *
142 * @return void
143 */
144 private function dismiss_notice(): void {
145 update_option( $this->get_notice_dismissed_key(), 'yes' );
146 }
147
148 /**
149 * Get the option key for dismissing the notice
150 *
151 * @return string
152 */
153 private function get_notice_dismissed_key(): string {
154 return $this->client->get_notice_dismissed_key();
155 }
156 }
157