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 | * @deprecated 9.8.0 |
||
602 | * |
||
603 | * @return bool |
||
604 | */ |
||
605 | public function is_userless() { |
||
609 | |||
610 | /** |
||
611 | * Returns true if the site is connected only at a site level. |
||
612 | * |
||
613 | * 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. |
||
614 | * |
||
615 | * @access public |
||
616 | * @since 9.8.0 |
||
617 | * |
||
618 | * @return bool |
||
619 | */ |
||
620 | public function is_site_connection() { |
||
623 | |||
624 | /** |
||
625 | * Checks to see if the connection owner of the site is missing. |
||
626 | * |
||
627 | * @return bool |
||
628 | */ |
||
629 | public function is_missing_connection_owner() { |
||
637 | |||
638 | /** |
||
639 | * Returns true if the user with the specified identifier is connected to |
||
640 | * WordPress.com. |
||
641 | * |
||
642 | * @param int $user_id the user identifier. Default is the current user. |
||
643 | * @return bool Boolean is the user connected? |
||
644 | */ |
||
645 | public function is_user_connected( $user_id = false ) { |
||
653 | |||
654 | /** |
||
655 | * Returns the local user ID of the connection owner. |
||
656 | * |
||
657 | * @return bool|int Returns the ID of the connection owner or False if no connection owner found. |
||
658 | */ |
||
659 | public function get_connection_owner_id() { |
||
663 | |||
664 | /** |
||
665 | * Get the wpcom user data of the current|specified connected user. |
||
666 | * |
||
667 | * @todo Refactor to properly load the XMLRPC client independently. |
||
668 | * |
||
669 | * @param Integer $user_id the user identifier. |
||
670 | * @return Object the user object. |
||
671 | */ |
||
672 | public function get_connected_user_data( $user_id = null ) { |
||
698 | |||
699 | /** |
||
700 | * Returns a user object of the connection owner. |
||
701 | * |
||
702 | * @return WP_User|false False if no connection owner found. |
||
703 | */ |
||
704 | public function get_connection_owner() { |
||
723 | |||
724 | /** |
||
725 | * Returns true if the provided user is the Jetpack connection owner. |
||
726 | * If user ID is not specified, the current user will be used. |
||
727 | * |
||
728 | * @param Integer|Boolean $user_id the user identifier. False for current user. |
||
729 | * @return Boolean True the user the connection owner, false otherwise. |
||
730 | */ |
||
731 | public function is_connection_owner( $user_id = false ) { |
||
738 | |||
739 | /** |
||
740 | * Connects the user with a specified ID to a WordPress.com user using the |
||
741 | * remote login flow. |
||
742 | * |
||
743 | * @access public |
||
744 | * |
||
745 | * @param Integer $user_id (optional) the user identifier, defaults to current user. |
||
746 | * @param String $redirect_url the URL to redirect the user to for processing, defaults to |
||
747 | * admin_url(). |
||
748 | * @return WP_Error only in case of a failed user lookup. |
||
749 | */ |
||
750 | public function connect_user( $user_id = null, $redirect_url = null ) { |
||
770 | |||
771 | /** |
||
772 | * Unlinks the current user from the linked WordPress.com user. |
||
773 | * |
||
774 | * @access public |
||
775 | * @static |
||
776 | * |
||
777 | * @todo Refactor to properly load the XMLRPC client independently. |
||
778 | * |
||
779 | * @param Integer $user_id the user identifier. |
||
780 | * @param bool $can_overwrite_primary_user Allow for the primary user to be disconnected. |
||
781 | * @return Boolean Whether the disconnection of the user was successful. |
||
782 | */ |
||
783 | public function disconnect_user( $user_id = null, $can_overwrite_primary_user = false ) { |
||
807 | |||
808 | /** |
||
809 | * Returns the requested Jetpack API URL. |
||
810 | * |
||
811 | * @param String $relative_url the relative API path. |
||
812 | * @return String API URL. |
||
813 | */ |
||
814 | public function api_url( $relative_url ) { |
||
851 | |||
852 | /** |
||
853 | * Returns the Jetpack XMLRPC WordPress.com API endpoint URL. |
||
854 | * |
||
855 | * @return String XMLRPC API URL. |
||
856 | */ |
||
857 | public function xmlrpc_api_url() { |
||
865 | |||
866 | /** |
||
867 | * Attempts Jetpack registration which sets up the site for connection. Should |
||
868 | * remain public because the call to action comes from the current site, not from |
||
869 | * WordPress.com. |
||
870 | * |
||
871 | * @param String $api_endpoint (optional) an API endpoint to use, defaults to 'register'. |
||
872 | * @return true|WP_Error The error object. |
||
873 | */ |
||
874 | public function register( $api_endpoint = 'register' ) { |
||
1020 | |||
1021 | /** |
||
1022 | * Attempts Jetpack registration. |
||
1023 | * |
||
1024 | * @param bool $tos_agree Whether the user agreed to TOS. |
||
1025 | * |
||
1026 | * @return bool|WP_Error |
||
1027 | */ |
||
1028 | public function try_registration( $tos_agree = true ) { |
||
1067 | |||
1068 | /** |
||
1069 | * Adds a parameter to the register request body |
||
1070 | * |
||
1071 | * @since 9.7.0 |
||
1072 | * |
||
1073 | * @param string $name The name of the parameter to be added. |
||
1074 | * @param string $value The value of the parameter to be added. |
||
1075 | * |
||
1076 | * @throws \InvalidArgumentException If supplied arguments are not strings. |
||
1077 | * @return void |
||
1078 | */ |
||
1079 | public function add_register_request_param( $name, $value ) { |
||
1085 | |||
1086 | /** |
||
1087 | * Takes the response from the Jetpack register new site endpoint and |
||
1088 | * verifies it worked properly. |
||
1089 | * |
||
1090 | * @since 2.6 |
||
1091 | * |
||
1092 | * @param Mixed $response the response object, or the error object. |
||
1093 | * @return string|WP_Error A JSON object on success or WP_Error on failures |
||
1094 | **/ |
||
1095 | protected function validate_remote_register_response( $response ) { |
||
1164 | |||
1165 | /** |
||
1166 | * Adds a used nonce to a list of known nonces. |
||
1167 | * |
||
1168 | * @param int $timestamp the current request timestamp. |
||
1169 | * @param string $nonce the nonce value. |
||
1170 | * @return bool whether the nonce is unique or not. |
||
1171 | * |
||
1172 | * @deprecated since 9.5.0 |
||
1173 | * @see Nonce_Handler::add() |
||
1174 | */ |
||
1175 | public function add_nonce( $timestamp, $nonce ) { |
||
1179 | |||
1180 | /** |
||
1181 | * Cleans nonces that were saved when calling ::add_nonce. |
||
1182 | * |
||
1183 | * @todo Properly prepare the query before executing it. |
||
1184 | * |
||
1185 | * @param bool $all whether to clean even non-expired nonces. |
||
1186 | * |
||
1187 | * @deprecated since 9.5.0 |
||
1188 | * @see Nonce_Handler::clean_all() |
||
1189 | */ |
||
1190 | public function clean_nonces( $all = false ) { |
||
1194 | |||
1195 | /** |
||
1196 | * Sets the Connection custom capabilities. |
||
1197 | * |
||
1198 | * @param string[] $caps Array of the user's capabilities. |
||
1199 | * @param string $cap Capability name. |
||
1200 | * @param int $user_id The user ID. |
||
1201 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1202 | */ |
||
1203 | public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1236 | |||
1237 | /** |
||
1238 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
1239 | * |
||
1240 | * Based on local php max_execution_time in php.ini |
||
1241 | * |
||
1242 | * @since 5.4 |
||
1243 | * @return int |
||
1244 | **/ |
||
1245 | public function get_max_execution_time() { |
||
1254 | |||
1255 | /** |
||
1256 | * Sets a minimum request timeout, and returns the current timeout |
||
1257 | * |
||
1258 | * @since 5.4 |
||
1259 | * @param Integer $min_timeout the minimum timeout value. |
||
1260 | **/ |
||
1261 | View Code Duplication | public function set_min_time_limit( $min_timeout ) { |
|
1269 | |||
1270 | /** |
||
1271 | * Get our assumed site creation date. |
||
1272 | * Calculated based on the earlier date of either: |
||
1273 | * - Earliest admin user registration date. |
||
1274 | * - Earliest date of post of any post type. |
||
1275 | * |
||
1276 | * @since 7.2.0 |
||
1277 | * |
||
1278 | * @return string Assumed site creation date and time. |
||
1279 | */ |
||
1280 | public function get_assumed_site_creation_date() { |
||
1319 | |||
1320 | /** |
||
1321 | * Adds the activation source string as a parameter to passed arguments. |
||
1322 | * |
||
1323 | * @todo Refactor to use rawurlencode() instead of urlencode(). |
||
1324 | * |
||
1325 | * @param array $args arguments that need to have the source added. |
||
1326 | * @return array $amended arguments. |
||
1327 | */ |
||
1328 | View Code Duplication | public static function apply_activation_source_to_args( $args ) { |
|
1343 | |||
1344 | /** |
||
1345 | * Generates two secret tokens and the end of life timestamp for them. |
||
1346 | * |
||
1347 | * @param String $action The action name. |
||
1348 | * @param Integer $user_id The user identifier. |
||
1349 | * @param Integer $exp Expiration time in seconds. |
||
1350 | */ |
||
1351 | public function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
1354 | |||
1355 | /** |
||
1356 | * Returns two secret tokens and the end of life timestamp for them. |
||
1357 | * |
||
1358 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->get() instead. |
||
1359 | * |
||
1360 | * @param String $action The action name. |
||
1361 | * @param Integer $user_id The user identifier. |
||
1362 | * @return string|array an array of secrets or an error string. |
||
1363 | */ |
||
1364 | public function get_secrets( $action, $user_id ) { |
||
1368 | |||
1369 | /** |
||
1370 | * Deletes secret tokens in case they, for example, have expired. |
||
1371 | * |
||
1372 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->delete() instead. |
||
1373 | * |
||
1374 | * @param String $action The action name. |
||
1375 | * @param Integer $user_id The user identifier. |
||
1376 | */ |
||
1377 | public function delete_secrets( $action, $user_id ) { |
||
1381 | |||
1382 | /** |
||
1383 | * Deletes all connection tokens and transients from the local Jetpack site. |
||
1384 | * If the plugin object has been provided in the constructor, the function first checks |
||
1385 | * whether it's the only active connection. |
||
1386 | * If there are any other connections, the function will do nothing and return `false` |
||
1387 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1388 | * |
||
1389 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1390 | * |
||
1391 | * @return bool True if disconnected successfully, false otherwise. |
||
1392 | */ |
||
1393 | public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { |
||
1429 | |||
1430 | /** |
||
1431 | * Tells WordPress.com to disconnect the site and clear all tokens from cached site. |
||
1432 | * If the plugin object has been provided in the constructor, the function first check |
||
1433 | * whether it's the only active connection. |
||
1434 | * If there are any other connections, the function will do nothing and return `false` |
||
1435 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1436 | * |
||
1437 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1438 | * |
||
1439 | * @return bool True if disconnected successfully, false otherwise. |
||
1440 | */ |
||
1441 | public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { |
||
1461 | |||
1462 | /** |
||
1463 | * Disconnect the plugin and remove the tokens. |
||
1464 | * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. |
||
1465 | * This is a proxy method to simplify the Connection package API. |
||
1466 | * |
||
1467 | * @see Manager::disable_plugin() |
||
1468 | * @see Manager::disconnect_site_wpcom() |
||
1469 | * @see Manager::delete_all_connection_tokens() |
||
1470 | * |
||
1471 | * @return bool |
||
1472 | */ |
||
1473 | public function remove_connection() { |
||
1480 | |||
1481 | /** |
||
1482 | * Completely clearing up the connection, and initiating reconnect. |
||
1483 | * |
||
1484 | * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. |
||
1485 | */ |
||
1486 | public function reconnect() { |
||
1494 | |||
1495 | /** |
||
1496 | * Validate the tokens, and refresh the invalid ones. |
||
1497 | * |
||
1498 | * @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. |
||
1499 | */ |
||
1500 | public function restore() { |
||
1536 | |||
1537 | /** |
||
1538 | * Responds to a WordPress.com call to register the current site. |
||
1539 | * Should be changed to protected. |
||
1540 | * |
||
1541 | * @param array $registration_data Array of [ secret_1, user_id ]. |
||
1542 | */ |
||
1543 | public function handle_registration( array $registration_data ) { |
||
1551 | |||
1552 | /** |
||
1553 | * Perform the API request to validate the blog and user tokens. |
||
1554 | * |
||
1555 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->validate_tokens() instead. |
||
1556 | * |
||
1557 | * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. |
||
1558 | * |
||
1559 | * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. |
||
1560 | */ |
||
1561 | public function validate_tokens( $user_id = null ) { |
||
1565 | |||
1566 | /** |
||
1567 | * Verify a Previously Generated Secret. |
||
1568 | * |
||
1569 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->verify() instead. |
||
1570 | * |
||
1571 | * @param string $action The type of secret to verify. |
||
1572 | * @param string $secret_1 The secret string to compare to what is stored. |
||
1573 | * @param int $user_id The user ID of the owner of the secret. |
||
1574 | * @return \WP_Error|string WP_Error on failure, secret_2 on success. |
||
1575 | */ |
||
1576 | public function verify_secrets( $action, $secret_1, $user_id ) { |
||
1580 | |||
1581 | /** |
||
1582 | * Responds to a WordPress.com call to authorize the current user. |
||
1583 | * Should be changed to protected. |
||
1584 | */ |
||
1585 | public function handle_authorization() { |
||
1588 | |||
1589 | /** |
||
1590 | * Obtains the auth token. |
||
1591 | * |
||
1592 | * @param array $data The request data. |
||
1593 | * @return object|\WP_Error Returns the auth token on success. |
||
1594 | * Returns a \WP_Error on failure. |
||
1595 | */ |
||
1596 | public function get_token( $data ) { |
||
1599 | |||
1600 | /** |
||
1601 | * Builds a URL to the Jetpack connection auth page. |
||
1602 | * |
||
1603 | * @param WP_User $user (optional) defaults to the current logged in user. |
||
1604 | * @param String $redirect (optional) a redirect URL to use instead of the default. |
||
1605 | * @return string Connect URL. |
||
1606 | */ |
||
1607 | public function get_authorization_url( $user = null, $redirect = null ) { |
||
1694 | |||
1695 | /** |
||
1696 | * Authorizes the user by obtaining and storing the user token. |
||
1697 | * |
||
1698 | * @param array $data The request data. |
||
1699 | * @return string|\WP_Error Returns a string on success. |
||
1700 | * Returns a \WP_Error on failure. |
||
1701 | */ |
||
1702 | public function authorize( $data = array() ) { |
||
1793 | |||
1794 | /** |
||
1795 | * Disconnects from the Jetpack servers. |
||
1796 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
1797 | */ |
||
1798 | public function disconnect_site() { |
||
1801 | |||
1802 | /** |
||
1803 | * The Base64 Encoding of the SHA1 Hash of the Input. |
||
1804 | * |
||
1805 | * @param string $text The string to hash. |
||
1806 | * @return string |
||
1807 | */ |
||
1808 | public function sha1_base64( $text ) { |
||
1811 | |||
1812 | /** |
||
1813 | * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. |
||
1814 | * |
||
1815 | * @param string $domain The domain to check. |
||
1816 | * |
||
1817 | * @return bool|WP_Error |
||
1818 | */ |
||
1819 | public function is_usable_domain( $domain ) { |
||
1906 | |||
1907 | /** |
||
1908 | * Gets the requested token. |
||
1909 | * |
||
1910 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead. |
||
1911 | * |
||
1912 | * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. |
||
1913 | * @param string|false $token_key If provided, check that the token matches the provided input. |
||
1914 | * @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. |
||
1915 | * |
||
1916 | * @return object|false |
||
1917 | * |
||
1918 | * @see $this->get_tokens()->get_access_token() |
||
1919 | */ |
||
1920 | public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { |
||
1924 | |||
1925 | /** |
||
1926 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths |
||
1927 | * since it is passed by reference to various methods. |
||
1928 | * Capture it here so we can verify the signature later. |
||
1929 | * |
||
1930 | * @param array $methods an array of available XMLRPC methods. |
||
1931 | * @return array the same array, since this method doesn't add or remove anything. |
||
1932 | */ |
||
1933 | public function xmlrpc_methods( $methods ) { |
||
1937 | |||
1938 | /** |
||
1939 | * Resets the raw post data parameter for testing purposes. |
||
1940 | */ |
||
1941 | public function reset_raw_post_data() { |
||
1944 | |||
1945 | /** |
||
1946 | * Registering an additional method. |
||
1947 | * |
||
1948 | * @param array $methods an array of available XMLRPC methods. |
||
1949 | * @return array the amended array in case the method is added. |
||
1950 | */ |
||
1951 | public function public_xmlrpc_methods( $methods ) { |
||
1957 | |||
1958 | /** |
||
1959 | * Handles a getOptions XMLRPC method call. |
||
1960 | * |
||
1961 | * @param array $args method call arguments. |
||
1962 | * @return an amended XMLRPC server options array. |
||
1963 | */ |
||
1964 | public function jetpack_get_options( $args ) { |
||
2005 | |||
2006 | /** |
||
2007 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
2008 | * |
||
2009 | * @param array $options standard Core options. |
||
2010 | * @return array amended options. |
||
2011 | */ |
||
2012 | public function xmlrpc_options( $options ) { |
||
2030 | |||
2031 | /** |
||
2032 | * Resets the saved authentication state in between testing requests. |
||
2033 | */ |
||
2034 | public function reset_saved_auth_state() { |
||
2037 | |||
2038 | /** |
||
2039 | * Sign a user role with the master access token. |
||
2040 | * If not specified, will default to the current user. |
||
2041 | * |
||
2042 | * @access public |
||
2043 | * |
||
2044 | * @param string $role User role. |
||
2045 | * @param int $user_id ID of the user. |
||
2046 | * @return string Signed user role. |
||
2047 | */ |
||
2048 | public function sign_role( $role, $user_id = null ) { |
||
2051 | |||
2052 | /** |
||
2053 | * Set the plugin instance. |
||
2054 | * |
||
2055 | * @param Plugin $plugin_instance The plugin instance. |
||
2056 | * |
||
2057 | * @return $this |
||
2058 | */ |
||
2059 | public function set_plugin_instance( Plugin $plugin_instance ) { |
||
2064 | |||
2065 | /** |
||
2066 | * Retrieve the plugin management object. |
||
2067 | * |
||
2068 | * @return Plugin|null |
||
2069 | */ |
||
2070 | public function get_plugin() { |
||
2073 | |||
2074 | /** |
||
2075 | * Get all connected plugins information, excluding those disconnected by user. |
||
2076 | * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded |
||
2077 | * Even if you don't use Jetpack Config, it may be introduced later by other plugins, |
||
2078 | * so please make sure not to run the method too early in the code. |
||
2079 | * |
||
2080 | * @return array|WP_Error |
||
2081 | */ |
||
2082 | public function get_connected_plugins() { |
||
2091 | |||
2092 | /** |
||
2093 | * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. |
||
2094 | * Note: this method does not remove any access tokens. |
||
2095 | * |
||
2096 | * @return bool |
||
2097 | */ |
||
2098 | public function disable_plugin() { |
||
2105 | |||
2106 | /** |
||
2107 | * Force plugin reconnect after user-initiated disconnect. |
||
2108 | * After its called, the plugin will be allowed to use the connection again. |
||
2109 | * Note: this method does not initialize access tokens. |
||
2110 | * |
||
2111 | * @return bool |
||
2112 | */ |
||
2113 | public function enable_plugin() { |
||
2120 | |||
2121 | /** |
||
2122 | * Whether the plugin is allowed to use the connection, or it's been disconnected by user. |
||
2123 | * If no plugin slug was passed into the constructor, always returns true. |
||
2124 | * |
||
2125 | * @return bool |
||
2126 | */ |
||
2127 | public function is_plugin_enabled() { |
||
2134 | |||
2135 | /** |
||
2136 | * Perform the API request to refresh the blog token. |
||
2137 | * Note that we are making this request on behalf of the Jetpack master user, |
||
2138 | * given they were (most probably) the ones that registered the site at the first place. |
||
2139 | * |
||
2140 | * @return WP_Error|bool The result of updating the blog_token option. |
||
2141 | */ |
||
2142 | public function refresh_blog_token() { |
||
2192 | |||
2193 | /** |
||
2194 | * Disconnect the user from WP.com, and initiate the reconnect process. |
||
2195 | * |
||
2196 | * @return bool |
||
2197 | */ |
||
2198 | public function refresh_user_token() { |
||
2203 | |||
2204 | /** |
||
2205 | * Fetches a signed token. |
||
2206 | * |
||
2207 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead. |
||
2208 | * |
||
2209 | * @param object $token the token. |
||
2210 | * @return WP_Error|string a signed token |
||
2211 | */ |
||
2212 | public function get_signed_token( $token ) { |
||
2216 | |||
2217 | /** |
||
2218 | * If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) |
||
2219 | * |
||
2220 | * @param array $stats The Heartbeat stats array. |
||
2221 | * @return array $stats |
||
2222 | */ |
||
2223 | public function add_stats_to_heartbeat( $stats ) { |
||
2238 | } |
||
2239 |
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.