1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
<?php /** * A hosting provide class for Jetpack. * * @package automattic/jetpack-status */
namespace Automattic\Jetpack\Status;
use Automattic\Jetpack\Constants;
/** * Hosting provider class. */ class Host { /** * Determine if this site is an WordPress.com on Atomic site or not by looking for presence of the wpcomsh plugin. * * @since 1.9.0 * * @return bool */ public function is_woa_site() { $ret = Cache::get( 'is_woa_site' ); if ( null === $ret ) { $ret = $this->is_atomic_platform() && Constants::is_true( 'WPCOMSH__PLUGIN_FILE' ); Cache::set( 'is_woa_site', $ret ); } return $ret; }
/** * Determine if the site is hosted on the Atomic hosting platform. * * @since 1.9.0 * * @return bool */ public function is_atomic_platform() { return Constants::is_true( 'ATOMIC_SITE_ID' ) && Constants::is_true( 'ATOMIC_CLIENT_ID' ); }
/** * Determine if this is a Newspack site. * * @return bool */ public function is_newspack_site() { return Constants::is_defined( 'NEWSPACK_PLUGIN_FILE' ); }
/** * Determine if this is a VIP-hosted site. * * @return bool */ public function is_vip_site() { return Constants::is_defined( 'WPCOM_IS_VIP_ENV' ) && true === Constants::get_constant( 'WPCOM_IS_VIP_ENV' ); }
/** * Determine if this is a Simple platform site. * * @return bool */ public function is_wpcom_simple() { return Constants::is_defined( 'IS_WPCOM' ) && true === Constants::get_constant( 'IS_WPCOM' ); }
/** * Determine if this is a WordPress.com site. * * Includes both Simple and WoA platforms. * * @return bool */ public function is_wpcom_platform() { return $this->is_wpcom_simple() || $this->is_woa_site(); }
/** * Determine if this is a P2 site. * This covers both P2 and P2020 themes. * * @return bool */ public function is_p2_site() { $site_id = $this->get_wpcom_site_id(); if ( ! $site_id ) { return false; } return str_contains( get_stylesheet(), 'pub/p2' ) || ( function_exists( '\WPForTeams\is_wpforteams_site' ) && \WPForTeams\is_wpforteams_site( $site_id ) ); }
/** * Get the current site's WordPress.com ID. * * @return mixed The site's WordPress.com ID. */ public function get_wpcom_site_id() { if ( $this->is_wpcom_simple() ) { return get_current_blog_id(); } elseif ( class_exists( 'Jetpack' ) && \Jetpack::is_connection_ready() ) { return \Jetpack_Options::get_option( 'id' ); } return false; }
/** * Add all wordpress.com environments to the safe redirect allowed list. * * To be used with a filter of allowed domains for a redirect. * * @param array $domains Allowed WP.com Environments. */ public static function allow_wpcom_environments( $domains ) { $domains[] = 'wordpress.com'; $domains[] = 'jetpack.wordpress.com'; $domains[] = 'wpcalypso.wordpress.com'; $domains[] = 'horizon.wordpress.com'; $domains[] = 'calypso.localhost'; return $domains; }
/** * Return Calypso environment value; used for developing Jetpack and pairing * it with different Calypso environments, such as localhost. * * @since 1.18.0 * * @return string Calypso environment */ public function get_calypso_env() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Nonce is not required; only used for changing environments. if ( isset( $_GET['calypso_env'] ) ) { return sanitize_key( $_GET['calypso_env'] ); } // phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( getenv( 'CALYPSO_ENV' ) ) { return sanitize_key( getenv( 'CALYPSO_ENV' ) ); }
if ( defined( 'CALYPSO_ENV' ) && CALYPSO_ENV ) { return sanitize_key( CALYPSO_ENV ); }
return ''; }
/** * Return source query param value from the URL if exists in the allowed sources list. * * @return string "source" query param value */ public function get_source_query() { // phpcs:disable WordPress.Security.NonceVerification.Recommended $allowed_sources = array( 'jetpack-manage', 'a8c-for-agencies' ); if ( isset( $_GET['source'] ) && in_array( $_GET['source'], $allowed_sources, true ) ) { return sanitize_key( $_GET['source'] ); }
return ''; }
/** * Returns a guess of the hosting provider for the current site based on various checks. * * @since 5.0.4 Added $guess parameter. * @since 6.0.0 Removed $guess parameter. * * @return string */ public function get_known_host_guess() { // First, let's check if we can recognize provider manually: switch ( true ) { case $this->is_woa_site(): $provider = 'woa'; break; case $this->is_atomic_platform(): $provider = 'atomic'; break; case $this->is_newspack_site(): $provider = 'newspack'; break; case $this->is_vip_site(): $provider = 'vip'; break; case $this->is_wpcom_simple(): case $this->is_wpcom_platform(): $provider = 'wpcom'; break; default: $provider = 'unknown'; break; }
return $provider; }
/** * Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. * * @since 3.0.2 Ported from Jetpack to the Status package. * * To be used with a filter of allowed domains for a redirect. * * @param array $domains Allowed WP.com Environments. * * @return array */ public static function allow_wpcom_public_api_domain( $domains ) { $domains[] = 'public-api.wordpress.com'; return $domains; } }
|