Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Manager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Manager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class Manager { |
||
24 | /** |
||
25 | * A copy of the raw POST data for signature verification purposes. |
||
26 | * |
||
27 | * @var String |
||
28 | */ |
||
29 | protected $raw_post_data; |
||
30 | |||
31 | /** |
||
32 | * Verification data needs to be stored to properly verify everything. |
||
33 | * |
||
34 | * @var Object |
||
35 | */ |
||
36 | private $xmlrpc_verification = null; |
||
37 | |||
38 | /** |
||
39 | * Plugin management object. |
||
40 | * |
||
41 | * @var Plugin |
||
42 | */ |
||
43 | private $plugin = null; |
||
44 | |||
45 | /** |
||
46 | * Initialize the object. |
||
47 | * Make sure to call the "Configure" first. |
||
48 | * |
||
49 | * @param string $plugin_slug Slug of the plugin using the connection (optional, but encouraged). |
||
|
|||
50 | * |
||
51 | * @see \Automattic\Jetpack\Config |
||
52 | */ |
||
53 | public function __construct( $plugin_slug = null ) { |
||
54 | if ( $plugin_slug && is_string( $plugin_slug ) ) { |
||
55 | $this->set_plugin_instance( new Plugin( $plugin_slug ) ); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Initializes required listeners. This is done separately from the constructors |
||
61 | * because some objects sometimes need to instantiate separate objects of this class. |
||
62 | * |
||
63 | * @todo Implement a proper nonce verification. |
||
64 | */ |
||
65 | public static function configure() { |
||
66 | $manager = new self(); |
||
67 | |||
68 | add_filter( |
||
69 | 'jetpack_constant_default_value', |
||
70 | __NAMESPACE__ . '\Utils::jetpack_api_constant_filter', |
||
71 | 10, |
||
72 | 2 |
||
73 | ); |
||
74 | |||
75 | $manager->setup_xmlrpc_handlers( |
||
76 | $_GET, // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
77 | $manager->has_connected_owner(), |
||
78 | $manager->verify_xml_rpc_signature() |
||
79 | ); |
||
80 | |||
81 | $manager->error_handler = Error_Handler::get_instance(); |
||
82 | |||
83 | if ( $manager->is_connected() ) { |
||
84 | add_filter( 'xmlrpc_methods', array( $manager, 'public_xmlrpc_methods' ) ); |
||
85 | } |
||
86 | |||
87 | add_action( 'rest_api_init', array( $manager, 'initialize_rest_api_registration_connector' ) ); |
||
88 | |||
89 | ( new Nonce_Handler() )->init_schedule(); |
||
90 | |||
91 | add_action( 'plugins_loaded', __NAMESPACE__ . '\Plugin_Storage::configure', 100 ); |
||
92 | |||
93 | add_filter( 'map_meta_cap', array( $manager, 'jetpack_connection_custom_caps' ), 1, 4 ); |
||
94 | |||
95 | Heartbeat::init(); |
||
96 | add_filter( 'jetpack_heartbeat_stats_array', array( $manager, 'add_stats_to_heartbeat' ) ); |
||
97 | |||
98 | Webhooks::init( $manager ); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Sets up the XMLRPC request handlers. |
||
103 | * |
||
104 | * @since 9.6.0 Deprecate $is_active param. |
||
105 | * |
||
106 | * @param array $request_params incoming request parameters. |
||
107 | * @param bool $has_connected_owner Whether the site has a connected owner. |
||
108 | * @param bool $is_signed whether the signature check has been successful. |
||
109 | * @param \Jetpack_XMLRPC_Server $xmlrpc_server (optional) an instance of the server to use instead of instantiating a new one. |
||
110 | */ |
||
111 | public function setup_xmlrpc_handlers( |
||
112 | $request_params, |
||
113 | $has_connected_owner, |
||
114 | $is_signed, |
||
115 | \Jetpack_XMLRPC_Server $xmlrpc_server = null |
||
116 | ) { |
||
117 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ), 1000, 2 ); |
||
118 | |||
119 | if ( |
||
120 | ! isset( $request_params['for'] ) |
||
121 | || 'jetpack' !== $request_params['for'] |
||
122 | ) { |
||
123 | return false; |
||
124 | } |
||
125 | |||
126 | // Alternate XML-RPC, via ?for=jetpack&jetpack=comms. |
||
127 | if ( |
||
128 | isset( $request_params['jetpack'] ) |
||
129 | && 'comms' === $request_params['jetpack'] |
||
130 | ) { |
||
131 | if ( ! Constants::is_defined( 'XMLRPC_REQUEST' ) ) { |
||
132 | // Use the real constant here for WordPress' sake. |
||
133 | define( 'XMLRPC_REQUEST', true ); |
||
134 | } |
||
135 | |||
136 | add_action( 'template_redirect', array( $this, 'alternate_xmlrpc' ) ); |
||
137 | |||
138 | add_filter( 'xmlrpc_methods', array( $this, 'remove_non_jetpack_xmlrpc_methods' ), 1000 ); |
||
139 | } |
||
140 | |||
141 | if ( ! Constants::get_constant( 'XMLRPC_REQUEST' ) ) { |
||
142 | return false; |
||
143 | } |
||
144 | // Display errors can cause the XML to be not well formed. |
||
145 | @ini_set( 'display_errors', false ); // phpcs:ignore |
||
146 | |||
147 | if ( $xmlrpc_server ) { |
||
148 | $this->xmlrpc_server = $xmlrpc_server; |
||
149 | } else { |
||
150 | $this->xmlrpc_server = new \Jetpack_XMLRPC_Server(); |
||
151 | } |
||
152 | |||
153 | $this->require_jetpack_authentication(); |
||
154 | |||
155 | if ( $is_signed ) { |
||
156 | // If the site is connected either at a site or user level and the request is signed, expose the methods. |
||
157 | // The callback is responsible to determine whether the request is signed with blog or user token and act accordingly. |
||
158 | // The actual API methods. |
||
159 | $callback = array( $this->xmlrpc_server, 'xmlrpc_methods' ); |
||
160 | |||
161 | // Hack to preserve $HTTP_RAW_POST_DATA. |
||
162 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
163 | |||
164 | } elseif ( $has_connected_owner && ! $is_signed ) { |
||
165 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
166 | // active Jetpack connection, so that additional users can link their account. |
||
167 | $callback = array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ); |
||
168 | |||
169 | } else { |
||
170 | // Any other unsigned request should expose the bootstrap methods. |
||
171 | $callback = array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ); |
||
172 | new XMLRPC_Connector( $this ); |
||
173 | } |
||
174 | |||
175 | add_filter( 'xmlrpc_methods', $callback ); |
||
176 | |||
177 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
178 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
179 | return true; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Initializes the REST API connector on the init hook. |
||
184 | */ |
||
185 | public function initialize_rest_api_registration_connector() { |
||
186 | new REST_Connector( $this ); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
191 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
192 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
193 | * which is accessible via a different URI. Most of the below is copied directly |
||
194 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
195 | * |
||
196 | * @todo Tighten $wp_xmlrpc_server_class a bit to make sure it doesn't do bad things. |
||
197 | */ |
||
198 | public function alternate_xmlrpc() { |
||
199 | // Some browser-embedded clients send cookies. We don't want them. |
||
200 | $_COOKIE = array(); |
||
201 | |||
202 | include_once ABSPATH . 'wp-admin/includes/admin.php'; |
||
203 | include_once ABSPATH . WPINC . '/class-IXR.php'; |
||
204 | include_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'; |
||
205 | |||
206 | /** |
||
207 | * Filters the class used for handling XML-RPC requests. |
||
208 | * |
||
209 | * @since 3.1.0 |
||
210 | * |
||
211 | * @param string $class The name of the XML-RPC server class. |
||
212 | */ |
||
213 | $wp_xmlrpc_server_class = apply_filters( 'wp_xmlrpc_server_class', 'wp_xmlrpc_server' ); |
||
214 | $wp_xmlrpc_server = new $wp_xmlrpc_server_class(); |
||
215 | |||
216 | // Fire off the request. |
||
217 | nocache_headers(); |
||
218 | $wp_xmlrpc_server->serve_request(); |
||
219 | |||
220 | exit; |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
225 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
226 | * ensure that Core and other plugins' methods are not exposed. |
||
227 | * |
||
228 | * @param array $methods a list of registered WordPress XMLRPC methods. |
||
229 | * @return array filtered $methods |
||
230 | */ |
||
231 | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
||
232 | $jetpack_methods = array(); |
||
233 | |||
234 | foreach ( $methods as $method => $callback ) { |
||
235 | if ( 0 === strpos( $method, 'jetpack.' ) ) { |
||
236 | $jetpack_methods[ $method ] = $callback; |
||
237 | } |
||
238 | } |
||
239 | |||
240 | return $jetpack_methods; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Removes all other authentication methods not to allow other |
||
245 | * methods to validate unauthenticated requests. |
||
246 | */ |
||
247 | public function require_jetpack_authentication() { |
||
248 | // Don't let anyone authenticate. |
||
249 | $_COOKIE = array(); |
||
250 | remove_all_filters( 'authenticate' ); |
||
251 | remove_all_actions( 'wp_login_failed' ); |
||
252 | |||
253 | if ( $this->is_connected() ) { |
||
254 | // Allow Jetpack authentication. |
||
255 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
256 | } |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
261 | * |
||
262 | * @param WP_User|Mixed $user user object if authenticated. |
||
263 | * @param String $username username. |
||
264 | * @param String $password password string. |
||
265 | * @return WP_User|Mixed authenticated user or error. |
||
266 | */ |
||
267 | public function authenticate_jetpack( $user, $username, $password ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
268 | if ( is_a( $user, '\\WP_User' ) ) { |
||
269 | return $user; |
||
270 | } |
||
271 | |||
272 | $token_details = $this->verify_xml_rpc_signature(); |
||
273 | |||
274 | if ( ! $token_details ) { |
||
275 | return $user; |
||
276 | } |
||
277 | |||
278 | if ( 'user' !== $token_details['type'] ) { |
||
279 | return $user; |
||
280 | } |
||
281 | |||
282 | if ( ! $token_details['user_id'] ) { |
||
283 | return $user; |
||
284 | } |
||
285 | |||
286 | nocache_headers(); |
||
287 | |||
288 | return new \WP_User( $token_details['user_id'] ); |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * Verifies the signature of the current request. |
||
293 | * |
||
294 | * @return false|array |
||
295 | */ |
||
296 | public function verify_xml_rpc_signature() { |
||
297 | if ( is_null( $this->xmlrpc_verification ) ) { |
||
298 | $this->xmlrpc_verification = $this->internal_verify_xml_rpc_signature(); |
||
299 | |||
300 | if ( is_wp_error( $this->xmlrpc_verification ) ) { |
||
301 | /** |
||
302 | * Action for logging XMLRPC signature verification errors. This data is sensitive. |
||
303 | * |
||
304 | * @since 7.5.0 |
||
305 | * |
||
306 | * @param WP_Error $signature_verification_error The verification error |
||
307 | */ |
||
308 | do_action( 'jetpack_verify_signature_error', $this->xmlrpc_verification ); |
||
309 | |||
310 | Error_Handler::get_instance()->report_error( $this->xmlrpc_verification ); |
||
311 | |||
312 | } |
||
313 | } |
||
314 | |||
315 | return is_wp_error( $this->xmlrpc_verification ) ? false : $this->xmlrpc_verification; |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * Verifies the signature of the current request. |
||
320 | * |
||
321 | * This function has side effects and should not be used. Instead, |
||
322 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
323 | * |
||
324 | * @internal |
||
325 | * @todo Refactor to use proper nonce verification. |
||
326 | */ |
||
327 | private function internal_verify_xml_rpc_signature() { |
||
328 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
||
329 | // It's not for us. |
||
330 | if ( ! isset( $_GET['token'] ) || empty( $_GET['signature'] ) ) { |
||
331 | return false; |
||
332 | } |
||
333 | |||
334 | $signature_details = array( |
||
335 | 'token' => isset( $_GET['token'] ) ? wp_unslash( $_GET['token'] ) : '', |
||
336 | 'timestamp' => isset( $_GET['timestamp'] ) ? wp_unslash( $_GET['timestamp'] ) : '', |
||
337 | 'nonce' => isset( $_GET['nonce'] ) ? wp_unslash( $_GET['nonce'] ) : '', |
||
338 | 'body_hash' => isset( $_GET['body-hash'] ) ? wp_unslash( $_GET['body-hash'] ) : '', |
||
339 | 'method' => wp_unslash( $_SERVER['REQUEST_METHOD'] ), |
||
340 | 'url' => wp_unslash( $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ), // Temp - will get real signature URL later. |
||
341 | 'signature' => isset( $_GET['signature'] ) ? wp_unslash( $_GET['signature'] ) : '', |
||
342 | ); |
||
343 | |||
344 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
||
345 | @list( $token_key, $version, $user_id ) = explode( ':', wp_unslash( $_GET['token'] ) ); |
||
346 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
||
347 | |||
348 | $jetpack_api_version = Constants::get_constant( 'JETPACK__API_VERSION' ); |
||
349 | |||
350 | if ( |
||
351 | empty( $token_key ) |
||
352 | || |
||
353 | empty( $version ) || (string) $jetpack_api_version !== $version ) { |
||
354 | return new \WP_Error( 'malformed_token', 'Malformed token in request', compact( 'signature_details' ) ); |
||
355 | } |
||
356 | |||
357 | if ( '0' === $user_id ) { |
||
358 | $token_type = 'blog'; |
||
359 | $user_id = 0; |
||
360 | } else { |
||
361 | $token_type = 'user'; |
||
362 | if ( empty( $user_id ) || ! ctype_digit( $user_id ) ) { |
||
363 | return new \WP_Error( |
||
364 | 'malformed_user_id', |
||
365 | 'Malformed user_id in request', |
||
366 | compact( 'signature_details' ) |
||
367 | ); |
||
368 | } |
||
369 | $user_id = (int) $user_id; |
||
370 | |||
371 | $user = new \WP_User( $user_id ); |
||
372 | if ( ! $user || ! $user->exists() ) { |
||
373 | return new \WP_Error( |
||
374 | 'unknown_user', |
||
375 | sprintf( 'User %d does not exist', $user_id ), |
||
376 | compact( 'signature_details' ) |
||
377 | ); |
||
378 | } |
||
379 | } |
||
380 | |||
381 | $token = $this->get_tokens()->get_access_token( $user_id, $token_key, false ); |
||
382 | if ( is_wp_error( $token ) ) { |
||
383 | $token->add_data( compact( 'signature_details' ) ); |
||
384 | return $token; |
||
385 | } elseif ( ! $token ) { |
||
386 | return new \WP_Error( |
||
387 | 'unknown_token', |
||
388 | sprintf( 'Token %s:%s:%d does not exist', $token_key, $version, $user_id ), |
||
389 | compact( 'signature_details' ) |
||
390 | ); |
||
391 | } |
||
392 | |||
393 | $jetpack_signature = new \Jetpack_Signature( $token->secret, (int) \Jetpack_Options::get_option( 'time_diff' ) ); |
||
394 | // phpcs:disable WordPress.Security.NonceVerification.Missing |
||
395 | if ( isset( $_POST['_jetpack_is_multipart'] ) ) { |
||
396 | $post_data = $_POST; |
||
397 | $file_hashes = array(); |
||
398 | foreach ( $post_data as $post_data_key => $post_data_value ) { |
||
399 | if ( 0 !== strpos( $post_data_key, '_jetpack_file_hmac_' ) ) { |
||
400 | continue; |
||
401 | } |
||
402 | $post_data_key = substr( $post_data_key, strlen( '_jetpack_file_hmac_' ) ); |
||
403 | $file_hashes[ $post_data_key ] = $post_data_value; |
||
404 | } |
||
405 | |||
406 | foreach ( $file_hashes as $post_data_key => $post_data_value ) { |
||
407 | unset( $post_data[ "_jetpack_file_hmac_{$post_data_key}" ] ); |
||
408 | $post_data[ $post_data_key ] = $post_data_value; |
||
409 | } |
||
410 | |||
411 | ksort( $post_data ); |
||
412 | |||
413 | $body = http_build_query( stripslashes_deep( $post_data ) ); |
||
414 | } elseif ( is_null( $this->raw_post_data ) ) { |
||
415 | $body = file_get_contents( 'php://input' ); |
||
416 | } else { |
||
417 | $body = null; |
||
418 | } |
||
419 | // phpcs:enable |
||
420 | |||
421 | $signature = $jetpack_signature->sign_current_request( |
||
422 | array( 'body' => is_null( $body ) ? $this->raw_post_data : $body ) |
||
423 | ); |
||
424 | |||
425 | $signature_details['url'] = $jetpack_signature->current_request_url; |
||
426 | |||
427 | if ( ! $signature ) { |
||
428 | return new \WP_Error( |
||
429 | 'could_not_sign', |
||
430 | 'Unknown signature error', |
||
431 | compact( 'signature_details' ) |
||
432 | ); |
||
433 | } elseif ( is_wp_error( $signature ) ) { |
||
434 | return $signature; |
||
435 | } |
||
436 | |||
437 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
||
438 | $timestamp = (int) $_GET['timestamp']; |
||
439 | $nonce = stripslashes( (string) $_GET['nonce'] ); |
||
440 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
||
441 | |||
442 | // Use up the nonce regardless of whether the signature matches. |
||
443 | if ( ! ( new Nonce_Handler() )->add( $timestamp, $nonce ) ) { |
||
444 | return new \WP_Error( |
||
445 | 'invalid_nonce', |
||
446 | 'Could not add nonce', |
||
447 | compact( 'signature_details' ) |
||
448 | ); |
||
449 | } |
||
450 | |||
451 | // Be careful about what you do with this debugging data. |
||
452 | // If a malicious requester has access to the expected signature, |
||
453 | // bad things might be possible. |
||
454 | $signature_details['expected'] = $signature; |
||
455 | |||
456 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
457 | if ( ! hash_equals( $signature, $_GET['signature'] ) ) { |
||
458 | return new \WP_Error( |
||
459 | 'signature_mismatch', |
||
460 | 'Signature mismatch', |
||
461 | compact( 'signature_details' ) |
||
462 | ); |
||
463 | } |
||
464 | |||
465 | /** |
||
466 | * Action for additional token checking. |
||
467 | * |
||
468 | * @since 7.7.0 |
||
469 | * |
||
470 | * @param array $post_data request data. |
||
471 | * @param array $token_data token data. |
||
472 | */ |
||
473 | return apply_filters( |
||
474 | 'jetpack_signature_check_token', |
||
475 | array( |
||
476 | 'type' => $token_type, |
||
477 | 'token_key' => $token_key, |
||
478 | 'user_id' => $token->external_user_id, |
||
479 | ), |
||
480 | $token, |
||
481 | $this->raw_post_data |
||
482 | ); |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI. |
||
487 | * |
||
488 | * This method is deprecated since Jetpack 9.6.0. Please use has_connected_owner instead. |
||
489 | * |
||
490 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
491 | * |
||
492 | * @deprecated 9.6.0 |
||
493 | * @see Manager::has_connected_owner |
||
494 | * @return Boolean is the site connected? |
||
495 | */ |
||
496 | public function is_active() { |
||
497 | return (bool) $this->get_tokens()->get_access_token( true ); |
||
498 | } |
||
499 | |||
500 | /** |
||
501 | * Obtains an instance of the Tokens class. |
||
502 | * |
||
503 | * @return Tokens the Tokens object |
||
504 | */ |
||
505 | public function get_tokens() { |
||
506 | return new Tokens(); |
||
507 | } |
||
508 | |||
509 | /** |
||
510 | * Returns true if the site has both a token and a blog id, which indicates a site has been registered. |
||
511 | * |
||
512 | * @access public |
||
513 | * @deprecated 9.2.0 Use is_connected instead |
||
514 | * @see Manager::is_connected |
||
515 | * |
||
516 | * @return bool |
||
517 | */ |
||
518 | public function is_registered() { |
||
519 | _deprecated_function( __METHOD__, 'jetpack-9.2' ); |
||
520 | return $this->is_connected(); |
||
521 | } |
||
522 | |||
523 | /** |
||
524 | * Returns true if the site has both a token and a blog id, which indicates a site has been connected. |
||
525 | * |
||
526 | * @access public |
||
527 | * @since 9.2.0 |
||
528 | * |
||
529 | * @return bool |
||
530 | */ |
||
531 | public function is_connected() { |
||
532 | $has_blog_id = (bool) \Jetpack_Options::get_option( 'id' ); |
||
533 | $has_blog_token = (bool) $this->get_tokens()->get_access_token(); |
||
534 | return $has_blog_id && $has_blog_token; |
||
535 | } |
||
536 | |||
537 | /** |
||
538 | * Returns true if the site has at least one connected administrator. |
||
539 | * |
||
540 | * @access public |
||
541 | * @since 9.2.0 |
||
542 | * |
||
543 | * @return bool |
||
544 | */ |
||
545 | public function has_connected_admin() { |
||
546 | return (bool) count( $this->get_connected_users( 'manage_options' ) ); |
||
547 | } |
||
548 | |||
549 | /** |
||
550 | * Returns true if the site has any connected user. |
||
551 | * |
||
552 | * @access public |
||
553 | * @since 9.2.0 |
||
554 | * |
||
555 | * @return bool |
||
556 | */ |
||
557 | public function has_connected_user() { |
||
558 | return (bool) count( $this->get_connected_users() ); |
||
559 | } |
||
560 | |||
561 | /** |
||
562 | * Returns an array of user_id's that have user tokens for communicating with wpcom. |
||
563 | * Able to select by specific capability. |
||
564 | * |
||
565 | * @param string $capability The capability of the user. |
||
566 | * @return array Array of WP_User objects if found. |
||
567 | */ |
||
568 | public function get_connected_users( $capability = 'any' ) { |
||
569 | return $this->get_tokens()->get_connected_users( $capability ); |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * Returns true if the site has a connected Blog owner (master_user). |
||
574 | * |
||
575 | * @access public |
||
576 | * @since 9.2.0 |
||
577 | * |
||
578 | * @return bool |
||
579 | */ |
||
580 | public function has_connected_owner() { |
||
583 | |||
584 | /** |
||
585 | * Returns true if the site is connected only at a site level. |
||
586 | * |
||
587 | * Note that we are explicitly checking for the existence of the master_user option in order to account for cases where we don't have any user tokens (user-level connection) but the master_user option is set, which could be the result of a problematic user connection. |
||
588 | * |
||
589 | * @access public |
||
590 | * @since 9.6.0 |
||
591 | * |
||
592 | * @return bool |
||
593 | */ |
||
594 | public function is_userless() { |
||
595 | return $this->is_connected() && ! $this->has_connected_user() && ! \Jetpack_Options::get_option( 'master_user' ); |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * Checks to see if the connection owner of the site is missing. |
||
600 | * |
||
601 | * @return bool |
||
602 | */ |
||
603 | public function is_missing_connection_owner() { |
||
604 | $connection_owner = $this->get_connection_owner_id(); |
||
605 | if ( ! get_user_by( 'id', $connection_owner ) ) { |
||
606 | return true; |
||
607 | } |
||
608 | |||
609 | return false; |
||
610 | } |
||
611 | |||
612 | /** |
||
613 | * Returns true if the user with the specified identifier is connected to |
||
614 | * WordPress.com. |
||
615 | * |
||
616 | * @param int $user_id the user identifier. Default is the current user. |
||
617 | * @return bool Boolean is the user connected? |
||
618 | */ |
||
619 | public function is_user_connected( $user_id = false ) { |
||
620 | $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); |
||
621 | if ( ! $user_id ) { |
||
622 | return false; |
||
623 | } |
||
624 | |||
625 | return (bool) $this->get_tokens()->get_access_token( $user_id ); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * Returns the local user ID of the connection owner. |
||
630 | * |
||
631 | * @return bool|int Returns the ID of the connection owner or False if no connection owner found. |
||
632 | */ |
||
633 | public function get_connection_owner_id() { |
||
634 | $owner = $this->get_connection_owner(); |
||
635 | return $owner instanceof \WP_User ? $owner->ID : false; |
||
636 | } |
||
637 | |||
638 | /** |
||
639 | * Get the wpcom user data of the current|specified connected user. |
||
640 | * |
||
641 | * @todo Refactor to properly load the XMLRPC client independently. |
||
642 | * |
||
643 | * @param Integer $user_id the user identifier. |
||
644 | * @return Object the user object. |
||
645 | */ |
||
646 | public function get_connected_user_data( $user_id = null ) { |
||
672 | |||
673 | /** |
||
674 | * Returns a user object of the connection owner. |
||
675 | * |
||
676 | * @return WP_User|false False if no connection owner found. |
||
677 | */ |
||
678 | public function get_connection_owner() { |
||
697 | |||
698 | /** |
||
699 | * Returns true if the provided user is the Jetpack connection owner. |
||
700 | * If user ID is not specified, the current user will be used. |
||
701 | * |
||
702 | * @param Integer|Boolean $user_id the user identifier. False for current user. |
||
703 | * @return Boolean True the user the connection owner, false otherwise. |
||
704 | */ |
||
705 | public function is_connection_owner( $user_id = false ) { |
||
712 | |||
713 | /** |
||
714 | * Connects the user with a specified ID to a WordPress.com user using the |
||
715 | * remote login flow. |
||
716 | * |
||
717 | * @access public |
||
718 | * |
||
719 | * @param Integer $user_id (optional) the user identifier, defaults to current user. |
||
720 | * @param String $redirect_url the URL to redirect the user to for processing, defaults to |
||
721 | * admin_url(). |
||
722 | * @return WP_Error only in case of a failed user lookup. |
||
723 | */ |
||
724 | public function connect_user( $user_id = null, $redirect_url = null ) { |
||
744 | |||
745 | /** |
||
746 | * Unlinks the current user from the linked WordPress.com user. |
||
747 | * |
||
748 | * @access public |
||
749 | * @static |
||
750 | * |
||
751 | * @todo Refactor to properly load the XMLRPC client independently. |
||
752 | * |
||
753 | * @param Integer $user_id the user identifier. |
||
754 | * @param bool $can_overwrite_primary_user Allow for the primary user to be disconnected. |
||
755 | * @return Boolean Whether the disconnection of the user was successful. |
||
756 | */ |
||
757 | public function disconnect_user( $user_id = null, $can_overwrite_primary_user = false ) { |
||
758 | $user_id = empty( $user_id ) ? get_current_user_id() : (int) $user_id; |
||
759 | |||
760 | $result = $this->get_tokens()->disconnect_user( $user_id, $can_overwrite_primary_user ); |
||
761 | |||
762 | if ( $result ) { |
||
763 | $xml = new \Jetpack_IXR_Client( compact( 'user_id' ) ); |
||
764 | $xml->query( 'jetpack.unlink_user', $user_id ); |
||
765 | |||
781 | |||
782 | /** |
||
783 | * Returns the requested Jetpack API URL. |
||
784 | * |
||
785 | * @param String $relative_url the relative API path. |
||
786 | * @return String API URL. |
||
787 | */ |
||
788 | public function api_url( $relative_url ) { |
||
825 | |||
826 | /** |
||
827 | * Returns the Jetpack XMLRPC WordPress.com API endpoint URL. |
||
828 | * |
||
829 | * @return String XMLRPC API URL. |
||
830 | */ |
||
831 | public function xmlrpc_api_url() { |
||
839 | |||
840 | /** |
||
841 | * Attempts Jetpack registration which sets up the site for connection. Should |
||
842 | * remain public because the call to action comes from the current site, not from |
||
843 | * WordPress.com. |
||
844 | * |
||
845 | * @param String $api_endpoint (optional) an API endpoint to use, defaults to 'register'. |
||
846 | * @return true|WP_Error The error object. |
||
847 | */ |
||
848 | public function register( $api_endpoint = 'register' ) { |
||
991 | |||
992 | /** |
||
993 | * Attempts Jetpack registration. |
||
994 | * |
||
995 | * @param bool $tos_agree Whether the user agreed to TOS. |
||
996 | * |
||
997 | * @return bool|WP_Error |
||
998 | */ |
||
999 | public function try_registration( $tos_agree = true ) { |
||
1038 | |||
1039 | /** |
||
1040 | * Takes the response from the Jetpack register new site endpoint and |
||
1041 | * verifies it worked properly. |
||
1042 | * |
||
1043 | * @since 2.6 |
||
1044 | * |
||
1045 | * @param Mixed $response the response object, or the error object. |
||
1046 | * @return string|WP_Error A JSON object on success or WP_Error on failures |
||
1047 | **/ |
||
1048 | protected function validate_remote_register_response( $response ) { |
||
1117 | |||
1118 | /** |
||
1119 | * Adds a used nonce to a list of known nonces. |
||
1120 | * |
||
1121 | * @param int $timestamp the current request timestamp. |
||
1122 | * @param string $nonce the nonce value. |
||
1123 | * @return bool whether the nonce is unique or not. |
||
1124 | * |
||
1125 | * @deprecated since 9.5.0 |
||
1126 | * @see Nonce_Handler::add() |
||
1127 | */ |
||
1128 | public function add_nonce( $timestamp, $nonce ) { |
||
1132 | |||
1133 | /** |
||
1134 | * Cleans nonces that were saved when calling ::add_nonce. |
||
1135 | * |
||
1136 | * @todo Properly prepare the query before executing it. |
||
1137 | * |
||
1138 | * @param bool $all whether to clean even non-expired nonces. |
||
1139 | * |
||
1140 | * @deprecated since 9.5.0 |
||
1141 | * @see Nonce_Handler::clean_all() |
||
1142 | */ |
||
1143 | public function clean_nonces( $all = false ) { |
||
1147 | |||
1148 | /** |
||
1149 | * Sets the Connection custom capabilities. |
||
1150 | * |
||
1151 | * @param string[] $caps Array of the user's capabilities. |
||
1152 | * @param string $cap Capability name. |
||
1153 | * @param int $user_id The user ID. |
||
1154 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1155 | */ |
||
1156 | public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1189 | |||
1190 | /** |
||
1191 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
1192 | * |
||
1193 | * Based on local php max_execution_time in php.ini |
||
1194 | * |
||
1195 | * @since 5.4 |
||
1196 | * @return int |
||
1197 | **/ |
||
1198 | public function get_max_execution_time() { |
||
1207 | |||
1208 | /** |
||
1209 | * Sets a minimum request timeout, and returns the current timeout |
||
1210 | * |
||
1211 | * @since 5.4 |
||
1212 | * @param Integer $min_timeout the minimum timeout value. |
||
1213 | **/ |
||
1214 | View Code Duplication | public function set_min_time_limit( $min_timeout ) { |
|
1222 | |||
1223 | /** |
||
1224 | * Get our assumed site creation date. |
||
1225 | * Calculated based on the earlier date of either: |
||
1226 | * - Earliest admin user registration date. |
||
1227 | * - Earliest date of post of any post type. |
||
1228 | * |
||
1229 | * @since 7.2.0 |
||
1230 | * |
||
1231 | * @return string Assumed site creation date and time. |
||
1232 | */ |
||
1233 | public function get_assumed_site_creation_date() { |
||
1272 | |||
1273 | /** |
||
1274 | * Adds the activation source string as a parameter to passed arguments. |
||
1275 | * |
||
1276 | * @todo Refactor to use rawurlencode() instead of urlencode(). |
||
1277 | * |
||
1278 | * @param array $args arguments that need to have the source added. |
||
1279 | * @return array $amended arguments. |
||
1280 | */ |
||
1281 | View Code Duplication | public static function apply_activation_source_to_args( $args ) { |
|
1296 | |||
1297 | /** |
||
1298 | * Generates two secret tokens and the end of life timestamp for them. |
||
1299 | * |
||
1300 | * @param String $action The action name. |
||
1301 | * @param Integer $user_id The user identifier. |
||
1302 | * @param Integer $exp Expiration time in seconds. |
||
1303 | */ |
||
1304 | public function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
1307 | |||
1308 | /** |
||
1309 | * Returns two secret tokens and the end of life timestamp for them. |
||
1310 | * |
||
1311 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->get() instead. |
||
1312 | * |
||
1313 | * @param String $action The action name. |
||
1314 | * @param Integer $user_id The user identifier. |
||
1315 | * @return string|array an array of secrets or an error string. |
||
1316 | */ |
||
1317 | public function get_secrets( $action, $user_id ) { |
||
1321 | |||
1322 | /** |
||
1323 | * Deletes secret tokens in case they, for example, have expired. |
||
1324 | * |
||
1325 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->delete() instead. |
||
1326 | * |
||
1327 | * @param String $action The action name. |
||
1328 | * @param Integer $user_id The user identifier. |
||
1329 | */ |
||
1330 | public function delete_secrets( $action, $user_id ) { |
||
1334 | |||
1335 | /** |
||
1336 | * Deletes all connection tokens and transients from the local Jetpack site. |
||
1337 | * If the plugin object has been provided in the constructor, the function first checks |
||
1338 | * whether it's the only active connection. |
||
1339 | * If there are any other connections, the function will do nothing and return `false` |
||
1340 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1341 | * |
||
1342 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1343 | * |
||
1344 | * @return bool True if disconnected successfully, false otherwise. |
||
1345 | */ |
||
1346 | public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { |
||
1382 | |||
1383 | /** |
||
1384 | * Tells WordPress.com to disconnect the site and clear all tokens from cached site. |
||
1385 | * If the plugin object has been provided in the constructor, the function first check |
||
1386 | * whether it's the only active connection. |
||
1387 | * If there are any other connections, the function will do nothing and return `false` |
||
1388 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1389 | * |
||
1390 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1391 | * |
||
1392 | * @return bool True if disconnected successfully, false otherwise. |
||
1393 | */ |
||
1394 | public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { |
||
1414 | |||
1415 | /** |
||
1416 | * Disconnect the plugin and remove the tokens. |
||
1417 | * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. |
||
1418 | * This is a proxy method to simplify the Connection package API. |
||
1419 | * |
||
1420 | * @see Manager::disable_plugin() |
||
1421 | * @see Manager::disconnect_site_wpcom() |
||
1422 | * @see Manager::delete_all_connection_tokens() |
||
1423 | * |
||
1424 | * @return bool |
||
1425 | */ |
||
1426 | public function remove_connection() { |
||
1433 | |||
1434 | /** |
||
1435 | * Completely clearing up the connection, and initiating reconnect. |
||
1436 | * |
||
1437 | * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. |
||
1438 | */ |
||
1439 | public function reconnect() { |
||
1447 | |||
1448 | /** |
||
1449 | * Validate the tokens, and refresh the invalid ones. |
||
1450 | * |
||
1451 | * @return string|bool|WP_Error True if connection restored or string indicating what's to be done next. A `WP_Error` object or false otherwise. |
||
1452 | */ |
||
1453 | public function restore() { |
||
1489 | |||
1490 | /** |
||
1491 | * Responds to a WordPress.com call to register the current site. |
||
1492 | * Should be changed to protected. |
||
1493 | * |
||
1494 | * @param array $registration_data Array of [ secret_1, user_id ]. |
||
1495 | */ |
||
1496 | public function handle_registration( array $registration_data ) { |
||
1504 | |||
1505 | /** |
||
1506 | * Perform the API request to validate the blog and user tokens. |
||
1507 | * |
||
1508 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->validate_tokens() instead. |
||
1509 | * |
||
1510 | * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. |
||
1511 | * |
||
1512 | * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. |
||
1513 | */ |
||
1514 | public function validate_tokens( $user_id = null ) { |
||
1518 | |||
1519 | /** |
||
1520 | * Verify a Previously Generated Secret. |
||
1521 | * |
||
1522 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->verify() instead. |
||
1523 | * |
||
1524 | * @param string $action The type of secret to verify. |
||
1525 | * @param string $secret_1 The secret string to compare to what is stored. |
||
1526 | * @param int $user_id The user ID of the owner of the secret. |
||
1527 | * @return \WP_Error|string WP_Error on failure, secret_2 on success. |
||
1528 | */ |
||
1529 | public function verify_secrets( $action, $secret_1, $user_id ) { |
||
1533 | |||
1534 | /** |
||
1535 | * Responds to a WordPress.com call to authorize the current user. |
||
1536 | * Should be changed to protected. |
||
1537 | */ |
||
1538 | public function handle_authorization() { |
||
1541 | |||
1542 | /** |
||
1543 | * Obtains the auth token. |
||
1544 | * |
||
1545 | * @param array $data The request data. |
||
1546 | * @return object|\WP_Error Returns the auth token on success. |
||
1547 | * Returns a \WP_Error on failure. |
||
1548 | */ |
||
1549 | public function get_token( $data ) { |
||
1552 | |||
1553 | /** |
||
1554 | * Builds a URL to the Jetpack connection auth page. |
||
1555 | * |
||
1556 | * @param WP_User $user (optional) defaults to the current logged in user. |
||
1557 | * @param String $redirect (optional) a redirect URL to use instead of the default. |
||
1558 | * @return string Connect URL. |
||
1559 | */ |
||
1560 | public function get_authorization_url( $user = null, $redirect = null ) { |
||
1646 | |||
1647 | /** |
||
1648 | * Authorizes the user by obtaining and storing the user token. |
||
1649 | * |
||
1650 | * @param array $data The request data. |
||
1651 | * @return string|\WP_Error Returns a string on success. |
||
1652 | * Returns a \WP_Error on failure. |
||
1653 | */ |
||
1654 | public function authorize( $data = array() ) { |
||
1745 | |||
1746 | /** |
||
1747 | * Disconnects from the Jetpack servers. |
||
1748 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
1749 | */ |
||
1750 | public function disconnect_site() { |
||
1753 | |||
1754 | /** |
||
1755 | * The Base64 Encoding of the SHA1 Hash of the Input. |
||
1756 | * |
||
1757 | * @param string $text The string to hash. |
||
1758 | * @return string |
||
1759 | */ |
||
1760 | public function sha1_base64( $text ) { |
||
1763 | |||
1764 | /** |
||
1765 | * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. |
||
1766 | * |
||
1767 | * @param string $domain The domain to check. |
||
1768 | * |
||
1769 | * @return bool|WP_Error |
||
1770 | */ |
||
1771 | public function is_usable_domain( $domain ) { |
||
1858 | |||
1859 | /** |
||
1860 | * Gets the requested token. |
||
1861 | * |
||
1862 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead. |
||
1863 | * |
||
1864 | * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. |
||
1865 | * @param string|false $token_key If provided, check that the token matches the provided input. |
||
1866 | * @param bool|true $suppress_errors If true, return a falsy value when the token isn't found; When false, return a descriptive WP_Error when the token isn't found. |
||
1867 | * |
||
1868 | * @return object|false |
||
1869 | * |
||
1870 | * @see $this->get_tokens()->get_access_token() |
||
1871 | */ |
||
1872 | public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { |
||
1876 | |||
1877 | /** |
||
1878 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths |
||
1879 | * since it is passed by reference to various methods. |
||
1880 | * Capture it here so we can verify the signature later. |
||
1881 | * |
||
1882 | * @param array $methods an array of available XMLRPC methods. |
||
1883 | * @return array the same array, since this method doesn't add or remove anything. |
||
1884 | */ |
||
1885 | public function xmlrpc_methods( $methods ) { |
||
1889 | |||
1890 | /** |
||
1891 | * Resets the raw post data parameter for testing purposes. |
||
1892 | */ |
||
1893 | public function reset_raw_post_data() { |
||
1896 | |||
1897 | /** |
||
1898 | * Registering an additional method. |
||
1899 | * |
||
1900 | * @param array $methods an array of available XMLRPC methods. |
||
1901 | * @return array the amended array in case the method is added. |
||
1902 | */ |
||
1903 | public function public_xmlrpc_methods( $methods ) { |
||
1909 | |||
1910 | /** |
||
1911 | * Handles a getOptions XMLRPC method call. |
||
1912 | * |
||
1913 | * @param array $args method call arguments. |
||
1914 | * @return an amended XMLRPC server options array. |
||
1915 | */ |
||
1916 | public function jetpack_get_options( $args ) { |
||
1957 | |||
1958 | /** |
||
1959 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
1960 | * |
||
1961 | * @param array $options standard Core options. |
||
1962 | * @return array amended options. |
||
1963 | */ |
||
1964 | public function xmlrpc_options( $options ) { |
||
1982 | |||
1983 | /** |
||
1984 | * Resets the saved authentication state in between testing requests. |
||
1985 | */ |
||
1986 | public function reset_saved_auth_state() { |
||
1989 | |||
1990 | /** |
||
1991 | * Sign a user role with the master access token. |
||
1992 | * If not specified, will default to the current user. |
||
1993 | * |
||
1994 | * @access public |
||
1995 | * |
||
1996 | * @param string $role User role. |
||
1997 | * @param int $user_id ID of the user. |
||
1998 | * @return string Signed user role. |
||
1999 | */ |
||
2000 | public function sign_role( $role, $user_id = null ) { |
||
2003 | |||
2004 | /** |
||
2005 | * Set the plugin instance. |
||
2006 | * |
||
2007 | * @param Plugin $plugin_instance The plugin instance. |
||
2008 | * |
||
2009 | * @return $this |
||
2010 | */ |
||
2011 | public function set_plugin_instance( Plugin $plugin_instance ) { |
||
2016 | |||
2017 | /** |
||
2018 | * Retrieve the plugin management object. |
||
2019 | * |
||
2020 | * @return Plugin|null |
||
2021 | */ |
||
2022 | public function get_plugin() { |
||
2025 | |||
2026 | /** |
||
2027 | * Get all connected plugins information, excluding those disconnected by user. |
||
2028 | * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded |
||
2029 | * Even if you don't use Jetpack Config, it may be introduced later by other plugins, |
||
2030 | * so please make sure not to run the method too early in the code. |
||
2031 | * |
||
2032 | * @return array|WP_Error |
||
2033 | */ |
||
2034 | public function get_connected_plugins() { |
||
2043 | |||
2044 | /** |
||
2045 | * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. |
||
2046 | * Note: this method does not remove any access tokens. |
||
2047 | * |
||
2048 | * @return bool |
||
2049 | */ |
||
2050 | public function disable_plugin() { |
||
2057 | |||
2058 | /** |
||
2059 | * Force plugin reconnect after user-initiated disconnect. |
||
2060 | * After its called, the plugin will be allowed to use the connection again. |
||
2061 | * Note: this method does not initialize access tokens. |
||
2062 | * |
||
2063 | * @return bool |
||
2064 | */ |
||
2065 | public function enable_plugin() { |
||
2072 | |||
2073 | /** |
||
2074 | * Whether the plugin is allowed to use the connection, or it's been disconnected by user. |
||
2075 | * If no plugin slug was passed into the constructor, always returns true. |
||
2076 | * |
||
2077 | * @return bool |
||
2078 | */ |
||
2079 | public function is_plugin_enabled() { |
||
2086 | |||
2087 | /** |
||
2088 | * Perform the API request to refresh the blog token. |
||
2089 | * Note that we are making this request on behalf of the Jetpack master user, |
||
2090 | * given they were (most probably) the ones that registered the site at the first place. |
||
2091 | * |
||
2092 | * @return WP_Error|bool The result of updating the blog_token option. |
||
2093 | */ |
||
2094 | public function refresh_blog_token() { |
||
2144 | |||
2145 | /** |
||
2146 | * Disconnect the user from WP.com, and initiate the reconnect process. |
||
2147 | * |
||
2148 | * @return bool |
||
2149 | */ |
||
2150 | public function refresh_user_token() { |
||
2155 | |||
2156 | /** |
||
2157 | * Fetches a signed token. |
||
2158 | * |
||
2159 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead. |
||
2160 | * |
||
2161 | * @param object $token the token. |
||
2162 | * @return WP_Error|string a signed token |
||
2163 | */ |
||
2164 | public function get_signed_token( $token ) { |
||
2168 | |||
2169 | /** |
||
2170 | * If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) |
||
2171 | * |
||
2172 | * @param array $stats The Heartbeat stats array. |
||
2173 | * @return array $stats |
||
2174 | */ |
||
2175 | public function add_stats_to_heartbeat( $stats ) { |
||
2190 | } |
||
2191 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.