client = $client; $this->textDomain = $client->get_text_domain(); } /** * Initialize the consent functionality * * @return void */ public function init(): void { add_action( 'admin_init', array( $this, 'handle_optin_optout' ) ); add_action( 'admin_notices', array( $this, 'show_consent_notice' ) ); } /** * Handle the user's opt-in/opt-out choice * * @return void */ public function handle_optin_optout(): void { if ( ! isset( $_GET['action'] ) || ! isset( $_GET['plugin'] ) ) { return; } if ( $_GET['plugin'] !== $this->client->get_slug() ) { return; } if ( $_GET['action'] === 'optin' ) { $this->client->set_optin_state( 'yes' ); $this->dismiss_notice(); // Explicitly call activate() to ensure table is created and flags are set. // Since we just set optin to 'yes', activate() will now track the 'plugin_activated' event. $this->client->activate(); } if ( $_GET['action'] === 'optout' ) { $this->client->set_optin_state( 'no' ); $this->dismiss_notice(); } wp_safe_redirect( remove_query_arg( array( 'action', 'plugin' ) ) ); exit; } /** * Show the consent notice * * @return void */ public function show_consent_notice(): void { if ( $this->is_notice_dismissed() ) { return; } // Don't show the notice if the user has already opted in or out if ( null !== $this->client->get_optin_state() ) { return; } $plugin_name = $this->client->get_plugin_name(); $optin_url = add_query_arg( array( 'action' => 'optin', 'plugin' => $this->client->get_slug(), ) ); $optout_url = add_query_arg( array( 'action' => 'optout', 'plugin' => $this->client->get_slug(), ) ); ?>
client->get_slug() . '_telemetry_privacy_policy_url', $this->client->get_privacy_url() ); $consent_service_name = apply_filters( $this->client->get_slug() . '_telemetry_consent_service_name', $this->client->get_consent_service_name() ); $message = apply_filters( $this->client->get_slug() . '_telemetry_consent_message', sprintf( __( '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. Learn more.', $this->textDomain ), '' . $plugin_name . '', esc_url( $privacy_policy_url ), esc_html( $consent_service_name ) ) ); echo '
' . $message . '
'; ?>