| @@ -21,8 +21,17 @@ | ||
| 21 | 21 | return 'general'; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | + * Read by the Settings service on every request, so it rides in alloptions. | |
| 26 | + * | |
| 27 | + * @return bool | |
| 28 | + */ | |
| 29 | + public function autoload(): bool { | |
| 30 | + return true; | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 25 | 34 | * Section defaults. |
| 26 | 35 | */ |
| 27 | 36 | public function defaults(): array { |
| 28 | 37 | return array( |
| @@ -42,8 +51,36 @@ | ||
| 42 | 51 | 'store_email' => '', |
| 43 | 52 | 'policies_and_conditions' => '', |
| 44 | 53 | 'store_tax_ids' => array(), |
| 45 | 54 | ); |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * The PERSISTED tracking consent, bypassing the read view. | |
| 59 | + * | |
| 60 | + * `read()` ends by applying `woocommerce_pos_general_settings`, so the | |
| 61 | + * ordinary accessor lets any plugin filtering that hook manufacture a | |
| 62 | + * consent the merchant never gave. Telemetry send-gates must ask the | |
| 63 | + * database instead. Still runs `migrate()`, so a merchant whose choice | |
| 64 | + * predates the move out of the legacy `tools` option is honoured rather | |
| 65 | + * than silently switched off. | |
| 66 | + * | |
| 67 | + * Display and UI reads keep using the filtered accessor. | |
| 68 | + * | |
| 69 | + * Falls back to the section default rather than an empty string: the value | |
| 70 | + * is mirrored to the POS client, whose schema expects one of the three | |
| 71 | + * states, and `undecided` is the fail-closed one. | |
| 72 | + * | |
| 73 | + * @return string One of allowed|denied|undecided. | |
| 74 | + */ | |
| 75 | + public function raw_tracking_consent(): string { | |
| 76 | + $raw = $this->migrate( $this->read_raw() ); | |
| 77 | + $defaults = $this->defaults(); | |
| 78 | + $fallback = \is_string( $defaults['tracking_consent'] ?? null ) ? $defaults['tracking_consent'] : 'undecided'; | |
| 79 | + | |
| 80 | + $consent = $raw['tracking_consent'] ?? $fallback; | |
| 81 | + | |
| 82 | + return \is_string( $consent ) ? $consent : $fallback; | |
| 46 | 83 | } |
| 47 | 84 | |
| 48 | 85 | /** |
| 49 | 86 | * Migrate tracking_consent from the legacy `tools` option if it was set |