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 ) { |
||
811 | |||
812 | /** |
||
813 | * Request to wpcom for a user to be unlinked from their WordPress.com account |
||
814 | * |
||
815 | * @access public |
||
816 | * |
||
817 | * @param Integer $user_id the user identifier. |
||
818 | * |
||
819 | * @return Boolean Whether the disconnection of the user was successful. |
||
820 | */ |
||
821 | public function unlink_user_from_wpcom( $user_id ) { |
||
832 | |||
833 | /** |
||
834 | * Returns the requested Jetpack API URL. |
||
835 | * |
||
836 | * @param String $relative_url the relative API path. |
||
837 | * @return String API URL. |
||
838 | */ |
||
839 | public function api_url( $relative_url ) { |
||
876 | |||
877 | /** |
||
878 | * Returns the Jetpack XMLRPC WordPress.com API endpoint URL. |
||
879 | * |
||
880 | * @return String XMLRPC API URL. |
||
881 | */ |
||
882 | public function xmlrpc_api_url() { |
||
890 | |||
891 | /** |
||
892 | * Attempts Jetpack registration which sets up the site for connection. Should |
||
893 | * remain public because the call to action comes from the current site, not from |
||
894 | * WordPress.com. |
||
895 | * |
||
896 | * @param String $api_endpoint (optional) an API endpoint to use, defaults to 'register'. |
||
897 | * @return true|WP_Error The error object. |
||
898 | */ |
||
899 | public function register( $api_endpoint = 'register' ) { |
||
1045 | |||
1046 | /** |
||
1047 | * Attempts Jetpack registration. |
||
1048 | * |
||
1049 | * @param bool $tos_agree Whether the user agreed to TOS. |
||
1050 | * |
||
1051 | * @return bool|WP_Error |
||
1052 | */ |
||
1053 | public function try_registration( $tos_agree = true ) { |
||
1092 | |||
1093 | /** |
||
1094 | * Adds a parameter to the register request body |
||
1095 | * |
||
1096 | * @since 9.7.0 |
||
1097 | * |
||
1098 | * @param string $name The name of the parameter to be added. |
||
1099 | * @param string $value The value of the parameter to be added. |
||
1100 | * |
||
1101 | * @throws \InvalidArgumentException If supplied arguments are not strings. |
||
1102 | * @return void |
||
1103 | */ |
||
1104 | public function add_register_request_param( $name, $value ) { |
||
1110 | |||
1111 | /** |
||
1112 | * Takes the response from the Jetpack register new site endpoint and |
||
1113 | * verifies it worked properly. |
||
1114 | * |
||
1115 | * @since 2.6 |
||
1116 | * |
||
1117 | * @param Mixed $response the response object, or the error object. |
||
1118 | * @return string|WP_Error A JSON object on success or WP_Error on failures |
||
1119 | **/ |
||
1120 | protected function validate_remote_register_response( $response ) { |
||
1189 | |||
1190 | /** |
||
1191 | * Adds a used nonce to a list of known nonces. |
||
1192 | * |
||
1193 | * @param int $timestamp the current request timestamp. |
||
1194 | * @param string $nonce the nonce value. |
||
1195 | * @return bool whether the nonce is unique or not. |
||
1196 | * |
||
1197 | * @deprecated since 9.5.0 |
||
1198 | * @see Nonce_Handler::add() |
||
1199 | */ |
||
1200 | public function add_nonce( $timestamp, $nonce ) { |
||
1204 | |||
1205 | /** |
||
1206 | * Cleans nonces that were saved when calling ::add_nonce. |
||
1207 | * |
||
1208 | * @todo Properly prepare the query before executing it. |
||
1209 | * |
||
1210 | * @param bool $all whether to clean even non-expired nonces. |
||
1211 | * |
||
1212 | * @deprecated since 9.5.0 |
||
1213 | * @see Nonce_Handler::clean_all() |
||
1214 | */ |
||
1215 | public function clean_nonces( $all = false ) { |
||
1219 | |||
1220 | /** |
||
1221 | * Sets the Connection custom capabilities. |
||
1222 | * |
||
1223 | * @param string[] $caps Array of the user's capabilities. |
||
1224 | * @param string $cap Capability name. |
||
1225 | * @param int $user_id The user ID. |
||
1226 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1227 | */ |
||
1228 | public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1261 | |||
1262 | /** |
||
1263 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
1264 | * |
||
1265 | * Based on local php max_execution_time in php.ini |
||
1266 | * |
||
1267 | * @since 5.4 |
||
1268 | * @return int |
||
1269 | **/ |
||
1270 | public function get_max_execution_time() { |
||
1279 | |||
1280 | /** |
||
1281 | * Sets a minimum request timeout, and returns the current timeout |
||
1282 | * |
||
1283 | * @since 5.4 |
||
1284 | * @param Integer $min_timeout the minimum timeout value. |
||
1285 | **/ |
||
1286 | View Code Duplication | public function set_min_time_limit( $min_timeout ) { |
|
1294 | |||
1295 | /** |
||
1296 | * Get our assumed site creation date. |
||
1297 | * Calculated based on the earlier date of either: |
||
1298 | * - Earliest admin user registration date. |
||
1299 | * - Earliest date of post of any post type. |
||
1300 | * |
||
1301 | * @since 7.2.0 |
||
1302 | * |
||
1303 | * @return string Assumed site creation date and time. |
||
1304 | */ |
||
1305 | public function get_assumed_site_creation_date() { |
||
1344 | |||
1345 | /** |
||
1346 | * Adds the activation source string as a parameter to passed arguments. |
||
1347 | * |
||
1348 | * @todo Refactor to use rawurlencode() instead of urlencode(). |
||
1349 | * |
||
1350 | * @param array $args arguments that need to have the source added. |
||
1351 | * @return array $amended arguments. |
||
1352 | */ |
||
1353 | View Code Duplication | public static function apply_activation_source_to_args( $args ) { |
|
1368 | |||
1369 | /** |
||
1370 | * Generates two secret tokens and the end of life timestamp for them. |
||
1371 | * |
||
1372 | * @param String $action The action name. |
||
1373 | * @param Integer $user_id The user identifier. |
||
1374 | * @param Integer $exp Expiration time in seconds. |
||
1375 | */ |
||
1376 | public function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
1379 | |||
1380 | /** |
||
1381 | * Returns two secret tokens and the end of life timestamp for them. |
||
1382 | * |
||
1383 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->get() instead. |
||
1384 | * |
||
1385 | * @param String $action The action name. |
||
1386 | * @param Integer $user_id The user identifier. |
||
1387 | * @return string|array an array of secrets or an error string. |
||
1388 | */ |
||
1389 | public function get_secrets( $action, $user_id ) { |
||
1393 | |||
1394 | /** |
||
1395 | * Deletes secret tokens in case they, for example, have expired. |
||
1396 | * |
||
1397 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->delete() instead. |
||
1398 | * |
||
1399 | * @param String $action The action name. |
||
1400 | * @param Integer $user_id The user identifier. |
||
1401 | */ |
||
1402 | public function delete_secrets( $action, $user_id ) { |
||
1406 | |||
1407 | /** |
||
1408 | * Deletes all connection tokens and transients from the local Jetpack site. |
||
1409 | * If the plugin object has been provided in the constructor, the function first checks |
||
1410 | * whether it's the only active connection. |
||
1411 | * If there are any other connections, the function will do nothing and return `false` |
||
1412 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1413 | * |
||
1414 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1415 | * |
||
1416 | * @return bool True if disconnected successfully, false otherwise. |
||
1417 | */ |
||
1418 | public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { |
||
1454 | |||
1455 | /** |
||
1456 | * Tells WordPress.com to disconnect the site and clear all tokens from cached site. |
||
1457 | * If the plugin object has been provided in the constructor, the function first check |
||
1458 | * whether it's the only active connection. |
||
1459 | * If there are any other connections, the function will do nothing and return `false` |
||
1460 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1461 | * |
||
1462 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1463 | * |
||
1464 | * @return bool True if disconnected successfully, false otherwise. |
||
1465 | */ |
||
1466 | public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { |
||
1486 | |||
1487 | /** |
||
1488 | * Disconnect the plugin and remove the tokens. |
||
1489 | * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. |
||
1490 | * This is a proxy method to simplify the Connection package API. |
||
1491 | * |
||
1492 | * @see Manager::disable_plugin() |
||
1493 | * @see Manager::disconnect_site_wpcom() |
||
1494 | * @see Manager::delete_all_connection_tokens() |
||
1495 | * |
||
1496 | * @return bool |
||
1497 | */ |
||
1498 | public function remove_connection() { |
||
1505 | |||
1506 | /** |
||
1507 | * Completely clearing up the connection, and initiating reconnect. |
||
1508 | * |
||
1509 | * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. |
||
1510 | */ |
||
1511 | public function reconnect() { |
||
1519 | |||
1520 | /** |
||
1521 | * Validate the tokens, and refresh the invalid ones. |
||
1522 | * |
||
1523 | * @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. |
||
1524 | */ |
||
1525 | public function restore() { |
||
1561 | |||
1562 | /** |
||
1563 | * Responds to a WordPress.com call to register the current site. |
||
1564 | * Should be changed to protected. |
||
1565 | * |
||
1566 | * @param array $registration_data Array of [ secret_1, user_id ]. |
||
1567 | */ |
||
1568 | public function handle_registration( array $registration_data ) { |
||
1576 | |||
1577 | /** |
||
1578 | * Perform the API request to validate the blog and user tokens. |
||
1579 | * |
||
1580 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->validate_tokens() instead. |
||
1581 | * |
||
1582 | * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. |
||
1583 | * |
||
1584 | * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. |
||
1585 | */ |
||
1586 | public function validate_tokens( $user_id = null ) { |
||
1590 | |||
1591 | /** |
||
1592 | * Verify a Previously Generated Secret. |
||
1593 | * |
||
1594 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->verify() instead. |
||
1595 | * |
||
1596 | * @param string $action The type of secret to verify. |
||
1597 | * @param string $secret_1 The secret string to compare to what is stored. |
||
1598 | * @param int $user_id The user ID of the owner of the secret. |
||
1599 | * @return \WP_Error|string WP_Error on failure, secret_2 on success. |
||
1600 | */ |
||
1601 | public function verify_secrets( $action, $secret_1, $user_id ) { |
||
1605 | |||
1606 | /** |
||
1607 | * Responds to a WordPress.com call to authorize the current user. |
||
1608 | * Should be changed to protected. |
||
1609 | */ |
||
1610 | public function handle_authorization() { |
||
1613 | |||
1614 | /** |
||
1615 | * Obtains the auth token. |
||
1616 | * |
||
1617 | * @param array $data The request data. |
||
1618 | * @return object|\WP_Error Returns the auth token on success. |
||
1619 | * Returns a \WP_Error on failure. |
||
1620 | */ |
||
1621 | public function get_token( $data ) { |
||
1624 | |||
1625 | /** |
||
1626 | * Builds a URL to the Jetpack connection auth page. |
||
1627 | * |
||
1628 | * @param WP_User $user (optional) defaults to the current logged in user. |
||
1629 | * @param String $redirect (optional) a redirect URL to use instead of the default. |
||
1630 | * @return string Connect URL. |
||
1631 | */ |
||
1632 | public function get_authorization_url( $user = null, $redirect = null ) { |
||
1719 | |||
1720 | /** |
||
1721 | * Authorizes the user by obtaining and storing the user token. |
||
1722 | * |
||
1723 | * @param array $data The request data. |
||
1724 | * @return string|\WP_Error Returns a string on success. |
||
1725 | * Returns a \WP_Error on failure. |
||
1726 | */ |
||
1727 | public function authorize( $data = array() ) { |
||
1818 | |||
1819 | /** |
||
1820 | * Disconnects from the Jetpack servers. |
||
1821 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
1822 | */ |
||
1823 | public function disconnect_site() { |
||
1826 | |||
1827 | /** |
||
1828 | * The Base64 Encoding of the SHA1 Hash of the Input. |
||
1829 | * |
||
1830 | * @param string $text The string to hash. |
||
1831 | * @return string |
||
1832 | */ |
||
1833 | public function sha1_base64( $text ) { |
||
1836 | |||
1837 | /** |
||
1838 | * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. |
||
1839 | * |
||
1840 | * @param string $domain The domain to check. |
||
1841 | * |
||
1842 | * @return bool|WP_Error |
||
1843 | */ |
||
1844 | public function is_usable_domain( $domain ) { |
||
1931 | |||
1932 | /** |
||
1933 | * Gets the requested token. |
||
1934 | * |
||
1935 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead. |
||
1936 | * |
||
1937 | * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. |
||
1938 | * @param string|false $token_key If provided, check that the token matches the provided input. |
||
1939 | * @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. |
||
1940 | * |
||
1941 | * @return object|false |
||
1942 | * |
||
1943 | * @see $this->get_tokens()->get_access_token() |
||
1944 | */ |
||
1945 | public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { |
||
1949 | |||
1950 | /** |
||
1951 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths |
||
1952 | * since it is passed by reference to various methods. |
||
1953 | * Capture it here so we can verify the signature later. |
||
1954 | * |
||
1955 | * @param array $methods an array of available XMLRPC methods. |
||
1956 | * @return array the same array, since this method doesn't add or remove anything. |
||
1957 | */ |
||
1958 | public function xmlrpc_methods( $methods ) { |
||
1962 | |||
1963 | /** |
||
1964 | * Resets the raw post data parameter for testing purposes. |
||
1965 | */ |
||
1966 | public function reset_raw_post_data() { |
||
1969 | |||
1970 | /** |
||
1971 | * Registering an additional method. |
||
1972 | * |
||
1973 | * @param array $methods an array of available XMLRPC methods. |
||
1974 | * @return array the amended array in case the method is added. |
||
1975 | */ |
||
1976 | public function public_xmlrpc_methods( $methods ) { |
||
1982 | |||
1983 | /** |
||
1984 | * Handles a getOptions XMLRPC method call. |
||
1985 | * |
||
1986 | * @param array $args method call arguments. |
||
1987 | * @return an amended XMLRPC server options array. |
||
1988 | */ |
||
1989 | public function jetpack_get_options( $args ) { |
||
2030 | |||
2031 | /** |
||
2032 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
2033 | * |
||
2034 | * @param array $options standard Core options. |
||
2035 | * @return array amended options. |
||
2036 | */ |
||
2037 | public function xmlrpc_options( $options ) { |
||
2055 | |||
2056 | /** |
||
2057 | * Resets the saved authentication state in between testing requests. |
||
2058 | */ |
||
2059 | public function reset_saved_auth_state() { |
||
2062 | |||
2063 | /** |
||
2064 | * Sign a user role with the master access token. |
||
2065 | * If not specified, will default to the current user. |
||
2066 | * |
||
2067 | * @access public |
||
2068 | * |
||
2069 | * @param string $role User role. |
||
2070 | * @param int $user_id ID of the user. |
||
2071 | * @return string Signed user role. |
||
2072 | */ |
||
2073 | public function sign_role( $role, $user_id = null ) { |
||
2076 | |||
2077 | /** |
||
2078 | * Set the plugin instance. |
||
2079 | * |
||
2080 | * @param Plugin $plugin_instance The plugin instance. |
||
2081 | * |
||
2082 | * @return $this |
||
2083 | */ |
||
2084 | public function set_plugin_instance( Plugin $plugin_instance ) { |
||
2089 | |||
2090 | /** |
||
2091 | * Retrieve the plugin management object. |
||
2092 | * |
||
2093 | * @return Plugin|null |
||
2094 | */ |
||
2095 | public function get_plugin() { |
||
2098 | |||
2099 | /** |
||
2100 | * Get all connected plugins information, excluding those disconnected by user. |
||
2101 | * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded |
||
2102 | * Even if you don't use Jetpack Config, it may be introduced later by other plugins, |
||
2103 | * so please make sure not to run the method too early in the code. |
||
2104 | * |
||
2105 | * @return array|WP_Error |
||
2106 | */ |
||
2107 | public function get_connected_plugins() { |
||
2116 | |||
2117 | /** |
||
2118 | * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. |
||
2119 | * Note: this method does not remove any access tokens. |
||
2120 | * |
||
2121 | * @return bool |
||
2122 | */ |
||
2123 | public function disable_plugin() { |
||
2130 | |||
2131 | /** |
||
2132 | * Force plugin reconnect after user-initiated disconnect. |
||
2133 | * After its called, the plugin will be allowed to use the connection again. |
||
2134 | * Note: this method does not initialize access tokens. |
||
2135 | * |
||
2136 | * @return bool |
||
2137 | */ |
||
2138 | public function enable_plugin() { |
||
2145 | |||
2146 | /** |
||
2147 | * Whether the plugin is allowed to use the connection, or it's been disconnected by user. |
||
2148 | * If no plugin slug was passed into the constructor, always returns true. |
||
2149 | * |
||
2150 | * @return bool |
||
2151 | */ |
||
2152 | public function is_plugin_enabled() { |
||
2159 | |||
2160 | /** |
||
2161 | * Perform the API request to refresh the blog token. |
||
2162 | * Note that we are making this request on behalf of the Jetpack master user, |
||
2163 | * given they were (most probably) the ones that registered the site at the first place. |
||
2164 | * |
||
2165 | * @return WP_Error|bool The result of updating the blog_token option. |
||
2166 | */ |
||
2167 | public function refresh_blog_token() { |
||
2217 | |||
2218 | /** |
||
2219 | * Disconnect the user from WP.com, and initiate the reconnect process. |
||
2220 | * |
||
2221 | * @return bool |
||
2222 | */ |
||
2223 | public function refresh_user_token() { |
||
2228 | |||
2229 | /** |
||
2230 | * Fetches a signed token. |
||
2231 | * |
||
2232 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead. |
||
2233 | * |
||
2234 | * @param object $token the token. |
||
2235 | * @return WP_Error|string a signed token |
||
2236 | */ |
||
2237 | public function get_signed_token( $token ) { |
||
2241 | |||
2242 | /** |
||
2243 | * If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) |
||
2244 | * |
||
2245 | * @param array $stats The Heartbeat stats array. |
||
2246 | * @return array $stats |
||
2247 | */ |
||
2248 | public function add_stats_to_heartbeat( $stats ) { |
||
2263 | } |
||
2264 |
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.