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
|
|
|
|
12
|
|
|
return Jetpack_Admin::init()->get_modules(); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public static function get_taxonomies() { |
16
|
|
|
global $wp_taxonomies; |
17
|
|
|
|
18
|
|
|
return $wp_taxonomies; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function get_post_types() { |
22
|
|
|
global $wp_post_types; |
23
|
|
|
|
24
|
|
|
return $wp_post_types; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public static function get_post_type_features() { |
28
|
|
|
global $_wp_post_type_features; |
29
|
|
|
|
30
|
|
|
return $_wp_post_type_features; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function get_hosting_provider() { |
34
|
|
|
if ( defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { |
35
|
|
|
return 'gd-managed-wp'; |
36
|
|
|
} |
37
|
|
|
if ( defined( 'MM_BASE_DIR' ) ) { |
38
|
|
|
return 'bh'; |
39
|
|
|
} |
40
|
|
|
if ( defined( 'IS_PRESSABLE' ) ) { |
41
|
|
|
return 'pressable'; |
42
|
|
|
} |
43
|
|
|
if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { |
44
|
|
|
return 'wpe'; |
45
|
|
|
} |
46
|
|
|
return 'unknown'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public static function rest_api_allowed_post_types() { |
50
|
|
|
/** This filter is already documented in class.json-api-endpoints.php */ |
51
|
|
|
return apply_filters( 'rest_api_allowed_post_types', array( 'post', 'page', 'revision' ) ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function rest_api_allowed_public_metadata() { |
55
|
|
|
/** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */ |
56
|
|
|
return apply_filters( 'rest_api_allowed_public_metadata', array() ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Finds out if a site is using a version control system. |
61
|
|
|
* @return bool |
62
|
|
|
**/ |
63
|
|
|
public static function is_version_controlled() { |
64
|
|
|
|
65
|
|
|
if ( ! class_exists( 'WP_Automatic_Updater' ) ) { |
66
|
|
|
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
67
|
|
|
} |
68
|
|
|
$updater = new WP_Automatic_Updater(); |
69
|
|
|
|
70
|
|
|
return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns true if the site has file write access false otherwise. |
75
|
|
|
* @return bool |
76
|
|
|
**/ |
77
|
|
|
public static function file_system_write_access() { |
78
|
|
|
if ( ! function_exists( 'get_filesystem_method' ) ) { |
79
|
|
|
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
83
|
|
|
|
84
|
|
|
$filesystem_method = get_filesystem_method(); |
85
|
|
|
if ( 'direct' === $filesystem_method ) { |
86
|
|
|
return true; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
ob_start(); |
90
|
|
|
$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
91
|
|
|
ob_end_clean(); |
92
|
|
|
if ( $filesystem_credentials_are_stored ) { |
93
|
|
|
return true; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function home_url() { |
100
|
|
|
return self::preserve_scheme( 'home', 'home_url', true ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public static function site_url() { |
104
|
|
|
return self::preserve_scheme( 'siteurl', 'site_url', true ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public static function main_network_site_url() { |
108
|
|
|
return self::preserve_scheme( 'siteurl', 'network_site_url', false ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public static function preserve_scheme( $option, $url_function, $normalize_www = false ) { |
112
|
|
|
$previous_https_value = isset( $_SERVER['HTTPS'] ) ? $_SERVER['HTTPS'] : null; |
113
|
|
|
$_SERVER['HTTPS'] = 'off'; |
114
|
|
|
$url = call_user_func( $url_function ); |
115
|
|
|
$option_url = get_option( $option ); |
116
|
|
|
if ( $previous_https_value ) { |
117
|
|
|
$_SERVER['HTTPS'] = $previous_https_value; |
118
|
|
|
} else { |
119
|
|
|
unset( $_SERVER['HTTPS'] ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ( $option_url === $url ) { |
123
|
|
|
return $url; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// turn them both into parsed format |
127
|
|
|
$option_url = parse_url( $option_url ); |
128
|
|
|
$url = parse_url( $url ); |
129
|
|
|
|
130
|
|
|
if ( $normalize_www ) { |
131
|
|
View Code Duplication |
if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) { |
132
|
|
|
// remove www if not present in option URL |
133
|
|
|
$url['host'] = $option_url['host']; |
134
|
|
|
} |
135
|
|
View Code Duplication |
if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) { |
136
|
|
|
// add www if present in option URL |
137
|
|
|
$url['host'] = $option_url['host']; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if ( $url['host'] === $option_url['host'] ) { |
142
|
|
|
$url['scheme'] = $option_url['scheme']; |
143
|
|
|
// return set_url_scheme( $current_url, $option_url['scheme'] ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$normalized_url = "{$url['scheme']}://{$url['host']}"; |
147
|
|
|
|
148
|
|
|
if ( isset( $url['path'] ) ) { |
149
|
|
|
$normalized_url .= "{$url['path']}"; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
if ( isset( $url['query'] ) ) { |
153
|
|
|
$normalized_url .= "?{$url['query']}"; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
return $normalized_url; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public static function get_plugins() { |
160
|
|
|
if ( ! function_exists( 'get_plugins' ) ) { |
161
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
165
|
|
|
return apply_filters( 'all_plugins', get_plugins() ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public static function wp_version() { |
169
|
|
|
global $wp_version; |
170
|
|
|
|
171
|
|
|
return $wp_version; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public static function site_icon_url() { |
175
|
|
|
if ( ! function_exists( 'get_site_icon_url' ) || ! has_site_icon() ) { |
176
|
|
|
return get_option( 'jetpack_site_icon_url' ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return get_site_icon_url(); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|