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.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / sal / class.json-api-site-jetpack-base.php
jetpack / sal Last commit date
class.json-api-date.php 4 years ago class.json-api-links.php 4 years ago class.json-api-metadata.php 4 years ago class.json-api-platform-jetpack.php 4 years ago class.json-api-platform.php 4 years ago class.json-api-post-base.php 4 years ago class.json-api-post-jetpack.php 4 years ago class.json-api-site-base.php 4 years ago class.json-api-site-jetpack-base.php 4 years ago class.json-api-site-jetpack.php 4 years ago class.json-api-token.php 4 years ago
class.json-api-site-jetpack-base.php
344 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * This class extends the SAL_Site class, providing the implementation for
4 * functions that were declared in that SAL_Site class as well as defining
5 * base functions to be implemented in class Jetpack_Site.
6 *
7 * @see class.json-api-site-jetpack.php for more context on
8 * the functions extended here.
9 *
10 * @package automattic/jetpack
11 */
12 require_once __DIR__ . '/class.json-api-site-base.php';
13
14 /**
15 * Base class for Abstract_Jetpack_Site.
16 */
17 abstract class Abstract_Jetpack_Site extends SAL_Site {
18
19 /**
20 * Defining a base get_constant() function to be extended in the Jetpack_Site class.
21 *
22 * If a Jetpack constant name has been defined, this will return the value of the constant.
23 *
24 * @param string $name the name of the Jetpack constant to check.
25 */
26 abstract protected function get_constant( $name );
27
28 /**
29 * Defining a base current_theme_supports() function to be extended in the Jetpack_Site class.
30 *
31 * Returns true if the current theme supports the $feature_name, false otherwise.
32 *
33 * @param string $feature_name the name of the Jetpack feature.
34 */
35 abstract protected function current_theme_supports( $feature_name );
36
37 /**
38 * Defining a base get_theme_support() function to be extended in the Jetpack_Site class.
39 *
40 * Gets theme support arguments to be checked against the specific Jetpack feature.
41 *
42 * @param string $feature_name the name of the Jetpack feature to check against.
43 */
44 abstract protected function get_theme_support( $feature_name );
45
46 /**
47 * Defining a base get_mock_option() function to be extended in the Jetpack_Site class.
48 *
49 * Retrieves a Jetpack option's value, given the option name.
50 *
51 * @param string $name the name of the Jetpack option, without the 'jetpack' prefix (eg. 'log' for 'jetpack_log').
52 */
53 abstract protected function get_mock_option( $name );
54
55 /**
56 * Defining a base get_jetpack_version() function to be extended in the Jetpack_Site class.
57 *
58 * Returns the current Jetpack version number.
59 */
60 abstract public function get_jetpack_version();
61
62 /**
63 * Defining a base get_updates() function to be extended in the Jetpack_Site class.
64 *
65 * Gets updates and then stores them in the jetpack_updates option, returning an array with the option schema.
66 */
67 abstract public function get_updates();
68
69 /**
70 * Defining a base main_network_site() function to be extended in the Jetpack_Site class.
71 *
72 * Returns the site URL for the current network.
73 */
74 abstract protected function main_network_site();
75
76 /**
77 * Defining a base wp_version() function to be extended in the Jetpack_Site class.
78 *
79 * Returns the WordPress version for the current site.
80 */
81 abstract protected function wp_version();
82
83 /**
84 * Defining a base max_upload_size() function to be extended in the Jetpack_Site class.
85 *
86 * Returns the maximum upload size allowed in php.ini.
87 */
88 abstract protected function max_upload_size();
89
90 /**
91 * Defining a base is_main_network() function to be extended in the Jetpack_Site class.
92 *
93 * Returns true if the site is within a system with a multiple networks, false otherwise.
94 *
95 * @see /projects/packages/status/src/class-status.php.
96 */
97 abstract protected function is_main_network();
98
99 /**
100 * Defining a base is_version_controlled() function to be extended in the Jetpack_Site class.
101 *
102 * Returns true if is_vcs_checkout discovers a version control checkout, false otherwise.
103 *
104 * @see projects/packages/sync/src/class-functions.php.
105 */
106 abstract protected function is_version_controlled();
107
108 /**
109 * Defining a base file_system_write_access() function to be extended in the Jetpack_Site class.
110 *
111 * Returns true if the site has file write access false otherwise.
112 *
113 * @see projects/packages/sync/src/class-functions.php.
114 */
115 abstract protected function file_system_write_access();
116
117 /**
118 * Fetch a list of active plugins that are using Jetpack Connection.
119 */
120 abstract protected function get_connection_active_plugins();
121
122 /**
123 * This function is implemented on WPCom sites, where a filter is removed which forces the URL to http.
124 *
125 * @see /wpcom/public.api/rest/sal/class.json-api-site-jetpack-shadow.php.
126 */
127 public function before_render() {
128 }
129
130 /**
131 * This function returns the value of the 'WP_MEMORY_LIMIT' constant.
132 *
133 * @return int|string
134 */
135 protected function wp_memory_limit() {
136 return $this->get_constant( 'WP_MEMORY_LIMIT' );
137 }
138
139 /**
140 * This function returns the value of the 'WP_MAX_MEMORY_LIMIT' constant.
141 *
142 * @return int|string
143 */
144 protected function wp_max_memory_limit() {
145 return $this->get_constant( 'WP_MAX_MEMORY_LIMIT' );
146 }
147
148 /**
149 * If a user has manage options permissions and the site is the main site of the network, make updates visible.
150 *
151 * Called after response_keys have been rendered, which itself is used to return all the necessary information for a site’s response.
152 *
153 * @param array $response an array of the response keys.
154 */
155 public function after_render( &$response ) {
156 if ( current_user_can( 'manage_options' ) && $this->is_main_site( $response ) ) {
157 $jetpack_update = $this->get_updates();
158 if ( ! empty( $jetpack_update ) ) {
159 // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates.
160 unset( $jetpack_update['wp_version'] );
161 // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates.
162 unset( $jetpack_update['site_is_version_controlled'] );
163
164 $response['updates'] = $jetpack_update;
165 }
166 }
167 }
168
169 /**
170 * Extends the Jetpack options array with details including site constraints, WordPress and Jetpack versions, and plugins using the Jetpack connection.
171 *
172 * @param array $options an array of the Jetpack options.
173 */
174 public function after_render_options( &$options ) {
175 $options['jetpack_version'] = $this->get_jetpack_version();
176
177 $main_network_site = $this->main_network_site();
178 if ( $main_network_site ) {
179 $options['main_network_site'] = (string) rtrim( $main_network_site, '/' );
180 }
181
182 $active_modules = Jetpack_Options::get_option( 'active_modules' );
183 if ( is_array( $active_modules ) ) {
184 $options['active_modules'] = (array) array_values( $active_modules );
185 }
186
187 $options['software_version'] = (string) $this->wp_version();
188 $options['max_upload_size'] = $this->max_upload_size();
189 $options['wp_memory_limit'] = $this->wp_memory_limit();
190 $options['wp_max_memory_limit'] = $this->wp_max_memory_limit();
191
192 // Sites have to prove that they are not main_network site.
193 // If the sync happends right then we should be able to see that we are not dealing with a network site.
194 $options['is_multi_network'] = (bool) $this->is_main_network();
195 $options['is_multi_site'] = (bool) $this->is_multisite();
196
197 $file_mod_disabled_reasons = array_keys(
198 array_filter(
199 array(
200 'automatic_updater_disabled' => (bool) $this->get_constant( 'AUTOMATIC_UPDATER_DISABLED' ),
201 // WP AUTO UPDATE CORE defaults to minor, '1' if true and '0' if set to false.
202 'wp_auto_update_core_disabled' => ! ( (bool) $this->get_constant( 'WP_AUTO_UPDATE_CORE' ) ),
203 'is_version_controlled' => (bool) $this->is_version_controlled(),
204 // By default we assume that site does have system write access if the value is not set yet.
205 'has_no_file_system_write_access' => ! (bool) $this->file_system_write_access(),
206 'disallow_file_mods' => (bool) $this->get_constant( 'DISALLOW_FILE_MODS' ),
207 )
208 )
209 );
210
211 $options['file_mod_disabled'] = empty( $file_mod_disabled_reasons ) ? false : $file_mod_disabled_reasons;
212
213 $options['jetpack_connection_active_plugins'] = $this->get_connection_active_plugins();
214 }
215
216 /**
217 * This function returns the values of any active Jetpack modules.
218 *
219 * @return array
220 */
221 public function get_jetpack_modules() {
222 return array_values( Jetpack_Options::get_option( 'active_modules', array() ) );
223 }
224
225 /**
226 * This function returns true if a specified Jetpack module is active, false otherwise.
227 *
228 * @param string $module The Jetpack module name to check.
229 *
230 * @return bool
231 */
232 public function is_module_active( $module ) {
233 return in_array( $module, Jetpack_Options::get_option( 'active_modules', array() ), true );
234 }
235
236 /**
237 * This function returns false for a check as to whether a site is a VIP site or not.
238 *
239 * @return bool Always returns false.
240 */
241 public function is_vip() {
242 return false; // this may change for VIP Go sites, which sync using Jetpack.
243 }
244
245 /**
246 * If the site's current theme supports post thumbnails, return true (otherwise return false).
247 *
248 * @return bool
249 */
250 public function featured_images_enabled() {
251 return $this->current_theme_supports( 'post-thumbnails' );
252 }
253
254 /**
255 * Returns an array of supported post formats.
256 *
257 * @return array
258 */
259 public function get_post_formats() {
260 // deprecated - see separate endpoint. get a list of supported post formats.
261 $all_formats = get_post_format_strings();
262 $supported = $this->get_theme_support( 'post-formats' );
263
264 $supported_formats = array();
265
266 if ( isset( $supported[0] ) ) {
267 foreach ( $supported[0] as $format ) {
268 $supported_formats[ $format ] = $all_formats[ $format ];
269 }
270 }
271
272 return $supported_formats;
273 }
274
275 /**
276 * Returns an array with site icon details.
277 *
278 * @return array
279 */
280 public function get_icon() {
281 $icon_id = get_option( 'site_icon' );
282 if ( empty( $icon_id ) ) {
283 $icon_id = Jetpack_Options::get_option( 'site_icon_id' );
284 }
285
286 if ( empty( $icon_id ) ) {
287 return null;
288 }
289
290 $icon = array_filter(
291 array(
292 'img' => wp_get_attachment_image_url( $icon_id, 'full' ),
293 'ico' => wp_get_attachment_image_url( $icon_id, array( 16, 16 ) ),
294 )
295 );
296
297 if ( empty( $icon ) ) {
298 return null;
299 }
300
301 if ( current_user_can( 'edit_posts', $icon_id ) ) {
302 $icon['media_id'] = (int) $icon_id;
303 }
304
305 return $icon;
306 }
307
308 /**
309 * Private methods
310 **/
311
312 /**
313 * This function returns true if the current site is the main network site, false otherwise.
314 *
315 * @param array $response The array of Jetpack response keys.
316 *
317 * @return bool
318 */
319 private function is_main_site( $response ) {
320 if ( isset( $response['options']->main_network_site, $response['options']->unmapped_url ) ) {
321 $main_network_site_url = set_url_scheme( $response['options']->main_network_site, 'http' );
322 $unmapped_url = set_url_scheme( $response['options']->unmapped_url, 'http' );
323 if ( $unmapped_url === $main_network_site_url ) {
324 return true;
325 }
326 }
327
328 return false;
329 }
330
331 /**
332 * For Jetpack sites this will always return false.
333 *
334 * This is extended for WordPress.com sites in wpcom/public.api/rest/sal/trait.json-api-site-wpcom.php.
335 *
336 * @param int $post_id The post id.
337 *
338 * @return bool
339 */
340 protected function is_a8c_publication( $post_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Extended and used in WordPress.com.
341 return false;
342 }
343 }
344