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' ) { |
||
1062 | |||
1063 | /** |
||
1064 | * Attempts Jetpack registration. |
||
1065 | * |
||
1066 | * @param bool $tos_agree Whether the user agreed to TOS. |
||
1067 | * |
||
1068 | * @return bool|WP_Error |
||
1069 | */ |
||
1070 | public function try_registration( $tos_agree = true ) { |
||
1109 | |||
1110 | /** |
||
1111 | * Adds a parameter to the register request body |
||
1112 | * |
||
1113 | * @since 9.7.0 |
||
1114 | * |
||
1115 | * @param string $name The name of the parameter to be added. |
||
1116 | * @param string $value The value of the parameter to be added. |
||
1117 | * |
||
1118 | * @throws \InvalidArgumentException If supplied arguments are not strings. |
||
1119 | * @return void |
||
1120 | */ |
||
1121 | public function add_register_request_param( $name, $value ) { |
||
1127 | |||
1128 | /** |
||
1129 | * Takes the response from the Jetpack register new site endpoint and |
||
1130 | * verifies it worked properly. |
||
1131 | * |
||
1132 | * @since 2.6 |
||
1133 | * |
||
1134 | * @param Mixed $response the response object, or the error object. |
||
1135 | * @return string|WP_Error A JSON object on success or WP_Error on failures |
||
1136 | **/ |
||
1137 | protected function validate_remote_register_response( $response ) { |
||
1206 | |||
1207 | /** |
||
1208 | * Adds a used nonce to a list of known nonces. |
||
1209 | * |
||
1210 | * @param int $timestamp the current request timestamp. |
||
1211 | * @param string $nonce the nonce value. |
||
1212 | * @return bool whether the nonce is unique or not. |
||
1213 | * |
||
1214 | * @deprecated since 9.5.0 |
||
1215 | * @see Nonce_Handler::add() |
||
1216 | */ |
||
1217 | public function add_nonce( $timestamp, $nonce ) { |
||
1221 | |||
1222 | /** |
||
1223 | * Cleans nonces that were saved when calling ::add_nonce. |
||
1224 | * |
||
1225 | * @todo Properly prepare the query before executing it. |
||
1226 | * |
||
1227 | * @param bool $all whether to clean even non-expired nonces. |
||
1228 | * |
||
1229 | * @deprecated since 9.5.0 |
||
1230 | * @see Nonce_Handler::clean_all() |
||
1231 | */ |
||
1232 | public function clean_nonces( $all = false ) { |
||
1236 | |||
1237 | /** |
||
1238 | * Sets the Connection custom capabilities. |
||
1239 | * |
||
1240 | * @param string[] $caps Array of the user's capabilities. |
||
1241 | * @param string $cap Capability name. |
||
1242 | * @param int $user_id The user ID. |
||
1243 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1244 | */ |
||
1245 | public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1278 | |||
1279 | /** |
||
1280 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
1281 | * |
||
1282 | * Based on local php max_execution_time in php.ini |
||
1283 | * |
||
1284 | * @since 5.4 |
||
1285 | * @return int |
||
1286 | **/ |
||
1287 | public function get_max_execution_time() { |
||
1296 | |||
1297 | /** |
||
1298 | * Sets a minimum request timeout, and returns the current timeout |
||
1299 | * |
||
1300 | * @since 5.4 |
||
1301 | * @param Integer $min_timeout the minimum timeout value. |
||
1302 | **/ |
||
1303 | View Code Duplication | public function set_min_time_limit( $min_timeout ) { |
|
1311 | |||
1312 | /** |
||
1313 | * Get our assumed site creation date. |
||
1314 | * Calculated based on the earlier date of either: |
||
1315 | * - Earliest admin user registration date. |
||
1316 | * - Earliest date of post of any post type. |
||
1317 | * |
||
1318 | * @since 7.2.0 |
||
1319 | * |
||
1320 | * @return string Assumed site creation date and time. |
||
1321 | */ |
||
1322 | public function get_assumed_site_creation_date() { |
||
1361 | |||
1362 | /** |
||
1363 | * Adds the activation source string as a parameter to passed arguments. |
||
1364 | * |
||
1365 | * @todo Refactor to use rawurlencode() instead of urlencode(). |
||
1366 | * |
||
1367 | * @param array $args arguments that need to have the source added. |
||
1368 | * @return array $amended arguments. |
||
1369 | */ |
||
1370 | View Code Duplication | public static function apply_activation_source_to_args( $args ) { |
|
1385 | |||
1386 | /** |
||
1387 | * Generates two secret tokens and the end of life timestamp for them. |
||
1388 | * |
||
1389 | * @param String $action The action name. |
||
1390 | * @param Integer $user_id The user identifier. |
||
1391 | * @param Integer $exp Expiration time in seconds. |
||
1392 | */ |
||
1393 | public function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
1396 | |||
1397 | /** |
||
1398 | * Returns two secret tokens and the end of life timestamp for them. |
||
1399 | * |
||
1400 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->get() instead. |
||
1401 | * |
||
1402 | * @param String $action The action name. |
||
1403 | * @param Integer $user_id The user identifier. |
||
1404 | * @return string|array an array of secrets or an error string. |
||
1405 | */ |
||
1406 | public function get_secrets( $action, $user_id ) { |
||
1410 | |||
1411 | /** |
||
1412 | * Deletes secret tokens in case they, for example, have expired. |
||
1413 | * |
||
1414 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->delete() instead. |
||
1415 | * |
||
1416 | * @param String $action The action name. |
||
1417 | * @param Integer $user_id The user identifier. |
||
1418 | */ |
||
1419 | public function delete_secrets( $action, $user_id ) { |
||
1423 | |||
1424 | /** |
||
1425 | * Deletes all connection tokens and transients from the local Jetpack site. |
||
1426 | * If the plugin object has been provided in the constructor, the function first checks |
||
1427 | * whether it's the only active connection. |
||
1428 | * If there are any other connections, the function will do nothing and return `false` |
||
1429 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1430 | * |
||
1431 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1432 | * |
||
1433 | * @return bool True if disconnected successfully, false otherwise. |
||
1434 | */ |
||
1435 | public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { |
||
1471 | |||
1472 | /** |
||
1473 | * Tells WordPress.com to disconnect the site and clear all tokens from cached site. |
||
1474 | * If the plugin object has been provided in the constructor, the function first check |
||
1475 | * whether it's the only active connection. |
||
1476 | * If there are any other connections, the function will do nothing and return `false` |
||
1477 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
1478 | * |
||
1479 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
1480 | * |
||
1481 | * @return bool True if disconnected successfully, false otherwise. |
||
1482 | */ |
||
1483 | public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { |
||
1503 | |||
1504 | /** |
||
1505 | * Disconnect the plugin and remove the tokens. |
||
1506 | * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. |
||
1507 | * This is a proxy method to simplify the Connection package API. |
||
1508 | * |
||
1509 | * @see Manager::disable_plugin() |
||
1510 | * @see Manager::disconnect_site_wpcom() |
||
1511 | * @see Manager::delete_all_connection_tokens() |
||
1512 | * |
||
1513 | * @return bool |
||
1514 | */ |
||
1515 | public function remove_connection() { |
||
1522 | |||
1523 | /** |
||
1524 | * Completely clearing up the connection, and initiating reconnect. |
||
1525 | * |
||
1526 | * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. |
||
1527 | */ |
||
1528 | public function reconnect() { |
||
1536 | |||
1537 | /** |
||
1538 | * Validate the tokens, and refresh the invalid ones. |
||
1539 | * |
||
1540 | * @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. |
||
1541 | */ |
||
1542 | public function restore() { |
||
1578 | |||
1579 | /** |
||
1580 | * Responds to a WordPress.com call to register the current site. |
||
1581 | * Should be changed to protected. |
||
1582 | * |
||
1583 | * @param array $registration_data Array of [ secret_1, user_id ]. |
||
1584 | */ |
||
1585 | public function handle_registration( array $registration_data ) { |
||
1593 | |||
1594 | /** |
||
1595 | * Perform the API request to validate the blog and user tokens. |
||
1596 | * |
||
1597 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->validate_tokens() instead. |
||
1598 | * |
||
1599 | * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. |
||
1600 | * |
||
1601 | * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. |
||
1602 | */ |
||
1603 | public function validate_tokens( $user_id = null ) { |
||
1607 | |||
1608 | /** |
||
1609 | * Verify a Previously Generated Secret. |
||
1610 | * |
||
1611 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->verify() instead. |
||
1612 | * |
||
1613 | * @param string $action The type of secret to verify. |
||
1614 | * @param string $secret_1 The secret string to compare to what is stored. |
||
1615 | * @param int $user_id The user ID of the owner of the secret. |
||
1616 | * @return \WP_Error|string WP_Error on failure, secret_2 on success. |
||
1617 | */ |
||
1618 | public function verify_secrets( $action, $secret_1, $user_id ) { |
||
1622 | |||
1623 | /** |
||
1624 | * Responds to a WordPress.com call to authorize the current user. |
||
1625 | * Should be changed to protected. |
||
1626 | */ |
||
1627 | public function handle_authorization() { |
||
1630 | |||
1631 | /** |
||
1632 | * Obtains the auth token. |
||
1633 | * |
||
1634 | * @param array $data The request data. |
||
1635 | * @return object|\WP_Error Returns the auth token on success. |
||
1636 | * Returns a \WP_Error on failure. |
||
1637 | */ |
||
1638 | public function get_token( $data ) { |
||
1641 | |||
1642 | /** |
||
1643 | * Builds a URL to the Jetpack connection auth page. |
||
1644 | * |
||
1645 | * @param WP_User $user (optional) defaults to the current logged in user. |
||
1646 | * @param String $redirect (optional) a redirect URL to use instead of the default. |
||
1647 | * @return string Connect URL. |
||
1648 | */ |
||
1649 | public function get_authorization_url( $user = null, $redirect = null ) { |
||
1736 | |||
1737 | /** |
||
1738 | * Authorizes the user by obtaining and storing the user token. |
||
1739 | * |
||
1740 | * @param array $data The request data. |
||
1741 | * @return string|\WP_Error Returns a string on success. |
||
1742 | * Returns a \WP_Error on failure. |
||
1743 | */ |
||
1744 | public function authorize( $data = array() ) { |
||
1835 | |||
1836 | /** |
||
1837 | * Disconnects from the Jetpack servers. |
||
1838 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
1839 | */ |
||
1840 | public function disconnect_site() { |
||
1843 | |||
1844 | /** |
||
1845 | * The Base64 Encoding of the SHA1 Hash of the Input. |
||
1846 | * |
||
1847 | * @param string $text The string to hash. |
||
1848 | * @return string |
||
1849 | */ |
||
1850 | public function sha1_base64( $text ) { |
||
1853 | |||
1854 | /** |
||
1855 | * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. |
||
1856 | * |
||
1857 | * @param string $domain The domain to check. |
||
1858 | * |
||
1859 | * @return bool|WP_Error |
||
1860 | */ |
||
1861 | public function is_usable_domain( $domain ) { |
||
1948 | |||
1949 | /** |
||
1950 | * Gets the requested token. |
||
1951 | * |
||
1952 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead. |
||
1953 | * |
||
1954 | * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. |
||
1955 | * @param string|false $token_key If provided, check that the token matches the provided input. |
||
1956 | * @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. |
||
1957 | * |
||
1958 | * @return object|false |
||
1959 | * |
||
1960 | * @see $this->get_tokens()->get_access_token() |
||
1961 | */ |
||
1962 | public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { |
||
1966 | |||
1967 | /** |
||
1968 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths |
||
1969 | * since it is passed by reference to various methods. |
||
1970 | * Capture it here so we can verify the signature later. |
||
1971 | * |
||
1972 | * @param array $methods an array of available XMLRPC methods. |
||
1973 | * @return array the same array, since this method doesn't add or remove anything. |
||
1974 | */ |
||
1975 | public function xmlrpc_methods( $methods ) { |
||
1979 | |||
1980 | /** |
||
1981 | * Resets the raw post data parameter for testing purposes. |
||
1982 | */ |
||
1983 | public function reset_raw_post_data() { |
||
1986 | |||
1987 | /** |
||
1988 | * Registering an additional method. |
||
1989 | * |
||
1990 | * @param array $methods an array of available XMLRPC methods. |
||
1991 | * @return array the amended array in case the method is added. |
||
1992 | */ |
||
1993 | public function public_xmlrpc_methods( $methods ) { |
||
1999 | |||
2000 | /** |
||
2001 | * Handles a getOptions XMLRPC method call. |
||
2002 | * |
||
2003 | * @param array $args method call arguments. |
||
2004 | * @return an amended XMLRPC server options array. |
||
2005 | */ |
||
2006 | public function jetpack_get_options( $args ) { |
||
2047 | |||
2048 | /** |
||
2049 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
2050 | * |
||
2051 | * @param array $options standard Core options. |
||
2052 | * @return array amended options. |
||
2053 | */ |
||
2054 | public function xmlrpc_options( $options ) { |
||
2072 | |||
2073 | /** |
||
2074 | * Resets the saved authentication state in between testing requests. |
||
2075 | */ |
||
2076 | public function reset_saved_auth_state() { |
||
2079 | |||
2080 | /** |
||
2081 | * Sign a user role with the master access token. |
||
2082 | * If not specified, will default to the current user. |
||
2083 | * |
||
2084 | * @access public |
||
2085 | * |
||
2086 | * @param string $role User role. |
||
2087 | * @param int $user_id ID of the user. |
||
2088 | * @return string Signed user role. |
||
2089 | */ |
||
2090 | public function sign_role( $role, $user_id = null ) { |
||
2093 | |||
2094 | /** |
||
2095 | * Set the plugin instance. |
||
2096 | * |
||
2097 | * @param Plugin $plugin_instance The plugin instance. |
||
2098 | * |
||
2099 | * @return $this |
||
2100 | */ |
||
2101 | public function set_plugin_instance( Plugin $plugin_instance ) { |
||
2106 | |||
2107 | /** |
||
2108 | * Retrieve the plugin management object. |
||
2109 | * |
||
2110 | * @return Plugin|null |
||
2111 | */ |
||
2112 | public function get_plugin() { |
||
2115 | |||
2116 | /** |
||
2117 | * Get all connected plugins information, excluding those disconnected by user. |
||
2118 | * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded |
||
2119 | * Even if you don't use Jetpack Config, it may be introduced later by other plugins, |
||
2120 | * so please make sure not to run the method too early in the code. |
||
2121 | * |
||
2122 | * @return array|WP_Error |
||
2123 | */ |
||
2124 | public function get_connected_plugins() { |
||
2133 | |||
2134 | /** |
||
2135 | * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. |
||
2136 | * Note: this method does not remove any access tokens. |
||
2137 | * |
||
2138 | * @return bool |
||
2139 | */ |
||
2140 | public function disable_plugin() { |
||
2147 | |||
2148 | /** |
||
2149 | * Force plugin reconnect after user-initiated disconnect. |
||
2150 | * After its called, the plugin will be allowed to use the connection again. |
||
2151 | * Note: this method does not initialize access tokens. |
||
2152 | * |
||
2153 | * @return bool |
||
2154 | */ |
||
2155 | public function enable_plugin() { |
||
2162 | |||
2163 | /** |
||
2164 | * Whether the plugin is allowed to use the connection, or it's been disconnected by user. |
||
2165 | * If no plugin slug was passed into the constructor, always returns true. |
||
2166 | * |
||
2167 | * @return bool |
||
2168 | */ |
||
2169 | public function is_plugin_enabled() { |
||
2176 | |||
2177 | /** |
||
2178 | * Perform the API request to refresh the blog token. |
||
2179 | * Note that we are making this request on behalf of the Jetpack master user, |
||
2180 | * given they were (most probably) the ones that registered the site at the first place. |
||
2181 | * |
||
2182 | * @return WP_Error|bool The result of updating the blog_token option. |
||
2183 | */ |
||
2184 | public function refresh_blog_token() { |
||
2234 | |||
2235 | /** |
||
2236 | * Disconnect the user from WP.com, and initiate the reconnect process. |
||
2237 | * |
||
2238 | * @return bool |
||
2239 | */ |
||
2240 | public function refresh_user_token() { |
||
2245 | |||
2246 | /** |
||
2247 | * Fetches a signed token. |
||
2248 | * |
||
2249 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead. |
||
2250 | * |
||
2251 | * @param object $token the token. |
||
2252 | * @return WP_Error|string a signed token |
||
2253 | */ |
||
2254 | public function get_signed_token( $token ) { |
||
2258 | |||
2259 | /** |
||
2260 | * If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) |
||
2261 | * |
||
2262 | * @param array $stats The Heartbeat stats array. |
||
2263 | * @return array $stats |
||
2264 | */ |
||
2265 | public function add_stats_to_heartbeat( $stats ) { |
||
2280 | } |
||
2281 |
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.