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 | * Holds extra parameters that will be sent along in the register request body. |
||
47 | * |
||
48 | * Use Manager::add_register_request_param to add values to this array. |
||
49 | * |
||
50 | * @since 9.7.0 |
||
51 | * @var array |
||
52 | */ |
||
53 | private static $extra_register_params = array(); |
||
54 | |||
55 | /** |
||
56 | * Initialize the object. |
||
57 | * Make sure to call the "Configure" first. |
||
58 | * |
||
59 | * @param string $plugin_slug Slug of the plugin using the connection (optional, but encouraged). |
||
|
|||
60 | * |
||
61 | * @see \Automattic\Jetpack\Config |
||
62 | */ |
||
63 | public function __construct( $plugin_slug = null ) { |
||
68 | |||
69 | /** |
||
70 | * Initializes required listeners. This is done separately from the constructors |
||
71 | * because some objects sometimes need to instantiate separate objects of this class. |
||
72 | * |
||
73 | * @todo Implement a proper nonce verification. |
||
74 | */ |
||
75 | public static function configure() { |
||
110 | |||
111 | /** |
||
112 | * Sets up the XMLRPC request handlers. |
||
113 | * |
||
114 | * @since 9.6.0 Deprecate $is_active param. |
||
115 | * |
||
116 | * @param array $request_params incoming request parameters. |
||
117 | * @param bool $has_connected_owner Whether the site has a connected owner. |
||
118 | * @param bool $is_signed whether the signature check has been successful. |
||
119 | * @param \Jetpack_XMLRPC_Server $xmlrpc_server (optional) an instance of the server to use instead of instantiating a new one. |
||
120 | */ |
||
121 | public function setup_xmlrpc_handlers( |
||
191 | |||
192 | /** |
||
193 | * Initializes the REST API connector on the init hook. |
||
194 | */ |
||
195 | public function initialize_rest_api_registration_connector() { |
||
198 | |||
199 | /** |
||
200 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
201 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
202 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
203 | * which is accessible via a different URI. Most of the below is copied directly |
||
204 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
205 | * |
||
206 | * @todo Tighten $wp_xmlrpc_server_class a bit to make sure it doesn't do bad things. |
||
207 | */ |
||
208 | public function alternate_xmlrpc() { |
||
232 | |||
233 | /** |
||
234 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
235 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
236 | * ensure that Core and other plugins' methods are not exposed. |
||
237 | * |
||
238 | * @param array $methods a list of registered WordPress XMLRPC methods. |
||
239 | * @return array filtered $methods |
||
240 | */ |
||
241 | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
||
252 | |||
253 | /** |
||
254 | * Removes all other authentication methods not to allow other |
||
255 | * methods to validate unauthenticated requests. |
||
256 | */ |
||
257 | public function require_jetpack_authentication() { |
||
268 | |||
269 | /** |
||
270 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
271 | * |
||
272 | * @param WP_User|Mixed $user user object if authenticated. |
||
273 | * @param String $username username. |
||
274 | * @param String $password password string. |
||
275 | * @return WP_User|Mixed authenticated user or error. |
||
276 | */ |
||
277 | public function authenticate_jetpack( $user, $username, $password ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
300 | |||
301 | /** |
||
302 | * Verifies the signature of the current request. |
||
303 | * |
||
304 | * @return false|array |
||
305 | */ |
||
306 | public function verify_xml_rpc_signature() { |
||
327 | |||
328 | /** |
||
329 | * Verifies the signature of the current request. |
||
330 | * |
||
331 | * This function has side effects and should not be used. Instead, |
||
332 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
333 | * |
||
334 | * @internal |
||
335 | * @todo Refactor to use proper nonce verification. |
||
336 | */ |
||
337 | private function internal_verify_xml_rpc_signature() { |
||
494 | |||
495 | /** |
||
496 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI. |
||
497 | * |
||
498 | * This method is deprecated since Jetpack 9.6.0. Please use has_connected_owner instead. |
||
499 | * |
||
500 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
501 | * |
||
502 | * @deprecated 9.6.0 |
||
503 | * @see Manager::has_connected_owner |
||
504 | * @return Boolean is the site connected? |
||
505 | */ |
||
506 | public function is_active() { |
||
509 | |||
510 | /** |
||
511 | * Obtains an instance of the Tokens class. |
||
512 | * |
||
513 | * @return Tokens the Tokens object |
||
514 | */ |
||
515 | public function get_tokens() { |
||
518 | |||
519 | /** |
||
520 | * Returns true if the site has both a token and a blog id, which indicates a site has been registered. |
||
521 | * |
||
522 | * @access public |
||
523 | * @deprecated 9.2.0 Use is_connected instead |
||
524 | * @see Manager::is_connected |
||
525 | * |
||
526 | * @return bool |
||
527 | */ |
||
528 | public function is_registered() { |
||
532 | |||
533 | /** |
||
534 | * Returns true if the site has both a token and a blog id, which indicates a site has been connected. |
||
535 | * |
||
536 | * @access public |
||
537 | * @since 9.2.0 |
||
538 | * |
||
539 | * @return bool |
||
540 | */ |
||
541 | public function is_connected() { |
||
546 | |||
547 | /** |
||
548 | * Returns true if the site has at least one connected administrator. |
||
549 | * |
||
550 | * @access public |
||
551 | * @since 9.2.0 |
||
552 | * |
||
553 | * @return bool |
||
554 | */ |
||
555 | public function has_connected_admin() { |
||
558 | |||
559 | /** |
||
560 | * Returns true if the site has any connected user. |
||
561 | * |
||
562 | * @access public |
||
563 | * @since 9.2.0 |
||
564 | * |
||
565 | * @return bool |
||
566 | */ |
||
567 | public function has_connected_user() { |
||
570 | |||
571 | /** |
||
572 | * Returns an array of user_id's that have user tokens for communicating with wpcom. |
||
573 | * Able to select by specific capability. |
||
574 | * |
||
575 | * @param string $capability The capability of the user. |
||
576 | * @return array Array of WP_User objects if found. |
||
577 | */ |
||
578 | public function get_connected_users( $capability = 'any' ) { |
||
581 | |||
582 | /** |
||
583 | * Returns true if the site has a connected Blog owner (master_user). |
||
584 | * |
||
585 | * @access public |
||
586 | * @since 9.2.0 |
||
587 | * |
||
588 | * @return bool |
||
589 | */ |
||
590 | public function has_connected_owner() { |
||
593 | |||
594 | /** |
||
595 | * Returns true if the site is connected only at a site level. |
||
596 | * |
||
597 | * 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. |
||
598 | * |
||
599 | * @access public |
||
600 | * @since 9.6.0 |
||
601 | * |
||
602 | * @return bool |
||
603 | */ |
||
604 | public function is_userless() { |
||
607 | |||
608 | /** |
||
609 | * Checks to see if the connection owner of the site is missing. |
||
610 | * |
||
611 | * @return bool |
||
612 | */ |
||
613 | public function is_missing_connection_owner() { |
||
621 | |||
622 | /** |
||
623 | * Returns true if the user with the specified identifier is connected to |
||
624 | * WordPress.com. |
||
625 | * |
||
626 | * @param int $user_id the user identifier. Default is the current user. |
||
627 | * @return bool Boolean is the user connected? |
||
628 | */ |
||
629 | public function is_user_connected( $user_id = false ) { |
||
637 | |||
638 | /** |
||
639 | * Returns the local user ID of the connection owner. |
||
640 | * |
||
641 | * @return bool|int Returns the ID of the connection owner or False if no connection owner found. |
||
642 | */ |
||
643 | public function get_connection_owner_id() { |
||
647 | |||
648 | /** |
||
649 | * Get the wpcom user data of the current|specified connected user. |
||
650 | * |
||
651 | * @todo Refactor to properly load the XMLRPC client independently. |
||
652 | * |
||
653 | * @param Integer $user_id the user identifier. |
||
654 | * @return Object the user object. |
||
655 | */ |
||
656 | public function get_connected_user_data( $user_id = null ) { |
||
682 | |||
683 | /** |
||
684 | * Returns a user object of the connection owner. |
||
685 | * |
||
686 | * @return WP_User|false False if no connection owner found. |
||
687 | */ |
||
688 | public function get_connection_owner() { |
||
707 | |||
708 | /** |
||
709 | * Returns true if the provided user is the Jetpack connection owner. |
||
710 | * If user ID is not specified, the current user will be used. |
||
711 | * |
||
712 | * @param Integer|Boolean $user_id the user identifier. False for current user. |
||
713 | * @return Boolean True the user the connection owner, false otherwise. |
||
714 | */ |
||
715 | public function is_connection_owner( $user_id = false ) { |
||
722 | |||
723 | /** |
||
724 | * Connects the user with a specified ID to a WordPress.com user using the |
||
725 | * remote login flow. |
||
726 | * |
||
727 | * @access public |
||
728 | * |
||
729 | * @param Integer $user_id (optional) the user identifier, defaults to current user. |
||
730 | * @param String $redirect_url the URL to redirect the user to for processing, defaults to |
||
731 | * admin_url(). |
||
732 | * @return WP_Error only in case of a failed user lookup. |
||
733 | */ |
||
734 | public function connect_user( $user_id = null, $redirect_url = null ) { |
||
754 | |||
755 | /** |
||
756 | * Unlinks the current user from the linked WordPress.com user. |
||
757 | * |
||
758 | * @access public |
||
759 | * @static |
||
760 | * |
||
761 | * @todo Refactor to properly load the XMLRPC client independently. |
||
762 | * |
||
763 | * @param Integer $user_id the user identifier. |
||
764 | * @param bool $can_overwrite_primary_user Allow for the primary user to be disconnected. |
||
765 | * @return Boolean Whether the disconnection of the user was successful. |
||
766 | */ |
||
767 | public function disconnect_user( $user_id = null, $can_overwrite_primary_user = false ) { |
||
791 | |||
792 | /** |
||
793 | * Returns the requested Jetpack API URL. |
||
794 | * |
||
795 | * @param String $relative_url the relative API path. |
||
796 | * @return String API URL. |
||
797 | */ |
||
798 | public function api_url( $relative_url ) { |
||
835 | |||
836 | /** |
||
837 | * Returns the Jetpack XMLRPC WordPress.com API endpoint URL. |
||
838 | * |
||
839 | * @return String XMLRPC API URL. |
||
840 | */ |
||
841 | public function xmlrpc_api_url() { |
||
849 | |||
850 | /** |
||
851 | * Attempts Jetpack registration which sets up the site for connection. Should |
||
852 | * remain public because the call to action comes from the current site, not from |
||
853 | * WordPress.com. |
||
854 | * |
||
855 | * @param String $api_endpoint (optional) an API endpoint to use, defaults to 'register'. |
||
856 | * @return true|WP_Error The error object. |
||
857 | */ |
||
858 | public function register( $api_endpoint = 'register' ) { |
||
1004 | |||
1005 | /** |
||
1006 | * Attempts Jetpack registration. |
||
1007 | * |
||
1008 | * @param bool $tos_agree Whether the user agreed to TOS. |
||
1009 | * |
||
1010 | * @return bool|WP_Error |
||
1011 | */ |
||
1012 | public function try_registration( $tos_agree = true ) { |
||
1051 | |||
1052 | /** |
||
1053 | * Adds a parameter to the register request body |
||
1054 | * |
||
1055 | * @since 9.7.0 |
||
1056 | * |
||
1057 | * @param string $name The name of the parameter to be added. |
||
1058 | * @param string $value The value of the parameter to be added. |
||
1059 | * |
||
1060 | * @throws \InvalidArgumentException If supplied arguments are not strings. |
||
1061 | * @return void |
||
1062 | */ |
||
1063 | public function add_register_request_param( $name, $value ) { |
||
1069 | |||
1070 | /** |
||
1071 | * Takes the response from the Jetpack register new site endpoint and |
||
1072 | * verifies it worked properly. |
||
1073 | * |
||
1074 | * @since 2.6 |
||
1075 | * |
||
1076 | * @param Mixed $response the response object, or the error object. |
||
1077 | * @return string|WP_Error A JSON object on success or WP_Error on failures |
||
1078 | **/ |
||
1079 | protected function validate_remote_register_response( $response ) { |
||
1148 | |||
1149 | /** |
||
1150 | * Adds a used nonce to a list of known nonces. |
||
1151 | * |
||
1152 | * @param int $timestamp the current request timestamp. |
||
1153 | * @param string $nonce the nonce value. |
||
1154 | * @return bool whether the nonce is unique or not. |
||
1155 | * |
||
1156 | * @deprecated since 9.5.0 |
||
1157 | * @see Nonce_Handler::add() |
||
1158 | */ |
||
1159 | public function add_nonce( $timestamp, $nonce ) { |
||
1163 | |||
1164 | /** |
||
1165 | * Cleans nonces that were saved when calling ::add_nonce. |
||
1166 | * |
||
1167 | * @todo Properly prepare the query before executing it. |
||
1168 | * |
||
1169 | * @param bool $all whether to clean even non-expired nonces. |
||
1170 | * |
||
1171 | * @deprecated since 9.5.0 |
||
1172 | * @see Nonce_Handler::clean_all() |
||
1173 | */ |
||
1174 | public function clean_nonces( $all = false ) { |
||
1178 | |||
1179 | /** |
||
1180 | * Sets the Connection custom capabilities. |
||
1181 | * |
||
1182 | * @param string[] $caps Array of the user's capabilities. |
||
1183 | * @param string $cap Capability name. |
||
1184 | * @param int $user_id The user ID. |
||
1185 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1186 | */ |
||
1187 | public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1220 | |||
1221 | /** |
||
1222 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
1223 | * |
||
1224 | * Based on local php max_execution_time in php.ini |
||
1225 | * |
||
1226 | * @since 5.4 |
||
1227 | * @return int |
||
1228 | **/ |
||
1229 | public function get_max_execution_time() { |
||
1238 | |||
1239 | /** |
||
1240 | * Sets a minimum request timeout, and returns the current timeout |
||
1241 | * |
||
1242 | * @since 5.4 |
||
1243 | * @param Integer $min_timeout the minimum timeout value. |
||
1244 | **/ |
||
1245 | View Code Duplication | public function set_min_time_limit( $min_timeout ) { |
|
1253 | |||
1254 | /** |
||
1255 | * Get our assumed site creation date. |
||
1256 | * Calculated based on the earlier date of either: |
||
1257 | * - Earliest admin user registration date. |
||
1258 | * - Earliest date of post of any post type. |
||
1259 | * |
||
1260 | * @since 7.2.0 |
||
1261 | * |
||
1262 | * @return string Assumed site creation date and time. |
||
1263 | */ |
||
1264 | public function get_assumed_site_creation_date() { |
||
1303 | |||
1304 | /** |
||
1305 | * Adds the activation source string as a parameter to passed arguments. |
||
1306 | * |
||
1307 | * @todo Refactor to use rawurlencode() instead of urlencode(). |
||
1308 | * |
||
1309 | * @param array $args arguments that need to have the source added. |
||
1310 | * @return array $amended arguments. |
||
1311 | */ |
||
1312 | View Code Duplication | public static function apply_activation_source_to_args( $args ) { |
|
1327 | |||
1328 | /** |
||
1329 | * Generates two secret tokens and the end of life timestamp for them. |
||
1330 | * |
||
1331 | * @param String $action The action name. |
||
1332 | * @param Integer $user_id The user identifier. |
||
1333 | * @param Integer $exp Expiration time in seconds. |
||
1334 | */ |
||
1335 | public function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
1338 | |||
1339 | /** |
||
1340 | * Returns two secret tokens and the end of life timestamp for them. |
||
1341 | * |
||
1342 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->get() instead. |
||
1343 | * |
||
1344 | * @param String $action The action name. |
||
1345 | * @param Integer $user_id The user identifier. |
||
1346 | * @return string|array an array of secrets or an error string. |
||
1347 | */ |
||
1348 | public function get_secrets( $action, $user_id ) { |
||
1352 | |||
1353 | /** |
||
1354 | * Deletes secret tokens in case they, for example, have expired. |
||
1355 | * |
||
1356 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->delete() instead. |
||
1357 | * |
||
1358 | * @param String $action The action name. |
||
1359 | * @param Integer $user_id The user identifier. |
||
1360 | */ |
||
1361 | public function delete_secrets( $action, $user_id ) { |
||
1365 | |||
1366 | /** |
||
1367 | * Deletes all connection tokens and transients from the local Jetpack site. |
||
1368 | * If the plugin object has been provided in the constructor, the function first checks |
||
1369 | * whether it's the only active connection. |
||
1370 | * If there are any other connections, the function will do nothing and return `false` |
||
1371 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1372 | * |
||
1373 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1374 | * |
||
1375 | * @return bool True if disconnected successfully, false otherwise. |
||
1376 | */ |
||
1377 | public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { |
||
1413 | |||
1414 | /** |
||
1415 | * Tells WordPress.com to disconnect the site and clear all tokens from cached site. |
||
1416 | * If the plugin object has been provided in the constructor, the function first check |
||
1417 | * whether it's the only active connection. |
||
1418 | * If there are any other connections, the function will do nothing and return `false` |
||
1419 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1420 | * |
||
1421 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1422 | * |
||
1423 | * @return bool True if disconnected successfully, false otherwise. |
||
1424 | */ |
||
1425 | public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { |
||
1445 | |||
1446 | /** |
||
1447 | * Disconnect the plugin and remove the tokens. |
||
1448 | * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. |
||
1449 | * This is a proxy method to simplify the Connection package API. |
||
1450 | * |
||
1451 | * @see Manager::disable_plugin() |
||
1452 | * @see Manager::disconnect_site_wpcom() |
||
1453 | * @see Manager::delete_all_connection_tokens() |
||
1454 | * |
||
1455 | * @return bool |
||
1456 | */ |
||
1457 | public function remove_connection() { |
||
1464 | |||
1465 | /** |
||
1466 | * Completely clearing up the connection, and initiating reconnect. |
||
1467 | * |
||
1468 | * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. |
||
1469 | */ |
||
1470 | public function reconnect() { |
||
1478 | |||
1479 | /** |
||
1480 | * Validate the tokens, and refresh the invalid ones. |
||
1481 | * |
||
1482 | * @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. |
||
1483 | */ |
||
1484 | public function restore() { |
||
1520 | |||
1521 | /** |
||
1522 | * Responds to a WordPress.com call to register the current site. |
||
1523 | * Should be changed to protected. |
||
1524 | * |
||
1525 | * @param array $registration_data Array of [ secret_1, user_id ]. |
||
1526 | */ |
||
1527 | public function handle_registration( array $registration_data ) { |
||
1535 | |||
1536 | /** |
||
1537 | * Perform the API request to validate the blog and user tokens. |
||
1538 | * |
||
1539 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->validate_tokens() instead. |
||
1540 | * |
||
1541 | * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. |
||
1542 | * |
||
1543 | * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. |
||
1544 | */ |
||
1545 | public function validate_tokens( $user_id = null ) { |
||
1549 | |||
1550 | /** |
||
1551 | * Verify a Previously Generated Secret. |
||
1552 | * |
||
1553 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->verify() instead. |
||
1554 | * |
||
1555 | * @param string $action The type of secret to verify. |
||
1556 | * @param string $secret_1 The secret string to compare to what is stored. |
||
1557 | * @param int $user_id The user ID of the owner of the secret. |
||
1558 | * @return \WP_Error|string WP_Error on failure, secret_2 on success. |
||
1559 | */ |
||
1560 | public function verify_secrets( $action, $secret_1, $user_id ) { |
||
1564 | |||
1565 | /** |
||
1566 | * Responds to a WordPress.com call to authorize the current user. |
||
1567 | * Should be changed to protected. |
||
1568 | */ |
||
1569 | public function handle_authorization() { |
||
1572 | |||
1573 | /** |
||
1574 | * Obtains the auth token. |
||
1575 | * |
||
1576 | * @param array $data The request data. |
||
1577 | * @return object|\WP_Error Returns the auth token on success. |
||
1578 | * Returns a \WP_Error on failure. |
||
1579 | */ |
||
1580 | public function get_token( $data ) { |
||
1583 | |||
1584 | /** |
||
1585 | * Builds a URL to the Jetpack connection auth page. |
||
1586 | * |
||
1587 | * @param WP_User $user (optional) defaults to the current logged in user. |
||
1588 | * @param String $redirect (optional) a redirect URL to use instead of the default. |
||
1589 | * @return string Connect URL. |
||
1590 | */ |
||
1591 | public function get_authorization_url( $user = null, $redirect = null ) { |
||
1678 | |||
1679 | /** |
||
1680 | * Authorizes the user by obtaining and storing the user token. |
||
1681 | * |
||
1682 | * @param array $data The request data. |
||
1683 | * @return string|\WP_Error Returns a string on success. |
||
1684 | * Returns a \WP_Error on failure. |
||
1685 | */ |
||
1686 | public function authorize( $data = array() ) { |
||
1777 | |||
1778 | /** |
||
1779 | * Disconnects from the Jetpack servers. |
||
1780 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
1781 | */ |
||
1782 | public function disconnect_site() { |
||
1785 | |||
1786 | /** |
||
1787 | * The Base64 Encoding of the SHA1 Hash of the Input. |
||
1788 | * |
||
1789 | * @param string $text The string to hash. |
||
1790 | * @return string |
||
1791 | */ |
||
1792 | public function sha1_base64( $text ) { |
||
1795 | |||
1796 | /** |
||
1797 | * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. |
||
1798 | * |
||
1799 | * @param string $domain The domain to check. |
||
1800 | * |
||
1801 | * @return bool|WP_Error |
||
1802 | */ |
||
1803 | public function is_usable_domain( $domain ) { |
||
1890 | |||
1891 | /** |
||
1892 | * Gets the requested token. |
||
1893 | * |
||
1894 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead. |
||
1895 | * |
||
1896 | * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. |
||
1897 | * @param string|false $token_key If provided, check that the token matches the provided input. |
||
1898 | * @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. |
||
1899 | * |
||
1900 | * @return object|false |
||
1901 | * |
||
1902 | * @see $this->get_tokens()->get_access_token() |
||
1903 | */ |
||
1904 | public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { |
||
1908 | |||
1909 | /** |
||
1910 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths |
||
1911 | * since it is passed by reference to various methods. |
||
1912 | * Capture it here so we can verify the signature later. |
||
1913 | * |
||
1914 | * @param array $methods an array of available XMLRPC methods. |
||
1915 | * @return array the same array, since this method doesn't add or remove anything. |
||
1916 | */ |
||
1917 | public function xmlrpc_methods( $methods ) { |
||
1921 | |||
1922 | /** |
||
1923 | * Resets the raw post data parameter for testing purposes. |
||
1924 | */ |
||
1925 | public function reset_raw_post_data() { |
||
1928 | |||
1929 | /** |
||
1930 | * Registering an additional method. |
||
1931 | * |
||
1932 | * @param array $methods an array of available XMLRPC methods. |
||
1933 | * @return array the amended array in case the method is added. |
||
1934 | */ |
||
1935 | public function public_xmlrpc_methods( $methods ) { |
||
1941 | |||
1942 | /** |
||
1943 | * Handles a getOptions XMLRPC method call. |
||
1944 | * |
||
1945 | * @param array $args method call arguments. |
||
1946 | * @return an amended XMLRPC server options array. |
||
1947 | */ |
||
1948 | public function jetpack_get_options( $args ) { |
||
1989 | |||
1990 | /** |
||
1991 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
1992 | * |
||
1993 | * @param array $options standard Core options. |
||
1994 | * @return array amended options. |
||
1995 | */ |
||
1996 | public function xmlrpc_options( $options ) { |
||
2014 | |||
2015 | /** |
||
2016 | * Resets the saved authentication state in between testing requests. |
||
2017 | */ |
||
2018 | public function reset_saved_auth_state() { |
||
2021 | |||
2022 | /** |
||
2023 | * Sign a user role with the master access token. |
||
2024 | * If not specified, will default to the current user. |
||
2025 | * |
||
2026 | * @access public |
||
2027 | * |
||
2028 | * @param string $role User role. |
||
2029 | * @param int $user_id ID of the user. |
||
2030 | * @return string Signed user role. |
||
2031 | */ |
||
2032 | public function sign_role( $role, $user_id = null ) { |
||
2035 | |||
2036 | /** |
||
2037 | * Set the plugin instance. |
||
2038 | * |
||
2039 | * @param Plugin $plugin_instance The plugin instance. |
||
2040 | * |
||
2041 | * @return $this |
||
2042 | */ |
||
2043 | public function set_plugin_instance( Plugin $plugin_instance ) { |
||
2048 | |||
2049 | /** |
||
2050 | * Retrieve the plugin management object. |
||
2051 | * |
||
2052 | * @return Plugin|null |
||
2053 | */ |
||
2054 | public function get_plugin() { |
||
2057 | |||
2058 | /** |
||
2059 | * Get all connected plugins information, excluding those disconnected by user. |
||
2060 | * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded |
||
2061 | * Even if you don't use Jetpack Config, it may be introduced later by other plugins, |
||
2062 | * so please make sure not to run the method too early in the code. |
||
2063 | * |
||
2064 | * @return array|WP_Error |
||
2065 | */ |
||
2066 | public function get_connected_plugins() { |
||
2075 | |||
2076 | /** |
||
2077 | * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. |
||
2078 | * Note: this method does not remove any access tokens. |
||
2079 | * |
||
2080 | * @return bool |
||
2081 | */ |
||
2082 | public function disable_plugin() { |
||
2089 | |||
2090 | /** |
||
2091 | * Force plugin reconnect after user-initiated disconnect. |
||
2092 | * After its called, the plugin will be allowed to use the connection again. |
||
2093 | * Note: this method does not initialize access tokens. |
||
2094 | * |
||
2095 | * @return bool |
||
2096 | */ |
||
2097 | public function enable_plugin() { |
||
2104 | |||
2105 | /** |
||
2106 | * Whether the plugin is allowed to use the connection, or it's been disconnected by user. |
||
2107 | * If no plugin slug was passed into the constructor, always returns true. |
||
2108 | * |
||
2109 | * @return bool |
||
2110 | */ |
||
2111 | public function is_plugin_enabled() { |
||
2118 | |||
2119 | /** |
||
2120 | * Perform the API request to refresh the blog token. |
||
2121 | * Note that we are making this request on behalf of the Jetpack master user, |
||
2122 | * given they were (most probably) the ones that registered the site at the first place. |
||
2123 | * |
||
2124 | * @return WP_Error|bool The result of updating the blog_token option. |
||
2125 | */ |
||
2126 | public function refresh_blog_token() { |
||
2176 | |||
2177 | /** |
||
2178 | * Disconnect the user from WP.com, and initiate the reconnect process. |
||
2179 | * |
||
2180 | * @return bool |
||
2181 | */ |
||
2182 | public function refresh_user_token() { |
||
2187 | |||
2188 | /** |
||
2189 | * Fetches a signed token. |
||
2190 | * |
||
2191 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead. |
||
2192 | * |
||
2193 | * @param object $token the token. |
||
2194 | * @return WP_Error|string a signed token |
||
2195 | */ |
||
2196 | public function get_signed_token( $token ) { |
||
2200 | |||
2201 | /** |
||
2202 | * If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) |
||
2203 | * |
||
2204 | * @param array $stats The Heartbeat stats array. |
||
2205 | * @return array $stats |
||
2206 | */ |
||
2207 | public function add_stats_to_heartbeat( $stats ) { |
||
2222 | } |
||
2223 |
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.