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 |
||
| 22 | class Manager { |
||
| 23 | const MAGIC_NORMAL_TOKEN_KEY = ';normal;'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Constant used to fetch the master user token. Deprecated. |
||
| 27 | * |
||
| 28 | * @deprecated 9.0.0 |
||
| 29 | * @see Manager::CONNECTION_OWNER |
||
| 30 | * @var boolean |
||
| 31 | */ |
||
| 32 | const JETPACK_MASTER_USER = true; //phpcs:ignore Jetpack.Constants.MasterUserConstant.ShouldNotBeUsed |
||
| 33 | |||
| 34 | /** |
||
| 35 | * For internal use only. If you need to get the connection owner, use the provided methods |
||
| 36 | * get_connection_owner_id, get_connection_owner and is_connection_owner |
||
| 37 | * |
||
| 38 | * @todo Add private visibility once PHP 7.1 is the minimum supported verion. |
||
| 39 | * |
||
| 40 | * @var boolean |
||
| 41 | */ |
||
| 42 | const CONNECTION_OWNER = true; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * A copy of the raw POST data for signature verification purposes. |
||
| 46 | * |
||
| 47 | * @var String |
||
| 48 | */ |
||
| 49 | protected $raw_post_data; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Verification data needs to be stored to properly verify everything. |
||
| 53 | * |
||
| 54 | * @var Object |
||
| 55 | */ |
||
| 56 | private $xmlrpc_verification = null; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Plugin management object. |
||
| 60 | * |
||
| 61 | * @var Plugin |
||
| 62 | */ |
||
| 63 | private $plugin = null; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Initialize the object. |
||
| 67 | * Make sure to call the "Configure" first. |
||
| 68 | * |
||
| 69 | * @param string $plugin_slug Slug of the plugin using the connection (optional, but encouraged). |
||
|
|
|||
| 70 | * |
||
| 71 | * @see \Automattic\Jetpack\Config |
||
| 72 | */ |
||
| 73 | public function __construct( $plugin_slug = null ) { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Initializes required listeners. This is done separately from the constructors |
||
| 81 | * because some objects sometimes need to instantiate separate objects of this class. |
||
| 82 | * |
||
| 83 | * @todo Implement a proper nonce verification. |
||
| 84 | */ |
||
| 85 | public static function configure() { |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Sets up the XMLRPC request handlers. |
||
| 126 | * |
||
| 127 | * @param array $request_params incoming request parameters. |
||
| 128 | * @param Boolean $is_active whether the connection is currently active. |
||
| 129 | * @param Boolean $is_signed whether the signature check has been successful. |
||
| 130 | * @param \Jetpack_XMLRPC_Server $xmlrpc_server (optional) an instance of the server to use instead of instantiating a new one. |
||
| 131 | */ |
||
| 132 | public function setup_xmlrpc_handlers( |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Initializes the REST API connector on the init hook. |
||
| 207 | */ |
||
| 208 | public function initialize_rest_api_registration_connector() { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
| 214 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
| 215 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
| 216 | * which is accessible via a different URI. Most of the below is copied directly |
||
| 217 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
| 218 | * |
||
| 219 | * @todo Tighten $wp_xmlrpc_server_class a bit to make sure it doesn't do bad things. |
||
| 220 | */ |
||
| 221 | public function alternate_xmlrpc() { |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
| 248 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
| 249 | * ensure that Core and other plugins' methods are not exposed. |
||
| 250 | * |
||
| 251 | * @param array $methods a list of registered WordPress XMLRPC methods. |
||
| 252 | * @return array filtered $methods |
||
| 253 | */ |
||
| 254 | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Removes all other authentication methods not to allow other |
||
| 268 | * methods to validate unauthenticated requests. |
||
| 269 | */ |
||
| 270 | public function require_jetpack_authentication() { |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 284 | * |
||
| 285 | * @param WP_User|Mixed $user user object if authenticated. |
||
| 286 | * @param String $username username. |
||
| 287 | * @param String $password password string. |
||
| 288 | * @return WP_User|Mixed authenticated user or error. |
||
| 289 | */ |
||
| 290 | public function authenticate_jetpack( $user, $username, $password ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Verifies the signature of the current request. |
||
| 316 | * |
||
| 317 | * @return false|array |
||
| 318 | */ |
||
| 319 | public function verify_xml_rpc_signature() { |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Verifies the signature of the current request. |
||
| 343 | * |
||
| 344 | * This function has side effects and should not be used. Instead, |
||
| 345 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
| 346 | * |
||
| 347 | * @internal |
||
| 348 | * @todo Refactor to use proper nonce verification. |
||
| 349 | */ |
||
| 350 | private function internal_verify_xml_rpc_signature() { |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI. |
||
| 510 | * |
||
| 511 | * @return Boolean is the site connected? |
||
| 512 | */ |
||
| 513 | public function is_active() { |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Returns true if the site has both a token and a blog id, which indicates a site has been registered. |
||
| 522 | * |
||
| 523 | * @access public |
||
| 524 | * @deprecated 9.2.0 Use is_connected instead |
||
| 525 | * @see Manager::is_connected |
||
| 526 | * |
||
| 527 | * @return bool |
||
| 528 | */ |
||
| 529 | public function is_registered() { |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Returns true if the site has both a token and a blog id, which indicates a site has been connected. |
||
| 536 | * |
||
| 537 | * @access public |
||
| 538 | * @since 9.2.0 |
||
| 539 | * |
||
| 540 | * @return bool |
||
| 541 | */ |
||
| 542 | public function is_connected() { |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Returns true if the site has at least one connected administrator. |
||
| 550 | * |
||
| 551 | * @access public |
||
| 552 | * @since 9.2.0 |
||
| 553 | * |
||
| 554 | * @return bool |
||
| 555 | */ |
||
| 556 | public function has_connected_admin() { |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Returns true if the site has any connected user. |
||
| 562 | * |
||
| 563 | * @access public |
||
| 564 | * @since 9.2.0 |
||
| 565 | * |
||
| 566 | * @return bool |
||
| 567 | */ |
||
| 568 | public function has_connected_user() { |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Returns true if the site has a connected Blog owner (master_user). |
||
| 574 | * |
||
| 575 | * @access public |
||
| 576 | * @since 9.2.0 |
||
| 577 | * |
||
| 578 | * @return bool |
||
| 579 | */ |
||
| 580 | public function has_connected_owner() { |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Checks to see if the connection owner of the site is missing. |
||
| 586 | * |
||
| 587 | * @return bool |
||
| 588 | */ |
||
| 589 | public function is_missing_connection_owner() { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Returns true if the user with the specified identifier is connected to |
||
| 600 | * WordPress.com. |
||
| 601 | * |
||
| 602 | * @param int $user_id the user identifier. Default is the current user. |
||
| 603 | * @return bool Boolean is the user connected? |
||
| 604 | */ |
||
| 605 | public function is_user_connected( $user_id = false ) { |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Returns the local user ID of the connection owner. |
||
| 616 | * |
||
| 617 | * @return bool|int Returns the ID of the connection owner or False if no connection owner found. |
||
| 618 | */ |
||
| 619 | public function get_connection_owner_id() { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Returns an array of user_id's that have user tokens for communicating with wpcom. |
||
| 626 | * Able to select by specific capability. |
||
| 627 | * |
||
| 628 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::get_connected_users() instead. |
||
| 629 | * |
||
| 630 | * @param string $capability The capability of the user. |
||
| 631 | * @return array Array of WP_User objects if found. |
||
| 632 | */ |
||
| 633 | public function get_connected_users( $capability = 'any' ) { |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Get the wpcom user data of the current|specified connected user. |
||
| 640 | * |
||
| 641 | * @todo Refactor to properly load the XMLRPC client independently. |
||
| 642 | * |
||
| 643 | * @param Integer $user_id the user identifier. |
||
| 644 | * @return Object the user object. |
||
| 645 | */ |
||
| 646 | public function get_connected_user_data( $user_id = null ) { |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Returns a user object of the connection owner. |
||
| 675 | * |
||
| 676 | * @return WP_User|false False if no connection owner found. |
||
| 677 | */ |
||
| 678 | public function get_connection_owner() { |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Returns true if the provided user is the Jetpack connection owner. |
||
| 700 | * If user ID is not specified, the current user will be used. |
||
| 701 | * |
||
| 702 | * @param Integer|Boolean $user_id the user identifier. False for current user. |
||
| 703 | * @return Boolean True the user the connection owner, false otherwise. |
||
| 704 | */ |
||
| 705 | public function is_connection_owner( $user_id = false ) { |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Connects the user with a specified ID to a WordPress.com user using the |
||
| 715 | * remote login flow. |
||
| 716 | * |
||
| 717 | * @access public |
||
| 718 | * |
||
| 719 | * @param Integer $user_id (optional) the user identifier, defaults to current user. |
||
| 720 | * @param String $redirect_url the URL to redirect the user to for processing, defaults to |
||
| 721 | * admin_url(). |
||
| 722 | * @return WP_Error only in case of a failed user lookup. |
||
| 723 | */ |
||
| 724 | public function connect_user( $user_id = null, $redirect_url = null ) { |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Unlinks the current user from the linked WordPress.com user. |
||
| 747 | * |
||
| 748 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::disconnect_user() instead. |
||
| 749 | * |
||
| 750 | * @access public |
||
| 751 | * @static |
||
| 752 | * |
||
| 753 | * @todo Refactor to properly load the XMLRPC client independently. |
||
| 754 | * |
||
| 755 | * @param Integer $user_id the user identifier. |
||
| 756 | * @param bool $can_overwrite_primary_user Allow for the primary user to be disconnected. |
||
| 757 | * @return Boolean Whether the disconnection of the user was successful. |
||
| 758 | */ |
||
| 759 | public static function disconnect_user( $user_id = null, $can_overwrite_primary_user = false ) { |
||
| 763 | |||
| 764 | /** |
||
| 765 | * Returns the requested Jetpack API URL. |
||
| 766 | * |
||
| 767 | * @param String $relative_url the relative API path. |
||
| 768 | * @return String API URL. |
||
| 769 | */ |
||
| 770 | public function api_url( $relative_url ) { |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Returns the Jetpack XMLRPC WordPress.com API endpoint URL. |
||
| 810 | * |
||
| 811 | * @return String XMLRPC API URL. |
||
| 812 | */ |
||
| 813 | public function xmlrpc_api_url() { |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Attempts Jetpack registration which sets up the site for connection. Should |
||
| 824 | * remain public because the call to action comes from the current site, not from |
||
| 825 | * WordPress.com. |
||
| 826 | * |
||
| 827 | * @param String $api_endpoint (optional) an API endpoint to use, defaults to 'register'. |
||
| 828 | * @return true|WP_Error The error object. |
||
| 829 | */ |
||
| 830 | public function register( $api_endpoint = 'register' ) { |
||
| 972 | |||
| 973 | /** |
||
| 974 | * Takes the response from the Jetpack register new site endpoint and |
||
| 975 | * verifies it worked properly. |
||
| 976 | * |
||
| 977 | * @since 2.6 |
||
| 978 | * |
||
| 979 | * @param Mixed $response the response object, or the error object. |
||
| 980 | * @return string|WP_Error A JSON object on success or WP_Error on failures |
||
| 981 | **/ |
||
| 982 | protected function validate_remote_register_response( $response ) { |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * Adds a used nonce to a list of known nonces. |
||
| 1054 | * |
||
| 1055 | * @param int $timestamp the current request timestamp. |
||
| 1056 | * @param string $nonce the nonce value. |
||
| 1057 | * @return bool whether the nonce is unique or not. |
||
| 1058 | */ |
||
| 1059 | public function add_nonce( $timestamp, $nonce ) { |
||
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Cleans nonces that were saved when calling ::add_nonce. |
||
| 1100 | * |
||
| 1101 | * @todo Properly prepare the query before executing it. |
||
| 1102 | * |
||
| 1103 | * @param bool $all whether to clean even non-expired nonces. |
||
| 1104 | */ |
||
| 1105 | public function clean_nonces( $all = false ) { |
||
| 1126 | |||
| 1127 | /** |
||
| 1128 | * Sets the Connection custom capabilities. |
||
| 1129 | * |
||
| 1130 | * @param string[] $caps Array of the user's capabilities. |
||
| 1131 | * @param string $cap Capability name. |
||
| 1132 | * @param int $user_id The user ID. |
||
| 1133 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
| 1134 | */ |
||
| 1135 | public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 1170 | * |
||
| 1171 | * Based on local php max_execution_time in php.ini |
||
| 1172 | * |
||
| 1173 | * @since 5.4 |
||
| 1174 | * @return int |
||
| 1175 | **/ |
||
| 1176 | public function get_max_execution_time() { |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Sets a minimum request timeout, and returns the current timeout |
||
| 1188 | * |
||
| 1189 | * @since 5.4 |
||
| 1190 | * @param Integer $min_timeout the minimum timeout value. |
||
| 1191 | **/ |
||
| 1192 | View Code Duplication | public function set_min_time_limit( $min_timeout ) { |
|
| 1200 | |||
| 1201 | /** |
||
| 1202 | * Get our assumed site creation date. |
||
| 1203 | * Calculated based on the earlier date of either: |
||
| 1204 | * - Earliest admin user registration date. |
||
| 1205 | * - Earliest date of post of any post type. |
||
| 1206 | * |
||
| 1207 | * @since 7.2.0 |
||
| 1208 | * |
||
| 1209 | * @return string Assumed site creation date and time. |
||
| 1210 | */ |
||
| 1211 | public function get_assumed_site_creation_date() { |
||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Adds the activation source string as a parameter to passed arguments. |
||
| 1253 | * |
||
| 1254 | * @todo Refactor to use rawurlencode() instead of urlencode(). |
||
| 1255 | * |
||
| 1256 | * @param array $args arguments that need to have the source added. |
||
| 1257 | * @return array $amended arguments. |
||
| 1258 | */ |
||
| 1259 | View Code Duplication | public static function apply_activation_source_to_args( $args ) { |
|
| 1274 | |||
| 1275 | /** |
||
| 1276 | * Generates two secret tokens and the end of life timestamp for them. |
||
| 1277 | * |
||
| 1278 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets::generate() instead. |
||
| 1279 | * |
||
| 1280 | * @param String $action The action name. |
||
| 1281 | * @param Integer $user_id The user identifier. |
||
| 1282 | * @param Integer $exp Expiration time in seconds. |
||
| 1283 | */ |
||
| 1284 | public function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * Returns two secret tokens and the end of life timestamp for them. |
||
| 1291 | * |
||
| 1292 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets::get() instead. |
||
| 1293 | * |
||
| 1294 | * @param String $action The action name. |
||
| 1295 | * @param Integer $user_id The user identifier. |
||
| 1296 | * @return string|array an array of secrets or an error string. |
||
| 1297 | */ |
||
| 1298 | public function get_secrets( $action, $user_id ) { |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Deletes secret tokens in case they, for example, have expired. |
||
| 1305 | * |
||
| 1306 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets::delete() instead. |
||
| 1307 | * |
||
| 1308 | * @param String $action The action name. |
||
| 1309 | * @param Integer $user_id The user identifier. |
||
| 1310 | */ |
||
| 1311 | public function delete_secrets( $action, $user_id ) { |
||
| 1315 | |||
| 1316 | /** |
||
| 1317 | * Deletes all connection tokens and transients from the local Jetpack site. |
||
| 1318 | * If the plugin object has been provided in the constructor, the function first checks |
||
| 1319 | * whether it's the only active connection. |
||
| 1320 | * If there are any other connections, the function will do nothing and return `false` |
||
| 1321 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
| 1322 | * |
||
| 1323 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
| 1324 | * |
||
| 1325 | * @return bool True if disconnected successfully, false otherwise. |
||
| 1326 | */ |
||
| 1327 | public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { |
||
| 1335 | |||
| 1336 | /** |
||
| 1337 | * Tells WordPress.com to disconnect the site and clear all tokens from cached site. |
||
| 1338 | * If the plugin object has been provided in the constructor, the function first check |
||
| 1339 | * whether it's the only active connection. |
||
| 1340 | * If there are any other connections, the function will do nothing and return `false` |
||
| 1341 | * (unless `$ignore_connected_plugins` is set to `true`). |
||
| 1342 | * |
||
| 1343 | * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. |
||
| 1344 | * |
||
| 1345 | * @return bool True if disconnected successfully, false otherwise. |
||
| 1346 | */ |
||
| 1347 | public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * Disconnect the plugin and remove the tokens. |
||
| 1370 | * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. |
||
| 1371 | * This is a proxy method to simplify the Connection package API. |
||
| 1372 | * |
||
| 1373 | * @see Manager::disable_plugin() |
||
| 1374 | * @see Manager::disconnect_site_wpcom() |
||
| 1375 | * @see Manager::delete_all_connection_tokens() |
||
| 1376 | * |
||
| 1377 | * @return bool |
||
| 1378 | */ |
||
| 1379 | public function remove_connection() { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Completely clearing up the connection, and initiating reconnect. |
||
| 1389 | * |
||
| 1390 | * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. |
||
| 1391 | */ |
||
| 1392 | public function reconnect() { |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Validate the tokens, and refresh the invalid ones. |
||
| 1403 | * |
||
| 1404 | * @return string|true|WP_Error True if connection restored or string indicating what's to be done next. A `WP_Error` object otherwise. |
||
| 1405 | */ |
||
| 1406 | public function restore() { |
||
| 1429 | |||
| 1430 | /** |
||
| 1431 | * Responds to a WordPress.com call to register the current site. |
||
| 1432 | * Should be changed to protected. |
||
| 1433 | * |
||
| 1434 | * @param array $registration_data Array of [ secret_1, user_id ]. |
||
| 1435 | */ |
||
| 1436 | public function handle_registration( array $registration_data ) { |
||
| 1444 | |||
| 1445 | /** |
||
| 1446 | * Perform the API request to validate the blog and user tokens. |
||
| 1447 | * |
||
| 1448 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::validate_tokens() instead. |
||
| 1449 | * |
||
| 1450 | * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. |
||
| 1451 | * |
||
| 1452 | * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. |
||
| 1453 | */ |
||
| 1454 | public function validate_tokens( $user_id = null ) { |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Verify a Previously Generated Secret. |
||
| 1461 | * |
||
| 1462 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets::verify() instead. |
||
| 1463 | * |
||
| 1464 | * @param string $action The type of secret to verify. |
||
| 1465 | * @param string $secret_1 The secret string to compare to what is stored. |
||
| 1466 | * @param int $user_id The user ID of the owner of the secret. |
||
| 1467 | * @return \WP_Error|string WP_Error on failure, secret_2 on success. |
||
| 1468 | */ |
||
| 1469 | public function verify_secrets( $action, $secret_1, $user_id ) { |
||
| 1473 | |||
| 1474 | /** |
||
| 1475 | * Responds to a WordPress.com call to authorize the current user. |
||
| 1476 | * Should be changed to protected. |
||
| 1477 | */ |
||
| 1478 | public function handle_authorization() { |
||
| 1481 | |||
| 1482 | /** |
||
| 1483 | * Obtains the auth token. |
||
| 1484 | * |
||
| 1485 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::get() instead. |
||
| 1486 | * |
||
| 1487 | * @param array $data The request data. |
||
| 1488 | * @return object|\WP_Error Returns the auth token on success. |
||
| 1489 | * Returns a \WP_Error on failure. |
||
| 1490 | */ |
||
| 1491 | public function get_token( $data ) { |
||
| 1495 | |||
| 1496 | /** |
||
| 1497 | * Builds a URL to the Jetpack connection auth page. |
||
| 1498 | * |
||
| 1499 | * @param WP_User $user (optional) defaults to the current logged in user. |
||
| 1500 | * @param String $redirect (optional) a redirect URL to use instead of the default. |
||
| 1501 | * @return string Connect URL. |
||
| 1502 | */ |
||
| 1503 | public function get_authorization_url( $user = null, $redirect = null ) { |
||
| 1590 | |||
| 1591 | /** |
||
| 1592 | * Authorizes the user by obtaining and storing the user token. |
||
| 1593 | * |
||
| 1594 | * @param array $data The request data. |
||
| 1595 | * @return string|\WP_Error Returns a string on success. |
||
| 1596 | * Returns a \WP_Error on failure. |
||
| 1597 | */ |
||
| 1598 | public function authorize( $data = array() ) { |
||
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Disconnects from the Jetpack servers. |
||
| 1694 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 1695 | */ |
||
| 1696 | public function disconnect_site() { |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * The Base64 Encoding of the SHA1 Hash of the Input. |
||
| 1702 | * |
||
| 1703 | * @param string $text The string to hash. |
||
| 1704 | * @return string |
||
| 1705 | */ |
||
| 1706 | public function sha1_base64( $text ) { |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. |
||
| 1712 | * |
||
| 1713 | * @param string $domain The domain to check. |
||
| 1714 | * |
||
| 1715 | * @return bool|WP_Error |
||
| 1716 | */ |
||
| 1717 | public function is_usable_domain( $domain ) { |
||
| 1804 | |||
| 1805 | /** |
||
| 1806 | * Gets the requested token. |
||
| 1807 | * |
||
| 1808 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::get_access_token() instead. |
||
| 1809 | * |
||
| 1810 | * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. |
||
| 1811 | * @param string|false $token_key If provided, check that the token matches the provided input. |
||
| 1812 | * @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. |
||
| 1813 | * |
||
| 1814 | * @return object|false |
||
| 1815 | * |
||
| 1816 | * @see Tokens::get_access_token() |
||
| 1817 | */ |
||
| 1818 | public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { |
||
| 1822 | |||
| 1823 | /** |
||
| 1824 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths |
||
| 1825 | * since it is passed by reference to various methods. |
||
| 1826 | * Capture it here so we can verify the signature later. |
||
| 1827 | * |
||
| 1828 | * @param array $methods an array of available XMLRPC methods. |
||
| 1829 | * @return array the same array, since this method doesn't add or remove anything. |
||
| 1830 | */ |
||
| 1831 | public function xmlrpc_methods( $methods ) { |
||
| 1835 | |||
| 1836 | /** |
||
| 1837 | * Resets the raw post data parameter for testing purposes. |
||
| 1838 | */ |
||
| 1839 | public function reset_raw_post_data() { |
||
| 1842 | |||
| 1843 | /** |
||
| 1844 | * Registering an additional method. |
||
| 1845 | * |
||
| 1846 | * @param array $methods an array of available XMLRPC methods. |
||
| 1847 | * @return array the amended array in case the method is added. |
||
| 1848 | */ |
||
| 1849 | public function public_xmlrpc_methods( $methods ) { |
||
| 1855 | |||
| 1856 | /** |
||
| 1857 | * Handles a getOptions XMLRPC method call. |
||
| 1858 | * |
||
| 1859 | * @param array $args method call arguments. |
||
| 1860 | * @return an amended XMLRPC server options array. |
||
| 1861 | */ |
||
| 1862 | public function jetpack_get_options( $args ) { |
||
| 1903 | |||
| 1904 | /** |
||
| 1905 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
| 1906 | * |
||
| 1907 | * @param array $options standard Core options. |
||
| 1908 | * @return array amended options. |
||
| 1909 | */ |
||
| 1910 | public function xmlrpc_options( $options ) { |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Resets the saved authentication state in between testing requests. |
||
| 1931 | */ |
||
| 1932 | public function reset_saved_auth_state() { |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Sign a user role with the master access token. |
||
| 1938 | * If not specified, will default to the current user. |
||
| 1939 | * |
||
| 1940 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::sign_role() instead. |
||
| 1941 | * |
||
| 1942 | * @access public |
||
| 1943 | * |
||
| 1944 | * @param string $role User role. |
||
| 1945 | * @param int $user_id ID of the user. |
||
| 1946 | * @return string Signed user role. |
||
| 1947 | */ |
||
| 1948 | public function sign_role( $role, $user_id = null ) { |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Set the plugin instance. |
||
| 1955 | * |
||
| 1956 | * @param Plugin $plugin_instance The plugin instance. |
||
| 1957 | * |
||
| 1958 | * @return $this |
||
| 1959 | */ |
||
| 1960 | public function set_plugin_instance( Plugin $plugin_instance ) { |
||
| 1965 | |||
| 1966 | /** |
||
| 1967 | * Retrieve the plugin management object. |
||
| 1968 | * |
||
| 1969 | * @return Plugin |
||
| 1970 | */ |
||
| 1971 | public function get_plugin() { |
||
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Get all connected plugins information, excluding those disconnected by user. |
||
| 1977 | * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded |
||
| 1978 | * Even if you don't use Jetpack Config, it may be introduced later by other plugins, |
||
| 1979 | * so please make sure not to run the method too early in the code. |
||
| 1980 | * |
||
| 1981 | * @return array|WP_Error |
||
| 1982 | */ |
||
| 1983 | public function get_connected_plugins() { |
||
| 1992 | |||
| 1993 | /** |
||
| 1994 | * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. |
||
| 1995 | * Note: this method does not remove any access tokens. |
||
| 1996 | * |
||
| 1997 | * @return bool |
||
| 1998 | */ |
||
| 1999 | public function disable_plugin() { |
||
| 2006 | |||
| 2007 | /** |
||
| 2008 | * Force plugin reconnect after user-initiated disconnect. |
||
| 2009 | * After its called, the plugin will be allowed to use the connection again. |
||
| 2010 | * Note: this method does not initialize access tokens. |
||
| 2011 | * |
||
| 2012 | * @return bool |
||
| 2013 | */ |
||
| 2014 | public function enable_plugin() { |
||
| 2021 | |||
| 2022 | /** |
||
| 2023 | * Whether the plugin is allowed to use the connection, or it's been disconnected by user. |
||
| 2024 | * If no plugin slug was passed into the constructor, always returns true. |
||
| 2025 | * |
||
| 2026 | * @return bool |
||
| 2027 | */ |
||
| 2028 | public function is_plugin_enabled() { |
||
| 2035 | |||
| 2036 | /** |
||
| 2037 | * Perform the API request to refresh the blog token. |
||
| 2038 | * Note that we are making this request on behalf of the Jetpack master user, |
||
| 2039 | * given they were (most probably) the ones that registered the site at the first place. |
||
| 2040 | * |
||
| 2041 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::refresh_blog_token() instead. |
||
| 2042 | * |
||
| 2043 | * @return WP_Error|bool The result of updating the blog_token option. |
||
| 2044 | */ |
||
| 2045 | public static function refresh_blog_token() { |
||
| 2049 | |||
| 2050 | /** |
||
| 2051 | * Disconnect the user from WP.com, and initiate the reconnect process. |
||
| 2052 | * |
||
| 2053 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::refresh_user_token() instead. |
||
| 2054 | * |
||
| 2055 | * @return bool |
||
| 2056 | */ |
||
| 2057 | public function refresh_user_token() { |
||
| 2061 | |||
| 2062 | /** |
||
| 2063 | * Fetches a signed token. |
||
| 2064 | * |
||
| 2065 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens::get_signed_token() instead. |
||
| 2066 | * |
||
| 2067 | * @param object $token the token. |
||
| 2068 | * @return WP_Error|string a signed token |
||
| 2069 | */ |
||
| 2070 | public function get_signed_token( $token ) { |
||
| 2074 | |||
| 2075 | /** |
||
| 2076 | * If connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) |
||
| 2077 | * |
||
| 2078 | * @param array $stats The Heartbeat stats array. |
||
| 2079 | * @return array $stats |
||
| 2080 | */ |
||
| 2081 | public function add_stats_to_heartbeat( $stats ) { |
||
| 2096 | } |
||
| 2097 |
This check looks for
@paramannotations 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.