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 Jetpack_CLI 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 Jetpack_CLI, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class Jetpack_CLI extends WP_CLI_Command { |
||
| 9 | // Aesthetics |
||
| 10 | public $green_open = "\033[32m"; |
||
| 11 | public $red_open = "\033[31m"; |
||
| 12 | public $yellow_open = "\033[33m"; |
||
| 13 | public $color_close = "\033[0m"; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Get Jetpack Details |
||
| 17 | * |
||
| 18 | * ## OPTIONS |
||
| 19 | * |
||
| 20 | * empty: Leave it empty for basic stats |
||
| 21 | * |
||
| 22 | * full: View full stats. It's the data from the heartbeat |
||
| 23 | * |
||
| 24 | * ## EXAMPLES |
||
| 25 | * |
||
| 26 | * wp jetpack status |
||
| 27 | * wp jetpack status full |
||
| 28 | * |
||
| 29 | */ |
||
| 30 | public function status( $args, $assoc_args ) { |
||
| 31 | require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-debugger.php' ); |
||
| 32 | |||
| 33 | WP_CLI::line( sprintf( __( 'Checking status for %s', 'jetpack' ), esc_url( get_home_url() ) ) ); |
||
| 34 | |||
| 35 | if ( ! Jetpack::is_active() ) { |
||
| 36 | WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) ); |
||
| 37 | } |
||
| 38 | |||
| 39 | View Code Duplication | if ( isset( $args[0] ) && 'full' !== $args[0] ) { |
|
| 40 | /* translators: %s is a command like "prompt" */ |
||
| 41 | WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $args[0] ) ); |
||
| 42 | } |
||
| 43 | |||
| 44 | $master_user_email = Jetpack::get_master_user_email(); |
||
| 45 | |||
| 46 | $jetpack_self_test = Jetpack_Debugger::run_self_test(); // Performs the same tests as jetpack.com/support/debug/ |
||
| 47 | |||
| 48 | if ( ! $jetpack_self_test || ! wp_remote_retrieve_response_code( $jetpack_self_test ) ) { |
||
| 49 | WP_CLI::error( __( 'Jetpack connection status unknown.', 'jetpack' ) ); |
||
| 50 | } else if ( 200 == wp_remote_retrieve_response_code( $jetpack_self_test ) ) { |
||
| 51 | WP_CLI::success( __( 'Jetpack is currently connected to WordPress.com', 'jetpack' ) ); |
||
| 52 | } else { |
||
| 53 | WP_CLI::error( __( 'Jetpack connection is broken.', 'jetpack' ) ); |
||
| 54 | } |
||
| 55 | |||
| 56 | WP_CLI::line( sprintf( __( 'The Jetpack Version is %s', 'jetpack' ), JETPACK__VERSION ) ); |
||
| 57 | WP_CLI::line( sprintf( __( 'The WordPress.com blog_id is %d', 'jetpack' ), Jetpack_Options::get_option( 'id' ) ) ); |
||
| 58 | WP_CLI::line( sprintf( __( 'The WordPress.com account for the primary connection is %s', 'jetpack' ), $master_user_email ) ); |
||
| 59 | |||
| 60 | /* |
||
| 61 | * Are they asking for all data? |
||
| 62 | * |
||
| 63 | * Loop through heartbeat data and organize by priority. |
||
| 64 | */ |
||
| 65 | $all_data = ( isset( $args[0] ) && 'full' == $args[0] ) ? 'full' : false; |
||
| 66 | if ( $all_data ) { |
||
|
|
|||
| 67 | // Heartbeat data |
||
| 68 | WP_CLI::line( "\n" . __( 'Additional data: ', 'jetpack' ) ); |
||
| 69 | |||
| 70 | // Get the filtered heartbeat data. |
||
| 71 | // Filtered so we can color/list by severity |
||
| 72 | $stats = Jetpack::jetpack_check_heartbeat_data(); |
||
| 73 | |||
| 74 | // Display red flags first |
||
| 75 | foreach ( $stats['bad'] as $stat => $value ) { |
||
| 76 | printf( "$this->red_open%-'.16s %s $this->color_close\n", $stat, $value ); |
||
| 77 | } |
||
| 78 | |||
| 79 | // Display caution warnings next |
||
| 80 | foreach ( $stats['caution'] as $stat => $value ) { |
||
| 81 | printf( "$this->yellow_open%-'.16s %s $this->color_close\n", $stat, $value ); |
||
| 82 | } |
||
| 83 | |||
| 84 | // The rest of the results are good! |
||
| 85 | foreach ( $stats['good'] as $stat => $value ) { |
||
| 86 | |||
| 87 | // Modules should get special spacing for aestetics |
||
| 88 | if ( strpos( $stat, 'odule-' ) ) { |
||
| 89 | printf( "%-'.30s %s\n", $stat, $value ); |
||
| 90 | usleep( 4000 ); // For dramatic effect lolz |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | printf( "%-'.16s %s\n", $stat, $value ); |
||
| 94 | usleep( 4000 ); // For dramatic effect lolz |
||
| 95 | } |
||
| 96 | } else { |
||
| 97 | // Just the basics |
||
| 98 | WP_CLI::line( "\n" . _x( "View full status with 'wp jetpack status full'", '"wp jetpack status full" is a command - do not translate', 'jetpack' ) ); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Tests the active connection |
||
| 104 | * |
||
| 105 | * Does a two-way test to verify that the local site can communicate with remote Jetpack/WP.com servers and that Jetpack/WP.com servers can talk to the local site. |
||
| 106 | * |
||
| 107 | * ## EXAMPLES |
||
| 108 | * |
||
| 109 | * wp jetpack test-connection |
||
| 110 | * |
||
| 111 | * @subcommand test-connection |
||
| 112 | */ |
||
| 113 | public function test_connection( $args, $assoc_args ) { |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Disconnect Jetpack Blogs or Users |
||
| 149 | * |
||
| 150 | * ## OPTIONS |
||
| 151 | * |
||
| 152 | * blog: Disconnect the entire blog. |
||
| 153 | * |
||
| 154 | * user <user_identifier>: Disconnect a specific user from WordPress.com. |
||
| 155 | * |
||
| 156 | * Please note, the primary account that the blog is connected |
||
| 157 | * to WordPress.com with cannot be disconnected without |
||
| 158 | * disconnecting the entire blog. |
||
| 159 | * |
||
| 160 | * ## EXAMPLES |
||
| 161 | * |
||
| 162 | * wp jetpack disconnect blog |
||
| 163 | * wp jetpack disconnect user 13 |
||
| 164 | * wp jetpack disconnect user username |
||
| 165 | * wp jetpack disconnect user [email protected] |
||
| 166 | * |
||
| 167 | * @synopsis <blog|user> [<user_identifier>] |
||
| 168 | */ |
||
| 169 | public function disconnect( $args, $assoc_args ) { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Reset Jetpack options and settings to default |
||
| 227 | * |
||
| 228 | * ## OPTIONS |
||
| 229 | * |
||
| 230 | * modules: Resets modules to default state ( get_default_modules() ) |
||
| 231 | * |
||
| 232 | * options: Resets all Jetpack options except: |
||
| 233 | * - All private options (Blog token, user token, etc...) |
||
| 234 | * - id (The Client ID/WP.com Blog ID of this site) |
||
| 235 | * - master_user |
||
| 236 | * - version |
||
| 237 | * - activated |
||
| 238 | * |
||
| 239 | * ## EXAMPLES |
||
| 240 | * |
||
| 241 | * wp jetpack reset options |
||
| 242 | * wp jetpack reset modules |
||
| 243 | * |
||
| 244 | * @synopsis <modules|options> |
||
| 245 | */ |
||
| 246 | public function reset( $args, $assoc_args ) { |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Manage Jetpack Modules |
||
| 307 | * |
||
| 308 | * ## OPTIONS |
||
| 309 | * |
||
| 310 | * <list|activate|deactivate|toggle> |
||
| 311 | * : The action to take. |
||
| 312 | * --- |
||
| 313 | * default: list |
||
| 314 | * options: |
||
| 315 | * - list |
||
| 316 | * - activate |
||
| 317 | * - deactivate |
||
| 318 | * - toggle |
||
| 319 | * --- |
||
| 320 | * |
||
| 321 | * [<module_slug>] |
||
| 322 | * : The slug of the module to perform an action on. |
||
| 323 | * |
||
| 324 | * [--format=<format>] |
||
| 325 | * : Allows overriding the output of the command when listing modules. |
||
| 326 | * --- |
||
| 327 | * default: table |
||
| 328 | * options: |
||
| 329 | * - table |
||
| 330 | * - json |
||
| 331 | * - csv |
||
| 332 | * - yaml |
||
| 333 | * - ids |
||
| 334 | * - count |
||
| 335 | * --- |
||
| 336 | * |
||
| 337 | * ## EXAMPLES |
||
| 338 | * |
||
| 339 | * wp jetpack module list |
||
| 340 | * wp jetpack module list --format=json |
||
| 341 | * wp jetpack module activate stats |
||
| 342 | * wp jetpack module deactivate stats |
||
| 343 | * wp jetpack module toggle stats |
||
| 344 | * wp jetpack module activate all |
||
| 345 | * wp jetpack module deactivate all |
||
| 346 | */ |
||
| 347 | public function module( $args, $assoc_args ) { |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Manage Protect Settings |
||
| 421 | * |
||
| 422 | * ## OPTIONS |
||
| 423 | * |
||
| 424 | * whitelist: Whitelist an IP address. You can also read or clear the whitelist. |
||
| 425 | * |
||
| 426 | * |
||
| 427 | * ## EXAMPLES |
||
| 428 | * |
||
| 429 | * wp jetpack protect whitelist <ip address> |
||
| 430 | * wp jetpack protect whitelist list |
||
| 431 | * wp jetpack protect whitelist clear |
||
| 432 | * |
||
| 433 | * @synopsis <whitelist> [<ip|ip_low-ip_high|list|clear>] |
||
| 434 | */ |
||
| 435 | public function protect( $args, $assoc_args ) { |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Manage Jetpack Options |
||
| 542 | * |
||
| 543 | * ## OPTIONS |
||
| 544 | * |
||
| 545 | * list : List all jetpack options and their values |
||
| 546 | * delete : Delete an option |
||
| 547 | * - can only delete options that are white listed. |
||
| 548 | * update : update an option |
||
| 549 | * - can only update option strings |
||
| 550 | * get : get the value of an option |
||
| 551 | * |
||
| 552 | * ## EXAMPLES |
||
| 553 | * |
||
| 554 | * wp jetpack options list |
||
| 555 | * wp jetpack options get <option_name> |
||
| 556 | * wp jetpack options delete <option_name> |
||
| 557 | * wp jetpack options update <option_name> [<option_value>] |
||
| 558 | * |
||
| 559 | * @synopsis <list|get|delete|update> [<option_name>] [<option_value>] |
||
| 560 | */ |
||
| 561 | public function options( $args, $assoc_args ) { |
||
| 562 | $action = isset( $args[0] ) ? $args[0] : 'list'; |
||
| 563 | $safe_to_modify = Jetpack_Options::get_options_for_reset(); |
||
| 564 | |||
| 565 | // Jumpstart is special |
||
| 566 | array_push( $safe_to_modify, 'jumpstart' ); |
||
| 567 | |||
| 568 | // Is the option flagged as unsafe? |
||
| 569 | $flagged = ! in_array( $args[1], $safe_to_modify ); |
||
| 570 | |||
| 571 | View Code Duplication | if ( ! in_array( $action, array( 'list', 'get', 'delete', 'update' ) ) ) { |
|
| 572 | /* translators: %s is a command like "prompt" */ |
||
| 573 | WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) ); |
||
| 574 | } |
||
| 575 | |||
| 576 | if ( isset( $args[0] ) ) { |
||
| 577 | if ( 'get' == $args[0] && isset( $args[1] ) ) { |
||
| 578 | $action = 'get'; |
||
| 579 | } else if ( 'delete' == $args[0] && isset( $args[1] ) ) { |
||
| 580 | $action = 'delete'; |
||
| 581 | View Code Duplication | } else if ( 'update' == $args[0] && isset( $args[1] ) ) { |
|
| 582 | $action = 'update'; |
||
| 583 | } else { |
||
| 584 | $action = 'list'; |
||
| 585 | } |
||
| 586 | } |
||
| 587 | |||
| 588 | // Bail if the option isn't found |
||
| 589 | $option = isset( $args[1] ) ? Jetpack_Options::get_option( $args[1] ) : false; |
||
| 590 | View Code Duplication | if ( isset( $args[1] ) && ! $option && 'update' !== $args[0] ) { |
|
| 591 | WP_CLI::error( __( 'Option not found or is empty. Use "list" to list option names', 'jetpack' ) ); |
||
| 592 | } |
||
| 593 | |||
| 594 | // Let's print_r the option if it's an array |
||
| 595 | // Used in the 'get' and 'list' actions |
||
| 596 | $option = is_array( $option ) ? print_r( $option ) : $option; |
||
| 597 | |||
| 598 | switch ( $action ) { |
||
| 599 | case 'get': |
||
| 600 | WP_CLI::success( "\t" . $option ); |
||
| 601 | break; |
||
| 602 | case 'delete': |
||
| 603 | jetpack_cli_are_you_sure( $flagged ); |
||
| 604 | |||
| 605 | Jetpack_Options::delete_option( $args[1] ); |
||
| 606 | WP_CLI::success( sprintf( __( 'Deleted option: %s', 'jetpack' ), $args[1] ) ); |
||
| 607 | break; |
||
| 608 | case 'update': |
||
| 609 | jetpack_cli_are_you_sure( $flagged ); |
||
| 610 | |||
| 611 | // Updating arrays would get pretty tricky... |
||
| 612 | $value = Jetpack_Options::get_option( $args[1] ); |
||
| 613 | if ( $value && is_array( $value ) ) { |
||
| 614 | WP_CLI::error( __( 'Sorry, no updating arrays at this time', 'jetpack' ) ); |
||
| 615 | } |
||
| 616 | |||
| 617 | Jetpack_Options::update_option( $args[1], $args[2] ); |
||
| 618 | WP_CLI::success( sprintf( _x( 'Updated option: %s to "%s"', 'Updating an option from "this" to "that".', 'jetpack' ), $args[1], $args[2] ) ); |
||
| 619 | break; |
||
| 620 | case 'list': |
||
| 621 | $options_compact = Jetpack_Options::get_option_names(); |
||
| 622 | $options_non_compact = Jetpack_Options::get_option_names( 'non_compact' ); |
||
| 623 | $options_private = Jetpack_Options::get_option_names( 'private' ); |
||
| 624 | $options = array_merge( $options_compact, $options_non_compact, $options_private ); |
||
| 625 | |||
| 626 | // Table headers |
||
| 627 | WP_CLI::line( "\t" . str_pad( __( 'Option', 'jetpack' ), 30 ) . __( 'Value', 'jetpack' ) ); |
||
| 628 | |||
| 629 | // List out the options and their values |
||
| 630 | // Tell them if the value is empty or not |
||
| 631 | // Tell them if it's an array |
||
| 632 | foreach ( $options as $option ) { |
||
| 633 | $value = Jetpack_Options::get_option( $option ); |
||
| 634 | if ( ! $value ) { |
||
| 635 | WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Empty' ); |
||
| 636 | continue; |
||
| 637 | } |
||
| 638 | |||
| 639 | if ( ! is_array( $value ) ) { |
||
| 640 | WP_CLI::line( "\t" . str_pad( $option, 30 ) . $value ); |
||
| 641 | } else if ( is_array( $value ) ) { |
||
| 642 | WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Array - Use "get <option>" to read option array.' ); |
||
| 643 | } |
||
| 644 | } |
||
| 645 | $option_text = '{' . _x( 'option', 'a variable command that a user can write, provided in the printed instructions', 'jetpack' ) . '}'; |
||
| 646 | $value_text = '{' . _x( 'value', 'the value that they want to update the option to', 'jetpack' ) . '}'; |
||
| 647 | |||
| 648 | WP_CLI::success( |
||
| 649 | _x( "Above are your options. You may 'get', 'delete', and 'update' them.", "'get', 'delete', and 'update' are commands - do not translate.", 'jetpack' ) . "\n" . |
||
| 650 | str_pad( 'wp jetpack options get', 26 ) . $option_text . "\n" . |
||
| 651 | str_pad( 'wp jetpack options delete', 26 ) . $option_text . "\n" . |
||
| 652 | str_pad( 'wp jetpack options update', 26 ) . "$option_text $value_text" . "\n" . |
||
| 653 | _x( "Type 'wp jetpack options' for more info.", "'wp jetpack options' is a command - do not translate.", 'jetpack' ) . "\n" |
||
| 654 | ); |
||
| 655 | break; |
||
| 656 | } |
||
| 657 | } |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Get the status of or start a new Jetpack sync. |
||
| 661 | * |
||
| 662 | * ## OPTIONS |
||
| 663 | * |
||
| 664 | * status : Print the current sync status |
||
| 665 | * start : Start a full sync from this site to WordPress.com |
||
| 666 | * |
||
| 667 | * ## EXAMPLES |
||
| 668 | * |
||
| 669 | * wp jetpack sync status |
||
| 670 | * wp jetpack sync start --modules=functions --sync_wait_time=5 |
||
| 671 | * |
||
| 672 | * @synopsis <status|start> [--<field>=<value>] |
||
| 673 | */ |
||
| 674 | public function sync( $args, $assoc_args ) { |
||
| 783 | |||
| 784 | /** |
||
| 785 | * List the contents of a specific Jetpack sync queue. |
||
| 786 | * |
||
| 787 | * ## OPTIONS |
||
| 788 | * |
||
| 789 | * peek : List the 100 front-most items on the queue. |
||
| 790 | * |
||
| 791 | * ## EXAMPLES |
||
| 792 | * |
||
| 793 | * wp jetpack sync_queue full_sync peek |
||
| 794 | * |
||
| 795 | * @synopsis <incremental|full_sync> <peek> |
||
| 796 | */ |
||
| 797 | public function sync_queue( $args, $assoc_args ) { |
||
| 848 | |||
| 849 | /** |
||
| 850 | * Cancel's the current Jetpack plan granted by this partner, if applicable |
||
| 851 | * |
||
| 852 | * Returns success or error JSON |
||
| 853 | * |
||
| 854 | * <token_json> |
||
| 855 | * : JSON blob of WPCOM API token |
||
| 856 | * [--partner_tracking_id=<partner_tracking_id>] |
||
| 857 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
| 858 | * |
||
| 859 | * * @synopsis <token_json> [--partner_tracking_id=<partner_tracking_id>] |
||
| 860 | */ |
||
| 861 | public function partner_cancel( $args, $named_args ) { |
||
| 913 | |||
| 914 | /** |
||
| 915 | * Provision a site using a Jetpack Partner license |
||
| 916 | * |
||
| 917 | * Returns JSON blob |
||
| 918 | * |
||
| 919 | * ## OPTIONS |
||
| 920 | * |
||
| 921 | * <token_json> |
||
| 922 | * : JSON blob of WPCOM API token |
||
| 923 | * [--plan=<plan_name>] |
||
| 924 | * : Slug of the requested plan, e.g. premium |
||
| 925 | * [--wpcom_user_id=<user_id>] |
||
| 926 | * : WordPress.com ID of user to connect as (must be whitelisted against partner key) |
||
| 927 | * [--wpcom_user_email=<wpcom_user_email>] |
||
| 928 | * : Override the email we send to WordPress.com for registration |
||
| 929 | * [--onboarding=<onboarding>] |
||
| 930 | * : Guide the user through an onboarding wizard |
||
| 931 | * [--force_register=<register>] |
||
| 932 | * : Whether to force a site to register |
||
| 933 | * [--force_connect=<force_connect>] |
||
| 934 | * : Force JPS to not reuse existing credentials |
||
| 935 | * [--home_url=<home_url>] |
||
| 936 | * : Overrides the home option via the home_url filter, or the WP_HOME constant |
||
| 937 | * [--site_url=<site_url>] |
||
| 938 | * : Overrides the siteurl option via the site_url filter, or the WP_SITEURL constant |
||
| 939 | * [--partner_tracking_id=<partner_tracking_id>] |
||
| 940 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
| 941 | * |
||
| 942 | * ## EXAMPLES |
||
| 943 | * |
||
| 944 | * $ wp jetpack partner_provision '{ some: "json" }' premium 1 |
||
| 945 | * { success: true } |
||
| 946 | * |
||
| 947 | * @synopsis <token_json> [--wpcom_user_id=<user_id>] [--plan=<plan_name>] [--onboarding=<onboarding>] [--force_register=<register>] [--force_connect=<force_connect>] [--home_url=<home_url>] [--site_url=<site_url>] [--wpcom_user_email=<wpcom_user_email>] [--partner_tracking_id=<partner_tracking_id>] |
||
| 948 | */ |
||
| 949 | public function partner_provision( $args, $named_args ) { |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Manages your Jetpack sitemap |
||
| 985 | * |
||
| 986 | * ## OPTIONS |
||
| 987 | * |
||
| 988 | * rebuild : Rebuild all sitemaps |
||
| 989 | * --purge : if set, will remove all existing sitemap data before rebuilding |
||
| 990 | * |
||
| 991 | * ## EXAMPLES |
||
| 992 | * |
||
| 993 | * wp jetpack sitemap rebuild |
||
| 994 | * |
||
| 995 | * @subcommand sitemap |
||
| 996 | * @synopsis <rebuild> [--purge] |
||
| 997 | */ |
||
| 998 | public function sitemap( $args, $assoc_args ) { |
||
| 1017 | |||
| 1018 | /** |
||
| 1019 | * Allows authorizing a user via the command line and will activate |
||
| 1020 | * |
||
| 1021 | * ## EXAMPLES |
||
| 1022 | * |
||
| 1023 | * wp jetpack authorize_user --token=123456789abcdef |
||
| 1024 | * |
||
| 1025 | * @synopsis --token=<value> |
||
| 1026 | */ |
||
| 1027 | public function authorize_user( $args, $named_args ) { |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Allows calling a WordPress.com API endpoint using the current blog's token. |
||
| 1066 | * |
||
| 1067 | * ## OPTIONS |
||
| 1068 | * --resource=<resource> |
||
| 1069 | * : The resource to call with the current blog's token, where `%d` represents the current blog's ID. |
||
| 1070 | * |
||
| 1071 | * [--api_version=<api_version>] |
||
| 1072 | * : The API version to query against. |
||
| 1073 | * |
||
| 1074 | * [--base_api_path=<base_api_path>] |
||
| 1075 | * : The base API path to query. |
||
| 1076 | * --- |
||
| 1077 | * default: rest |
||
| 1078 | * --- |
||
| 1079 | * |
||
| 1080 | * [--body=<body>] |
||
| 1081 | * : A JSON encoded string representing arguments to send in the body. |
||
| 1082 | * |
||
| 1083 | * [--field=<value>] |
||
| 1084 | * : Any number of arguments that should be passed to the resource. |
||
| 1085 | * |
||
| 1086 | * [--pretty] |
||
| 1087 | * : Will pretty print the results of a successful API call. |
||
| 1088 | * |
||
| 1089 | * [--strip-success] |
||
| 1090 | * : Will remove the green success label from successful API calls. |
||
| 1091 | * |
||
| 1092 | * ## EXAMPLES |
||
| 1093 | * |
||
| 1094 | * wp jetpack call_api --resource='/sites/%d' |
||
| 1095 | */ |
||
| 1096 | public function call_api( $args, $named_args ) { |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * API wrapper for getting stats from the WordPress.com API for the current site. |
||
| 1165 | * |
||
| 1166 | * ## OPTIONS |
||
| 1167 | * |
||
| 1168 | * [--quantity=<quantity>] |
||
| 1169 | * : The number of units to include. |
||
| 1170 | * --- |
||
| 1171 | * default: 30 |
||
| 1172 | * --- |
||
| 1173 | * |
||
| 1174 | * [--period=<period>] |
||
| 1175 | * : The unit of time to query stats for. |
||
| 1176 | * --- |
||
| 1177 | * default: day |
||
| 1178 | * options: |
||
| 1179 | * - day |
||
| 1180 | * - week |
||
| 1181 | * - month |
||
| 1182 | * - year |
||
| 1183 | * --- |
||
| 1184 | * |
||
| 1185 | * [--date=<date>] |
||
| 1186 | * : The latest date to return stats for. Ex. - 2018-01-01. |
||
| 1187 | * |
||
| 1188 | * [--pretty] |
||
| 1189 | * : Will pretty print the results of a successful API call. |
||
| 1190 | * |
||
| 1191 | * [--strip-success] |
||
| 1192 | * : Will remove the green success label from successful API calls. |
||
| 1193 | * |
||
| 1194 | * ## EXAMPLES |
||
| 1195 | * |
||
| 1196 | * wp jetpack get_stats |
||
| 1197 | */ |
||
| 1198 | public function get_stats( $args, $named_args ) { |
||
| 1231 | |||
| 1232 | /* |
||
| 1233 | * Allows management of publicize connections. |
||
| 1234 | * |
||
| 1235 | * ## OPTIONS |
||
| 1236 | * |
||
| 1237 | * <list|disconnect> |
||
| 1238 | * : The action to perform. |
||
| 1239 | * --- |
||
| 1240 | * options: |
||
| 1241 | * - list |
||
| 1242 | * - disconnect |
||
| 1243 | * --- |
||
| 1244 | * |
||
| 1245 | * [<identifier>] |
||
| 1246 | * : The connection ID or service to perform an action on. |
||
| 1247 | * |
||
| 1248 | * [--format=<format>] |
||
| 1249 | * : Allows overriding the output of the command when listing connections. |
||
| 1250 | * --- |
||
| 1251 | * default: table |
||
| 1252 | * options: |
||
| 1253 | * - table |
||
| 1254 | * - json |
||
| 1255 | * - csv |
||
| 1256 | * - yaml |
||
| 1257 | * - ids |
||
| 1258 | * - count |
||
| 1259 | * --- |
||
| 1260 | * |
||
| 1261 | * ## EXAMPLES |
||
| 1262 | * |
||
| 1263 | * wp jetpack publicize list |
||
| 1264 | * wp jetpack publicize list twitter |
||
| 1265 | * wp --user=1 jetpack publicize list |
||
| 1266 | * wp --user=1 jetpack publicize list twitter |
||
| 1267 | * wp jetpack publicize list 123456 |
||
| 1268 | * wp jetpack publicize disconnect 123456 |
||
| 1269 | * wp jetpack publicize disconnect all |
||
| 1270 | * wp jetpack publicize disconnect twitter |
||
| 1271 | */ |
||
| 1272 | public function publicize( $args, $named_args ) { |
||
| 1411 | |||
| 1412 | private function get_api_host() { |
||
| 1416 | |||
| 1417 | private function partner_provision_error( $error ) { |
||
| 1425 | } |
||
| 1426 | |||
| 1427 | /* |
||
| 1463 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: