|
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 rest_api_allowed_post_types() { |
|
28
|
|
|
/** This filter is already documented in class.json-api-endpoints.php */ |
|
29
|
|
|
return apply_filters( 'rest_api_allowed_post_types', array( 'post', 'page', 'revision' ) ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public static function rest_api_allowed_public_metadata() { |
|
33
|
|
|
/** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */ |
|
34
|
|
|
return apply_filters( 'rest_api_allowed_public_metadata', array() ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Finds out if a site is using a version control system. |
|
39
|
|
|
* @return bool |
|
40
|
|
|
**/ |
|
41
|
|
|
public static function is_version_controlled() { |
|
42
|
|
|
|
|
43
|
|
|
if ( ! class_exists( 'WP_Automatic_Updater' ) ) { |
|
44
|
|
|
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
45
|
|
|
} |
|
46
|
|
|
$updater = new WP_Automatic_Updater(); |
|
47
|
|
|
|
|
48
|
|
|
return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Returns true if the site has file write access false otherwise. |
|
53
|
|
|
* @return bool |
|
54
|
|
|
**/ |
|
55
|
|
|
public static function file_system_write_access() { |
|
56
|
|
|
if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
57
|
|
|
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
61
|
|
|
|
|
62
|
|
|
$filesystem_method = get_filesystem_method(); |
|
63
|
|
|
if ( 'direct' === $filesystem_method ) { |
|
64
|
|
|
return true; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
ob_start(); |
|
68
|
|
|
$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
|
69
|
|
|
ob_end_clean(); |
|
70
|
|
|
if ( $filesystem_credentials_are_stored ) { |
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public static function home_url() { |
|
78
|
|
|
return self::preserve_scheme( 'home', home_url(), true ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public static function site_url() { |
|
82
|
|
|
return self::preserve_scheme( 'siteurl', site_url(), true ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public static function main_network_site_url() { |
|
86
|
|
|
return self::preserve_scheme( 'siteurl', network_site_url(), false ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public static function preserve_scheme( $option, $url, $normalize_www = false ) { |
|
90
|
|
|
$option_url = get_option( $option ); |
|
91
|
|
|
if ( $option_url === $url ) { |
|
92
|
|
|
return $url; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// turn them both into parsed format |
|
96
|
|
|
$option_url = parse_url( $option_url ); |
|
97
|
|
|
$url = parse_url( $url ); |
|
98
|
|
|
|
|
99
|
|
|
if ( $normalize_www ) { |
|
100
|
|
View Code Duplication |
if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) { |
|
101
|
|
|
// remove www if not present in option URL |
|
102
|
|
|
$url['host'] = $option_url['host']; |
|
103
|
|
|
} |
|
104
|
|
View Code Duplication |
if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) { |
|
105
|
|
|
// add www if present in option URL |
|
106
|
|
|
$url['host'] = $option_url['host']; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if ( $url['host'] === $option_url['host'] ) { |
|
111
|
|
|
$url['scheme'] = $option_url['scheme']; |
|
112
|
|
|
// return set_url_scheme( $current_url, $option_url['scheme'] ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$normalized_url = "{$url['scheme']}://{$url['host']}"; |
|
116
|
|
|
|
|
117
|
|
|
if ( isset( $url['path'] ) ) { |
|
118
|
|
|
$normalized_url .= "{$url['path']}"; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if ( isset( $url['query'] ) ) { |
|
122
|
|
|
$normalized_url .= "?{$url['query']}"; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $normalized_url; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public static function get_plugins() { |
|
129
|
|
|
if ( ! function_exists( 'get_plugins' ) ) { |
|
130
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
|
134
|
|
|
return apply_filters( 'all_plugins', get_plugins() ); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public static function wp_version() { |
|
138
|
|
|
global $wp_version; |
|
139
|
|
|
|
|
140
|
|
|
return $wp_version; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|