|
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
|
|
|
/** |
|
11
|
|
|
* Class Terms_Of_Service |
|
12
|
|
|
* |
|
13
|
|
|
* Helper class that is responsible for the state of agreement of the terms of service. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Terms_Of_Service { |
|
16
|
|
|
/** |
|
17
|
|
|
* Jetpack option name where the terms of service state is stored. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
const OPTION_NAME = 'tos_agreed'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Allow the site to agree to the terms of service. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function agree() { |
|
27
|
|
|
$this->set_agree(); |
|
28
|
|
|
/** |
|
29
|
|
|
* Acton fired when the master user has agreed to the terms of service. |
|
30
|
|
|
* |
|
31
|
|
|
* @since 7.9.0 |
|
32
|
|
|
*/ |
|
33
|
|
|
do_action( 'jetpack_agreed_to_terms_of_service' ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Allow the site to reject to the terms of service. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function reject() { |
|
40
|
|
|
$this->set_reject(); |
|
41
|
|
|
/** |
|
42
|
|
|
* Acton fired when the master user has revoked their agreement to the terms of service. |
|
43
|
|
|
* |
|
44
|
|
|
* @since 7.9.1 |
|
45
|
|
|
*/ |
|
46
|
|
|
do_action( 'jetpack_reject_terms_of_service' ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns whether the master user has agreed to the terms of service. |
|
51
|
|
|
* |
|
52
|
|
|
* The following conditions have to be met in order to agree to the terms of service. |
|
53
|
|
|
* 1. The master user has gone though the connect flow. |
|
54
|
|
|
* 2. The site is not in dev mode. |
|
55
|
|
|
* 3. The master user of the site is still connected (deprecated @since 8.9.0). |
|
56
|
|
|
* |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function has_agreed() { |
|
60
|
|
|
if ( $this->is_offline_mode() ) { |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
/** |
|
64
|
|
|
* Before 8.9.0 we used to also check if the master user of the site is connected |
|
65
|
|
|
* by calling the Connection related `is_active` method. |
|
66
|
|
|
* As of 8.9.0 we have removed this check in order to resolve the |
|
67
|
|
|
* circular dependencies it was introducing to composer packages. |
|
68
|
|
|
* |
|
69
|
|
|
* @since 8.9.0 |
|
70
|
|
|
*/ |
|
71
|
|
|
return $this->get_raw_has_agreed(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the Terms of Service text to display on the "Connection" page. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $button_label The "connection" button label to be insterted into the TOS text. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function get_tos( $button_label = 'Connect to WP.com' ) { |
|
82
|
|
|
return sprintf( |
|
83
|
|
|
wp_kses( |
|
84
|
|
|
/* Translators: placeholders are links. */ |
|
85
|
|
|
__( 'By clicking the <strong>%1$s</strong> button, you agree to our <a href="%2$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%3$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com.', 'jetpack' ), |
|
86
|
|
|
array( |
|
87
|
|
|
'a' => array( |
|
88
|
|
|
'href' => array(), |
|
89
|
|
|
'target' => array(), |
|
90
|
|
|
'rel' => array(), |
|
91
|
|
|
), |
|
92
|
|
|
'strong' => true, |
|
93
|
|
|
) |
|
94
|
|
|
), |
|
95
|
|
|
esc_html( $button_label ), |
|
96
|
|
|
esc_url( Redirect::get_url( 'wpcom-tos' ) ), |
|
97
|
|
|
esc_url( Redirect::get_url( 'jetpack-support-what-data-does-jetpack-sync' ) ) |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Abstracted for testing purposes. |
|
103
|
|
|
* Tells us if the site is in dev mode. |
|
104
|
|
|
* |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function is_offline_mode() { |
|
108
|
|
|
return ( new Status() )->is_offline_mode(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Gets just the Jetpack Option that contains the terms of service state. |
|
113
|
|
|
* Abstracted for testing purposes. |
|
114
|
|
|
* |
|
115
|
|
|
* @return bool |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function get_raw_has_agreed() { |
|
118
|
|
|
return \Jetpack_Options::get_option( self::OPTION_NAME, false ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Sets the correct Jetpack Option to mark the that the site has agreed to the terms of service. |
|
123
|
|
|
* Abstracted for testing purposes. |
|
124
|
|
|
*/ |
|
125
|
|
|
protected function set_agree() { |
|
126
|
|
|
\Jetpack_Options::update_option( self::OPTION_NAME, true ); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Sets the correct Jetpack Option to mark that the site has rejected the terms of service. |
|
131
|
|
|
* Abstracted for testing purposes. |
|
132
|
|
|
*/ |
|
133
|
|
|
protected function set_reject() { |
|
134
|
|
|
\Jetpack_Options::update_option( self::OPTION_NAME, false ); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|