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
|
|
|
/** |
27
|
|
|
* Finds out if a site is using a version control system. |
28
|
|
|
* @return bool |
29
|
|
|
**/ |
30
|
|
|
public static function is_version_controlled() { |
31
|
|
|
|
32
|
|
|
if ( ! class_exists( 'WP_Automatic_Updater' ) ) { |
33
|
|
|
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
34
|
|
|
} |
35
|
|
|
$updater = new WP_Automatic_Updater(); |
36
|
|
|
return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns true if the site has file write access false otherwise. |
41
|
|
|
* @return bool |
42
|
|
|
**/ |
43
|
|
|
public static function file_system_write_access() { |
44
|
|
|
if ( ! function_exists( 'get_filesystem_method' ) ) { |
45
|
|
|
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
49
|
|
|
|
50
|
|
|
$filesystem_method = get_filesystem_method(); |
51
|
|
|
if ( $filesystem_method === 'direct' ) { |
52
|
|
|
return true; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
ob_start(); |
56
|
|
|
$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
57
|
|
|
ob_end_clean(); |
58
|
|
|
if ( $filesystem_credentials_are_stored ) { |
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function home_url() { |
66
|
|
|
return self::preserve_scheme( 'home', home_url() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function site_url() { |
70
|
|
|
return self::preserve_scheme( 'siteurl', site_url() ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static function main_network_site_url() { |
74
|
|
|
return self::preserve_scheme( 'siteurl', network_site_url() ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public static function preserve_scheme( $option, $current_url ) { |
78
|
|
|
$option_url = get_option( $option ); |
79
|
|
|
if ( $option_url === $current_url ) { |
80
|
|
|
return $current_url; |
81
|
|
|
} |
82
|
|
|
$parsed_option_url = parse_url( $option_url ); |
83
|
|
|
$parsed_current_url = parse_url( $current_url ); |
84
|
|
|
if ( $parsed_current_url[ 'host' ] === $parsed_option_url[ 'host' ] ) { |
85
|
|
|
return set_url_scheme( $current_url, $parsed_option_url['scheme'] ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $current_url; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public static function get_plugins() { |
92
|
|
|
if ( ! function_exists( 'get_plugins' ) ) { |
93
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
94
|
|
|
} |
95
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
96
|
|
|
return apply_filters( 'all_plugins', get_plugins() ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function wp_version() { |
100
|
|
|
global $wp_version; |
101
|
|
|
return $wp_version; |
102
|
|
|
} |
103
|
|
|
} |