PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.1.3
Jetpack – WP Security, Backup, Speed, & Growth v12.1.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7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3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / _inc / lib / core-api / class.jetpack-core-api-site-endpoints.php
jetpack / _inc / lib / core-api Last commit date
wpcom-endpoints 3 years ago wpcom-fields 3 years ago class-wpcom-rest-field-controller.php 4 years ago class.jetpack-core-api-module-endpoints.php 3 years ago class.jetpack-core-api-site-endpoints.php 3 years ago class.jetpack-core-api-widgets-endpoints.php 4 years ago class.jetpack-core-api-xmlrpc-consumer-endpoint.php 4 years ago load-wpcom-endpoints.php 4 years ago
class.jetpack-core-api-site-endpoints.php
305 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * List of /site core REST API endpoints used in Jetpack's dashboard.
4 *
5 * @package automattic/jetpack
6 */
7
8 use Automattic\Jetpack\Connection\Client;
9 use Automattic\Jetpack\Stats\WPCOM_Stats;
10
11 /**
12 * This is the endpoint class for `/site` endpoints.
13 */
14 class Jetpack_Core_API_Site_Endpoint {
15 /**
16 * Returns commonly used WP_Error indicating failure to fetch data
17 *
18 * @return WP_Error that denotes our inability to fetch the requested data
19 */
20 private static function get_failed_fetch_error() {
21 return new WP_Error(
22 'failed_to_fetch_data',
23 esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
24 array( 'status' => 500 )
25 );
26 }
27
28 /**
29 * Returns the result of `/sites/%s/features` endpoint call.
30 *
31 * @return object $features has 'active' and 'available' properties each of which contain feature slugs.
32 * 'active' is a simple array of slugs that are active on the current plan.
33 * 'available' is an object with keys that represent feature slugs and values are arrays
34 * of plan slugs that enable these features
35 */
36 public static function get_features() {
37 // Make the API request.
38 $request = sprintf( '/sites/%d/features', Jetpack_Options::get_option( 'id' ) );
39 $response = Client::wpcom_json_api_request_as_blog( $request, '1.1' );
40
41 // Bail if there was an error or malformed response.
42 if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
43 return self::get_failed_fetch_error();
44 }
45
46 // Decode the results.
47 $results = json_decode( $response['body'], true );
48
49 // Bail if there were no results or plan details returned.
50 if ( ! is_array( $results ) ) {
51 return self::get_failed_fetch_error();
52 }
53
54 return rest_ensure_response(
55 array(
56 'code' => 'success',
57 'message' => esc_html__( 'Site features correctly received.', 'jetpack' ),
58 'data' => wp_remote_retrieve_body( $response ),
59 )
60 );
61 }
62
63 /**
64 * Returns the result of `/sites/%s/purchases` endpoint call.
65 *
66 * @return array of site purchases.
67 */
68 public static function get_purchases() {
69 // Make the API request.
70 $request = sprintf( '/sites/%d/purchases', Jetpack_Options::get_option( 'id' ) );
71 $response = Client::wpcom_json_api_request_as_blog( $request, '1.1' );
72
73 // Bail if there was an error or malformed response.
74 if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
75 return self::get_failed_fetch_error();
76 }
77
78 if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
79 return self::get_failed_fetch_error();
80 }
81
82 // Decode the results.
83 $results = json_decode( $response['body'], true );
84
85 // Bail if there were no results or purchase details returned.
86 if ( ! is_array( $results ) ) {
87 return self::get_failed_fetch_error();
88 }
89
90 return rest_ensure_response(
91 array(
92 'code' => 'success',
93 'message' => esc_html__( 'Site purchases correctly received.', 'jetpack' ),
94 'data' => wp_remote_retrieve_body( $response ),
95 )
96 );
97 }
98
99 /**
100 * Returns the result of `/sites/%d/products` endpoint call.
101 *
102 * @return array of site products.
103 */
104 public static function get_products() {
105 $url = sprintf( '/sites/%d/products?locale=%s&type=jetpack', Jetpack_Options::get_option( 'id' ), get_user_locale() );
106 $response = Client::wpcom_json_api_request_as_blog( $url, '1.1' );
107
108 if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
109 return self::get_failed_fetch_error();
110 }
111
112 $results = json_decode( wp_remote_retrieve_body( $response ), true );
113 if ( ! is_array( $results ) ) {
114 return self::get_failed_fetch_error();
115 }
116
117 return rest_ensure_response(
118 array(
119 'code' => 'success',
120 'message' => esc_html__( 'Site products correctly received.', 'jetpack' ),
121 'data' => $results,
122 )
123 );
124 }
125
126 /**
127 * Check that the current user has permissions to request information about this site.
128 *
129 * @since 5.1.0
130 *
131 * @return bool
132 */
133 public static function can_request() {
134 return current_user_can( 'jetpack_manage_modules' );
135 }
136
137 /**
138 * Gets an array of data that show how Jetpack is currently being used to benefit the site.
139 *
140 * @since 7.7
141 *
142 * @return WP_REST_Response
143 */
144 public static function get_benefits() {
145 $benefits = array();
146
147 /*
148 * We get different benefits from Stats:
149 * - this year's visitors
150 * - Followers (only if subs module is active)
151 * - Sharing counts (not currently supported in Jetpack -- https://github.com/Automattic/jetpack/issues/844 )
152 */
153 $stats = null;
154 if ( function_exists( 'convert_stats_array_to_object' ) ) {
155 $stats = convert_stats_array_to_object(
156 ( new WPCOM_Stats() )->get_stats( array( 'fields' => 'stats' ) )
157 );
158 }
159 $has_stats = null !== $stats && ! is_wp_error( $stats );
160
161 // Yearly visitors.
162 if ( $has_stats && $stats->stats->visitors > 0 ) {
163 $benefits[] = array(
164 'name' => 'jetpack-stats',
165 'title' => esc_html__( 'Jetpack Stats', 'jetpack' ),
166 'description' => esc_html__( 'Visitors tracked by Jetpack', 'jetpack' ),
167 'value' => absint( $stats->stats->visitors ),
168 );
169 }
170
171 // Protect blocked logins.
172 if ( Jetpack::is_module_active( 'protect' ) ) {
173 $protect = get_site_option( 'jetpack_protect_blocked_attempts' );
174 if ( $protect > 0 ) {
175 $benefits[] = array(
176 'name' => 'protect',
177 'title' => esc_html__( 'Brute force protection', 'jetpack' ),
178 'description' => esc_html__( 'The number of malicious login attempts blocked by Jetpack', 'jetpack' ),
179 'value' => absint( $protect ),
180 );
181 }
182 }
183
184 // Number of followers.
185 if ( $has_stats && $stats->stats->followers_blog > 0 && Jetpack::is_module_active( 'subscriptions' ) ) {
186 $benefits[] = array(
187 'name' => 'subscribers',
188 'title' => esc_html__( 'Subscribers', 'jetpack' ),
189 'description' => esc_html__( 'People subscribed to your updates through Jetpack', 'jetpack' ),
190 'value' => absint( $stats->stats->followers_blog ),
191 );
192 }
193
194 // VaultPress backups.
195 if ( Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) && class_exists( 'VaultPress' ) ) {
196 $vaultpress = new VaultPress();
197 if ( $vaultpress->is_registered() ) {
198 $data = json_decode( base64_decode( $vaultpress->contact_service( 'plugin_data' ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
199 if ( $data && $data->features->backups && ! empty( $data->backups->stats ) && $data->backups->stats->revisions > 0 ) {
200 $benefits[] = array(
201 'name' => 'jetpack-backup',
202 'title' => esc_html__( 'Jetpack Backup', 'jetpack' ),
203 'description' => esc_html__( 'The number of times Jetpack has backed up your site and kept it safe', 'jetpack' ),
204 'value' => absint( $data->backups->stats->revisions ),
205 );
206 }
207 }
208 }
209
210 // Number of forms sent via a Jetpack contact form.
211 if ( Jetpack::is_module_active( 'contact-form' ) ) {
212 $contact_form_count = array_sum( get_object_vars( wp_count_posts( 'feedback' ) ) );
213 if ( $contact_form_count > 0 ) {
214 $benefits[] = array(
215 'name' => 'contact-form-feedback',
216 'title' => esc_html__( 'Contact Form Feedback', 'jetpack' ),
217 'description' => esc_html__( 'Form submissions stored by Jetpack', 'jetpack' ),
218 'value' => absint( $contact_form_count ),
219 );
220 }
221 }
222
223 // Number of images in the library if Photon is active.
224 if ( Jetpack::is_module_active( 'photon' ) ) {
225 $photon_count = array_reduce(
226 get_object_vars( wp_count_attachments( array( 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp' ) ) ),
227 function ( $i, $j ) {
228 return $i + $j;
229 }
230 );
231 if ( $photon_count > 0 ) {
232 $benefits[] = array(
233 'name' => 'image-hosting',
234 'title' => esc_html__( 'Image Hosting', 'jetpack' ),
235 'description' => esc_html__( 'Super-fast, mobile-ready images served by Jetpack', 'jetpack' ),
236 'value' => absint( $photon_count ),
237 );
238 }
239 }
240
241 // Number of VideoPress videos on the site.
242 if ( Jetpack::is_module_active( 'videopress' ) ) {
243 $videopress_attachments = wp_count_attachments( 'video/videopress' );
244 if (
245 isset( $videopress_attachments->{'video/videopress'} )
246 && $videopress_attachments->{'video/videopress'} > 0
247 ) {
248 $benefits[] = array(
249 'name' => 'video-hosting',
250 'title' => esc_html__( 'Video Hosting', 'jetpack' ),
251 'description' => esc_html__( 'Ad-free, lightning-fast videos delivered by Jetpack', 'jetpack' ),
252 'value' => absint( $videopress_attachments->{'video/videopress'} ),
253 );
254 }
255 }
256
257 // Number of active Publicize connections.
258 if ( Jetpack::is_module_active( 'publicize' ) && class_exists( 'Publicize' ) ) {
259 $publicize = new Publicize();
260 $connections = $publicize->get_all_connections();
261
262 $number_of_connections = 0;
263 if ( is_array( $connections ) && ! empty( $connections ) ) {
264 $number_of_connections = count( $connections );
265 }
266
267 if ( $number_of_connections > 0 ) {
268 $benefits[] = array(
269 'name' => 'publicize',
270 'title' => esc_html__( 'Jetpack Social', 'jetpack' ),
271 'description' => esc_html__( 'Live social media site connections, powered by Jetpack', 'jetpack' ),
272 'value' => absint( $number_of_connections ),
273 );
274 }
275 }
276
277 // Total number of shares.
278 if ( $has_stats && $stats->stats->shares > 0 ) {
279 $benefits[] = array(
280 'name' => 'sharing',
281 'title' => esc_html__( 'Sharing', 'jetpack' ),
282 'description' => esc_html__( 'The number of times visitors have shared your posts with the world using Jetpack', 'jetpack' ),
283 'value' => absint( $stats->stats->shares ),
284 );
285 }
286
287 if ( Jetpack::is_module_active( 'search' ) && ! class_exists( 'Automattic\\Jetpack\\Search_Plugin\\Jetpack_Search_Plugin' ) ) {
288 $benefits[] = array(
289 'name' => 'search',
290 'title' => esc_html__( 'Search', 'jetpack' ),
291 'description' => esc_html__( 'Help your visitors find exactly what they are looking for, fast', 'jetpack' ),
292 );
293 }
294
295 // Finally, return the whole list of benefits.
296 return rest_ensure_response(
297 array(
298 'code' => 'success',
299 'message' => esc_html__( 'Site benefits correctly received.', 'jetpack' ),
300 'data' => wp_json_encode( $benefits ),
301 )
302 );
303 }
304 }
305