1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* A Terms of Service class for Jetpack. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-terms-of-service |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack; |
9
|
|
|
|
10
|
|
|
use Automattic\Jetpack\Status; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Terms_Of_Service |
14
|
|
|
* |
15
|
|
|
* Helper class that is responsible for the state of agreement of the terms of service. |
16
|
|
|
*/ |
17
|
|
|
class Terms_Of_Service { |
18
|
|
|
/** |
19
|
|
|
* Jetpack option name where the terms of service state is stored. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
const OPTION_NAME = 'tos_agreed'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Allow the site to agree to the terms of service. |
27
|
|
|
*/ |
28
|
|
|
public function agree() { |
29
|
|
|
$this->set_agree(); |
30
|
|
|
/** |
31
|
|
|
* Acton fired when the master user has agreed to the terms of service. |
32
|
|
|
* |
33
|
|
|
* @since 7.9.0 |
34
|
|
|
*/ |
35
|
|
|
do_action( 'jetpack_agreed_to_terms_of_service' ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Allow the site to reject to the terms of service. |
40
|
|
|
*/ |
41
|
|
|
public function reject() { |
42
|
|
|
$this->set_reject(); |
43
|
|
|
/** |
44
|
|
|
* Acton fired when the master user has revoked their agreement to the terms of service. |
45
|
|
|
* |
46
|
|
|
* @since 7.9.1 |
47
|
|
|
*/ |
48
|
|
|
do_action( 'jetpack_reject_terms_of_service' ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns whether the master user has agreed to the terms of service. |
53
|
|
|
* |
54
|
|
|
* The following conditions have to be met in order to agree to the terms of service. |
55
|
|
|
* 1. The master user has gone though the connect flow. |
56
|
|
|
* 2. The site is not in dev mode. |
57
|
|
|
* 3. The master user of the site is still connected (deprecated @since 8.9.0). |
58
|
|
|
* |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function has_agreed() { |
62
|
|
|
if ( $this->is_offline_mode() ) { |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
/** |
66
|
|
|
* Before 8.9.0 we used to also check if the master user of the site is connected |
67
|
|
|
* by calling the Connection related `is_active` method. |
68
|
|
|
* As of 8.9.0 we have removed this check in order to resolve the |
69
|
|
|
* circular dependencies it was introducing to composer packages. |
70
|
|
|
* |
71
|
|
|
* @since 8.9.0 |
72
|
|
|
*/ |
73
|
|
|
return $this->get_raw_has_agreed(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Abstracted for testing purposes. |
78
|
|
|
* Tells us if the site is in dev mode. |
79
|
|
|
* |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
|
|
protected function is_offline_mode() { |
83
|
|
|
return ( new Status() )->is_offline_mode(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Gets just the Jetpack Option that contains the terms of service state. |
88
|
|
|
* Abstracted for testing purposes. |
89
|
|
|
* |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
protected function get_raw_has_agreed() { |
93
|
|
|
return \Jetpack_Options::get_option( self::OPTION_NAME, false ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Sets the correct Jetpack Option to mark the that the site has agreed to the terms of service. |
98
|
|
|
* Abstracted for testing purposes. |
99
|
|
|
*/ |
100
|
|
|
protected function set_agree() { |
101
|
|
|
\Jetpack_Options::update_option( self::OPTION_NAME, true ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Sets the correct Jetpack Option to mark that the site has rejected the terms of service. |
106
|
|
|
* Abstracted for testing purposes. |
107
|
|
|
*/ |
108
|
|
|
protected function set_reject() { |
109
|
|
|
\Jetpack_Options::update_option( self::OPTION_NAME, false ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|