PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.17
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.17
1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 All 162 releases
woocommerce-pos / includes / Services / Anon_ID.php

Anon_ID.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.17, at includes/Services/Anon_ID.php

63 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Anonymous analytics identity for the wp-admin landing page.
4 *
5 * Owns the `wcpos_anon_id` option: a random v4 UUID that keys experiment
6 * assignment for sites that have NOT consented to profile tracking. It is
7 * never derived from the URL or site data (landing-experiments spec §5.1).
8 *
9 * @package WCPOS\WooCommercePOS\Services
10 */
11
12 namespace WCPOS\WooCommercePOS\Services;
13
14 /**
15 * Anon_ID service.
16 */
17 class Anon_ID {
18 /**
19 * Option name. Program-wide identifier — the wcpos.com reconciler and the
20 * landing bootstrap both refer to it by this name; do not rename.
21 */
22 const OPTION = 'wcpos_anon_id';
23
24 /**
25 * Returns the stored anon id, creating one on first use.
26 *
27 * @return string v4 UUID.
28 */
29 public function get(): string {
30 $id = get_option( self::OPTION );
31
32 if ( ! \is_string( $id ) || '' === $id ) {
33 $id = wp_generate_uuid4();
34 // Autoload off: only the landing page (and WP-CLI) ever reads it.
35 if ( ! add_option( self::OPTION, $id, '', false ) ) {
36 // Lost a first-load race — return the persisted winner, never a stray id.
37 $id = (string) get_option( self::OPTION );
38 }
39 }
40
41 return $id;
42 }
43
44 /**
45 * Replaces the stored id with a fresh UUID (privacy affordance).
46 *
47 * @return string The new v4 UUID.
48 */
49 public function rotate(): string {
50 $id = wp_generate_uuid4();
51 update_option( self::OPTION, $id, false );
52
53 return $id;
54 }
55
56 /**
57 * Deletes the stored id (privacy affordance; also run on uninstall).
58 */
59 public function delete(): void {
60 delete_option( self::OPTION );
61 }
62 }
63