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\Connection\Manager; |
11
|
|
|
use Automattic\Jetpack\Status; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Terms_Of_Service |
15
|
|
|
* |
16
|
|
|
* Helper class that is responsible for the state of agreement of the terms of service. |
17
|
|
|
*/ |
18
|
|
|
class Terms_Of_Service { |
19
|
|
|
/** |
20
|
|
|
* Jetpack option name where the terms of service state is stored. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
const OPTION_NAME = 'tos_agreed'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Allow the site to agree to the terms of service. |
28
|
|
|
*/ |
29
|
|
|
public function agree() { |
30
|
|
|
$this->set_agree(); |
31
|
|
|
/** |
32
|
|
|
* Acton fired when the master user has agreed to the terms of service. |
33
|
|
|
* |
34
|
|
|
* @since 7.9.0 |
35
|
|
|
*/ |
36
|
|
|
do_action( 'jetpack_agreed_to_terms_of_service' ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Allow the site to reject to the terms of service. |
41
|
|
|
*/ |
42
|
|
|
public function reject() { |
43
|
|
|
$this->set_reject(); |
44
|
|
|
/** |
45
|
|
|
* Acton fired when the master user has revoked their agreement to the terms of service. |
46
|
|
|
* |
47
|
|
|
* @since 7.9.0 |
48
|
|
|
*/ |
49
|
|
|
do_action( 'jetpack_reject_to_terms_of_service' ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns whether the master user has agreed to the terms of service. |
54
|
|
|
* |
55
|
|
|
* The following conditions have to be met in order to agree to the terms of service. |
56
|
|
|
* 1. The master user has gone though the connect flow. |
57
|
|
|
* 2. The site is not in dev mode. |
58
|
|
|
* 3. The master user of the site is still connected. |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function has_agreed() { |
63
|
|
|
if ( ! $this->get_raw_has_agreed() ) { |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if ( $this->is_development_mode() ) { |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->is_active(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Abstracted for testing purposes. |
76
|
|
|
* Tells us if the site is in dev mode. |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
protected function is_development_mode() { |
81
|
|
|
$status = new Status(); |
82
|
|
|
return $status->is_development_mode(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Tells us if the site is connected. |
87
|
|
|
* Abstracted for testing purposes. |
88
|
|
|
* |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
protected function is_active() { |
92
|
|
|
$manager = new Manager(); |
93
|
|
|
return $manager->is_active(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Gets just the Jetpack Option that contains the terms of service state. |
98
|
|
|
* Abstracted for testing purposes. |
99
|
|
|
* |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
protected function get_raw_has_agreed() { |
103
|
|
|
return \Jetpack_Options::get_option( self::OPTION_NAME ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Sets the correct Jetpack Option to mark the that the site has agreed to the terms of service. |
108
|
|
|
* Abstracted for testing purposes. |
109
|
|
|
*/ |
110
|
|
|
protected function set_agree() { |
111
|
|
|
\Jetpack_Options::update_option( self::OPTION_NAME, true ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Sets the correct Jetpack Option to mark that the site has rejected the terms of service. |
116
|
|
|
* Abstracted for testing purposes. |
117
|
|
|
*/ |
118
|
|
|
protected function set_reject() { |
119
|
|
|
\Jetpack_Options::update_option( self::OPTION_NAME, false ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|