Completed
Push — update/non-admin-view ( b1ee9d...762240 )
by
unknown
10:19
created

Jetpack_Sync_Functions::wp_version()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
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
		require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' );
11
		return Jetpack_Admin::init()->get_modules();
12
	}
13
14
	public static function get_taxonomies() {
15
		global $wp_taxonomies;
16
17
		return $wp_taxonomies;
18
	}
19
20
	public static function get_post_types() {
21
		global $wp_post_types;
22
23
		return $wp_post_types;
24
	}
25
26
	public static function rest_api_allowed_post_types() {
27
		/** This filter is already documented in class.json-api-endpoints.php */
28
		return apply_filters( 'rest_api_allowed_post_types', array( 'post', 'page', 'revision' ) );
29
	}
30
31
	public static function rest_api_allowed_public_metadata() {
32
		/** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */
33
		return apply_filters( 'rest_api_allowed_public_metadata', array() );
34
	}
35
36
	/**
37
	 * Finds out if a site is using a version control system.
38
	 * @return bool
39
	 **/
40
	public static function is_version_controlled() {
41
42
		if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
43
			require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
44
		}
45
		$updater               = new WP_Automatic_Updater();
46
		return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) );
47
	}
48
49
	/**
50
	 * Returns true if the site has file write access false otherwise.
51
	 * @return bool
52
	 **/
53
	public static function file_system_write_access() {
54
		if ( ! function_exists( 'get_filesystem_method' ) ) {
55
			require_once( ABSPATH . 'wp-admin/includes/file.php' );
56
		}
57
58
		require_once( ABSPATH . 'wp-admin/includes/template.php' );
59
60
		$filesystem_method = get_filesystem_method();
61
		if ( $filesystem_method === 'direct' ) {
62
			return true;
63
		}
64
65
		ob_start();
66
		$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
67
		ob_end_clean();
68
		if ( $filesystem_credentials_are_stored ) {
69
			return true;
70
		}
71
72
		return false;
73
	}
74
75
	public static function home_url() {
76
		return self::preserve_scheme( 'home', home_url() );
77
	}
78
79
	public static function site_url() {
80
		return self::preserve_scheme( 'siteurl', site_url() );
81
	}
82
83
	public static function main_network_site_url() {
84
		return self::preserve_scheme( 'siteurl', network_site_url() );
85
	}
86
87
	public static function preserve_scheme( $option, $current_url ) {
88
		$option_url = get_option( $option );
89
		if ( $option_url === $current_url ) {
90
			return $current_url;
91
		}
92
		$parsed_option_url = parse_url( $option_url );
93
		$parsed_current_url = parse_url( $current_url );
94
		if ( $parsed_current_url[ 'host' ] === $parsed_option_url[ 'host' ] ) {
95
			return set_url_scheme( $current_url,  $parsed_option_url['scheme'] );
96
		}
97
98
		return $current_url;
99
	}
100
101
	public static function get_plugins() {
102
		if ( ! function_exists( 'get_plugins' ) ) {
103
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
104
		}
105
		/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
106
		return apply_filters( 'all_plugins', get_plugins() );
107
	}
108
109
	public static function wp_version() {
110
		global $wp_version;
111
		return $wp_version;
112
	}
113
}
114