Completed
Push — add/sync-rest-2 ( b5463d...83f13e )
by
unknown
219:15 queued 210:11
created

Jetpack_Sync_Functions::get_all()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 19
rs 9.4285
cc 2
eloc 17
nc 2
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Jetpack_Sync_Functions::get_modules() 0 9 3
1
<?php
2
3
/*
4
 * Utility functions to generate data synced to wpcom
5
 */
6
7
class Jetpack_Sync_Functions {
8
9
	public static function get_modules() {
10
		$modules = array();
11
		$active_modules = Jetpack::get_active_modules();
12
		foreach ( Jetpack::get_available_modules() as $available_module ) {
13
			$modules[ $available_module ] = in_array( $available_module, $active_modules );
14
		}
15
		$modules['vaultpress'] = class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' );
16
		return $modules;
17
	}
18
19
	/**
20
	 * Finds out if a site is using a version control system.
21
	 * @return string ( '1' | '0' )
22
	 **/
23
	public static function is_version_controlled() {
24
25
		if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
26
			require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
27
		}
28
		$updater = new WP_Automatic_Updater();
29
		$is_version_controlled = strval( $updater->is_vcs_checkout( $context = ABSPATH ) );
30
		// transients should not be empty
31
		if ( empty( $is_version_controlled ) ) {
32
			$is_version_controlled = '0';
33
		}
34
		return $is_version_controlled;
35
	}
36
37
	/**
38
	 * Returns true if the site has file write access false otherwise.
39
	 * @return string ( '1' | '0' )
40
	 **/
41
	public static function file_system_write_access() {
42
		if ( ! function_exists( 'get_filesystem_method' ) ) {
43
			require_once( ABSPATH . 'wp-admin/includes/file.php' );
44
		}
45
46
		require_once( ABSPATH . 'wp-admin/includes/template.php' );
47
48
		$filesystem_method = get_filesystem_method();
49
		if ( $filesystem_method === 'direct' ) {
50
			return 1;
51
		}
52
53
		ob_start();
54
		$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
55
		ob_end_clean();
56
		if ( $filesystem_credentials_are_stored ) {
57
			return 1;
58
		}
59
		return 0;
60
	}
61
}