PluginProbe
Blocks – Reusable Content, Shortcodes & Site Variables / trunk
Blocks – Reusable Content, Shortcodes & Site Variables vtrunk
26.09.03.15 26.08.31.21 26.08.22.20 26.08.22.22 26.08.22.17 26.08.22.13 26.08.21.19 26.08.07.23 26.07.19.14 26.07.13.21 26.07.13.17 26.07.12.13 026.07.07.21 026.07.05.18 026.06.26.20 026.06.26.21 026.06.08.20 026.05.13.14 026.04.29.10 trunk 026.02.22.22 026.03.16.23 026.04.23.13
blocks / includes / signls / src / Consent.php

Consent.php in Blocks – Reusable Content, Shortcodes & Site Variables trunk, at includes/signls/src/Consent.php

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Explicit product consent state.
4 *
5 * @package signls-sdk
6 * @license GPL-3.0-or-later
7 */
8
9 namespace Signls\Sdk\V1;
10
11 defined( 'ABSPATH' ) || exit;
12
13 final class Consent {
14
15 const VERSION = 1;
16
17 private $state;
18
19 public function __construct( StateStore $state ) {
20 $this->state = $state;
21 }
22
23 public function status(): string {
24 $status = (string) $this->state->get( 'consent_status', 'unset' );
25 return in_array( $status, array( 'unset', 'enabled', 'disabled' ), true ) ? $status : 'unset';
26 }
27
28 public function enabled(): bool {
29 return 'enabled' === $this->status();
30 }
31
32 public function enable( string $source, int $notice_version ): bool {
33 $now = time();
34 $first_enabled = (int) $this->state->get( 'consent_first_enabled_at', 0 );
35 if ( $first_enabled <= 0 ) {
36 $first_enabled = $now;
37 }
38
39 return $this->state->set_many(
40 array(
41 'consent_status' => 'enabled',
42 'consent_version' => self::VERSION,
43 'consent_first_enabled_at' => $first_enabled,
44 'consent_last_changed_at' => $now,
45 'consent_source' => Sanitizer::slug( $source, 48, 'unknown' ),
46 'consent_notice_version' => max( 1, $notice_version ),
47 )
48 );
49 }
50
51 public function disable( string $source, int $notice_version ): bool {
52 return $this->state->set_many(
53 array(
54 'consent_status' => 'disabled',
55 'consent_version' => self::VERSION,
56 'consent_last_changed_at' => time(),
57 'consent_source' => Sanitizer::slug( $source, 48, 'unknown' ),
58 'consent_notice_version' => max( 1, $notice_version ),
59 )
60 );
61 }
62 }
63