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 | |||
| 10 | // Aesthetics |
||
| 11 | public $green_open = "\033[32m"; |
||
| 12 | public $red_open = "\033[31m"; |
||
| 13 | public $yellow_open = "\033[33m"; |
||
| 14 | public $color_close = "\033[0m"; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Get Jetpack Details |
||
| 18 | * |
||
| 19 | * ## OPTIONS |
||
| 20 | * |
||
| 21 | * empty: Leave it empty for basic stats |
||
| 22 | * |
||
| 23 | * full: View full stats. It's the data from the heartbeat |
||
| 24 | * |
||
| 25 | * ## EXAMPLES |
||
| 26 | * |
||
| 27 | * wp jetpack status |
||
| 28 | * wp jetpack status full |
||
| 29 | * |
||
| 30 | */ |
||
| 31 | public function status( $args, $assoc_args ) { |
||
| 32 | |||
| 33 | WP_CLI::line( sprintf( __( 'Checking status for %s', 'jetpack' ), esc_url( get_site_url() ) ) ); |
||
| 34 | |||
| 35 | if ( ! Jetpack::is_active() ) { |
||
| 36 | WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) ); |
||
| 37 | } |
||
| 38 | |||
| 39 | 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 | /* |
||
| 47 | * Are they asking for all data? |
||
| 48 | * |
||
| 49 | * Loop through heartbeat data and organize by priority. |
||
| 50 | */ |
||
| 51 | $all_data = ( isset( $args[0] ) && 'full' == $args[0] ) ? 'full' : false; |
||
| 52 | if ( $all_data ) { |
||
|
|
|||
| 53 | WP_CLI::success( __( 'Jetpack is currently connected to WordPress.com', 'jetpack' ) ); |
||
| 54 | WP_CLI::line( sprintf( __( "The Jetpack Version is %s", 'jetpack' ), JETPACK__VERSION ) ); |
||
| 55 | WP_CLI::line( sprintf( __( "The WordPress.com blog_id is %d", 'jetpack' ), Jetpack_Options::get_option( 'id' ) ) ); |
||
| 56 | WP_CLI::line( sprintf( __( 'The WordPress.com account for the primary connection is %s', 'jetpack' ), $master_user_email ) ); |
||
| 57 | |||
| 58 | // Heartbeat data |
||
| 59 | WP_CLI::line( "\n" . __( 'Additional data: ', 'jetpack' ) ); |
||
| 60 | |||
| 61 | // Get the filtered heartbeat data. |
||
| 62 | // Filtered so we can color/list by severity |
||
| 63 | $stats = Jetpack::jetpack_check_heartbeat_data(); |
||
| 64 | |||
| 65 | // Display red flags first |
||
| 66 | foreach ( $stats['bad'] as $stat => $value ) { |
||
| 67 | printf( "$this->red_open%-'.16s %s $this->color_close\n", $stat, $value ); |
||
| 68 | } |
||
| 69 | |||
| 70 | // Display caution warnings next |
||
| 71 | foreach ( $stats['caution'] as $stat => $value ) { |
||
| 72 | printf( "$this->yellow_open%-'.16s %s $this->color_close\n", $stat, $value ); |
||
| 73 | } |
||
| 74 | |||
| 75 | // The rest of the results are good! |
||
| 76 | foreach ( $stats['good'] as $stat => $value ) { |
||
| 77 | |||
| 78 | // Modules should get special spacing for aestetics |
||
| 79 | if ( strpos( $stat, 'odule-' ) ) { |
||
| 80 | printf( "%-'.30s %s\n", $stat, $value ); |
||
| 81 | usleep( 4000 ); // For dramatic effect lolz |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | printf( "%-'.16s %s\n", $stat, $value ); |
||
| 85 | usleep( 4000 ); // For dramatic effect lolz |
||
| 86 | } |
||
| 87 | } else { |
||
| 88 | // Just the basics |
||
| 89 | WP_CLI::success( __( 'Jetpack is currently connected to WordPress.com', 'jetpack' ) ); |
||
| 90 | WP_CLI::line( sprintf( __( 'The Jetpack Version is %s', 'jetpack' ), JETPACK__VERSION ) ); |
||
| 91 | WP_CLI::line( sprintf( __( 'The WordPress.com blog_id is %d', 'jetpack' ), Jetpack_Options::get_option( 'id' ) ) ); |
||
| 92 | WP_CLI::line( sprintf( __( 'The WordPress.com account for the primary connection is %s', 'jetpack' ), $master_user_email ) ); |
||
| 93 | WP_CLI::line( "\n" . _x( "View full status with 'wp jetpack status full'", '"wp jetpack status full" is a command - do not translate', 'jetpack' ) ); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Tests the active connection |
||
| 99 | * |
||
| 100 | * 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. |
||
| 101 | * |
||
| 102 | * ## EXAMPLES |
||
| 103 | * |
||
| 104 | * wp jetpack test-connection |
||
| 105 | * |
||
| 106 | * @subcommand test-connection |
||
| 107 | */ |
||
| 108 | public function test_connection( $args, $assoc_args ) { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Disconnect Jetpack Blogs or Users |
||
| 144 | * |
||
| 145 | * ## OPTIONS |
||
| 146 | * |
||
| 147 | * blog: Disconnect the entire blog. |
||
| 148 | * |
||
| 149 | * user <user_identifier>: Disconnect a specific user from WordPress.com. |
||
| 150 | * |
||
| 151 | * Please note, the primary account that the blog is connected |
||
| 152 | * to WordPress.com with cannot be disconnected without |
||
| 153 | * disconnecting the entire blog. |
||
| 154 | * |
||
| 155 | * ## EXAMPLES |
||
| 156 | * |
||
| 157 | * wp jetpack disconnect blog |
||
| 158 | * wp jetpack disconnect user 13 |
||
| 159 | * wp jetpack disconnect user username |
||
| 160 | * wp jetpack disconnect user [email protected] |
||
| 161 | * |
||
| 162 | * @synopsis <blog|user> [<user_identifier>] |
||
| 163 | */ |
||
| 164 | public function disconnect( $args, $assoc_args ) { |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Reset Jetpack options and settings to default |
||
| 222 | * |
||
| 223 | * ## OPTIONS |
||
| 224 | * |
||
| 225 | * modules: Resets modules to default state ( get_default_modules() ) |
||
| 226 | * |
||
| 227 | * options: Resets all Jetpack options except: |
||
| 228 | * - All private options (Blog token, user token, etc...) |
||
| 229 | * - id (The Client ID/WP.com Blog ID of this site) |
||
| 230 | * - master_user |
||
| 231 | * - version |
||
| 232 | * - activated |
||
| 233 | * |
||
| 234 | * ## EXAMPLES |
||
| 235 | * |
||
| 236 | * wp jetpack reset options |
||
| 237 | * wp jetpack reset modules |
||
| 238 | * |
||
| 239 | * @synopsis <modules|options> |
||
| 240 | */ |
||
| 241 | public function reset( $args, $assoc_args ) { |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Manage Jetpack Modules |
||
| 302 | * |
||
| 303 | * ## OPTIONS |
||
| 304 | * |
||
| 305 | * list : View all available modules, and their status. |
||
| 306 | * activate all : Activate all modules |
||
| 307 | * deactivate all: Deactivate all modules |
||
| 308 | * |
||
| 309 | * activate <module_slug> : Activate a module. |
||
| 310 | * deactivate <module_slug> : Deactivate a module. |
||
| 311 | * toggle <module_slug> : Toggle a module on or off. |
||
| 312 | * |
||
| 313 | * ## EXAMPLES |
||
| 314 | * |
||
| 315 | * wp jetpack module list |
||
| 316 | * wp jetpack module activate stats |
||
| 317 | * wp jetpack module deactivate stats |
||
| 318 | * wp jetpack module toggle stats |
||
| 319 | * |
||
| 320 | * wp jetpack module activate all |
||
| 321 | * wp jetpack module deactivate all |
||
| 322 | * |
||
| 323 | * @synopsis <list|activate|deactivate|toggle> [<module_name>] |
||
| 324 | */ |
||
| 325 | public function module( $args, $assoc_args ) { |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Manage Protect Settings |
||
| 391 | * |
||
| 392 | * ## OPTIONS |
||
| 393 | * |
||
| 394 | * whitelist: Whitelist an IP address. You can also read or clear the whitelist. |
||
| 395 | * |
||
| 396 | * |
||
| 397 | * ## EXAMPLES |
||
| 398 | * |
||
| 399 | * wp jetpack protect whitelist <ip address> |
||
| 400 | * wp jetpack protect whitelist list |
||
| 401 | * wp jetpack protect whitelist clear |
||
| 402 | * |
||
| 403 | * @synopsis <whitelist> [<ip|ip_low-ip_high|list|clear>] |
||
| 404 | */ |
||
| 405 | public function protect( $args, $assoc_args ) { |
||
| 406 | $action = isset( $args[0] ) ? $args[0] : 'prompt'; |
||
| 407 | if ( ! in_array( $action, array( 'whitelist' ) ) ) { |
||
| 408 | /* translators: %s is a command like "prompt" */ |
||
| 409 | WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) ); |
||
| 410 | } |
||
| 411 | // Check if module is active |
||
| 412 | if ( ! Jetpack::is_module_active( __FUNCTION__ ) ) { |
||
| 413 | WP_CLI::error( sprintf( _x( '%s is not active. You can activate it with "wp jetpack module activate %s"', '"wp jetpack module activate" is a command - do not translate', 'jetpack' ), __FUNCTION__, __FUNCTION__ ) ); |
||
| 414 | } |
||
| 415 | if ( in_array( $action, array( 'whitelist' ) ) ) { |
||
| 416 | if ( isset( $args[1] ) ) { |
||
| 417 | $action = 'whitelist'; |
||
| 418 | } else { |
||
| 419 | $action = 'prompt'; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | switch ( $action ) { |
||
| 423 | case 'whitelist': |
||
| 424 | $whitelist = array(); |
||
| 425 | $new_ip = $args[1]; |
||
| 426 | $current_whitelist = get_site_option( 'jetpack_protect_whitelist', array() ); |
||
| 427 | |||
| 428 | // Build array of IPs that are already whitelisted. |
||
| 429 | // Re-build manually instead of using jetpack_protect_format_whitelist() so we can easily get |
||
| 430 | // low & high range params for jetpack_protect_ip_address_is_in_range(); |
||
| 431 | foreach( $current_whitelist as $whitelisted ) { |
||
| 432 | |||
| 433 | // IP ranges |
||
| 434 | if ( $whitelisted->range ) { |
||
| 435 | |||
| 436 | // Is it already whitelisted? |
||
| 437 | if ( jetpack_protect_ip_address_is_in_range( $new_ip, $whitelisted->range_low, $whitelisted->range_high ) ) { |
||
| 438 | /* translators: %s is an IP address */ |
||
| 439 | WP_CLI::error( sprintf( __( '%s has already been whitelisted', 'jetpack' ), $new_ip ) ); |
||
| 440 | break; |
||
| 441 | } |
||
| 442 | $whitelist[] = $whitelisted->range_low . " - " . $whitelisted->range_high; |
||
| 443 | |||
| 444 | } else { // Individual IPs |
||
| 445 | |||
| 446 | // Check if the IP is already whitelisted (single IP only) |
||
| 447 | if ( $new_ip == $whitelisted->ip_address ) { |
||
| 448 | /* translators: %s is an IP address */ |
||
| 449 | WP_CLI::error( sprintf( __( '%s has already been whitelisted', 'jetpack' ), $new_ip ) ); |
||
| 450 | break; |
||
| 451 | } |
||
| 452 | $whitelist[] = $whitelisted->ip_address; |
||
| 453 | |||
| 454 | } |
||
| 455 | } |
||
| 456 | |||
| 457 | /* |
||
| 458 | * List the whitelist |
||
| 459 | * Done here because it's easier to read the $whitelist array after it's been rebuilt |
||
| 460 | */ |
||
| 461 | if ( isset( $args[1] ) && 'list' == $args[1] ) { |
||
| 462 | View Code Duplication | if ( ! empty( $whitelist ) ) { |
|
| 463 | WP_CLI::success( __( 'Here are your whitelisted IPs:', 'jetpack' ) ); |
||
| 464 | foreach ( $whitelist as $ip ) { |
||
| 465 | WP_CLI::line( "\t" . str_pad( $ip, 24 ) ) ; |
||
| 466 | } |
||
| 467 | } else { |
||
| 468 | WP_CLI::line( __( 'Whitelist is empty.', "jetpack" ) ) ; |
||
| 469 | } |
||
| 470 | break; |
||
| 471 | } |
||
| 472 | |||
| 473 | /* |
||
| 474 | * Clear the whitelist |
||
| 475 | */ |
||
| 476 | if ( isset( $args[1] ) && 'clear' == $args[1] ) { |
||
| 477 | if ( ! empty( $whitelist ) ) { |
||
| 478 | $whitelist = array(); |
||
| 479 | jetpack_protect_save_whitelist( $whitelist ); |
||
| 480 | WP_CLI::success( __( 'Cleared all whitelisted IPs', 'jetpack' ) ); |
||
| 481 | } else { |
||
| 482 | WP_CLI::line( __( 'Whitelist is empty.', "jetpack" ) ) ; |
||
| 483 | } |
||
| 484 | break; |
||
| 485 | } |
||
| 486 | |||
| 487 | // Append new IP to whitelist array |
||
| 488 | array_push( $whitelist, $new_ip ); |
||
| 489 | |||
| 490 | // Save whitelist if there are no errors |
||
| 491 | $result = jetpack_protect_save_whitelist( $whitelist ); |
||
| 492 | if ( is_wp_error( $result ) ) { |
||
| 493 | WP_CLI::error( __( $result, 'jetpack' ) ); |
||
| 494 | } |
||
| 495 | |||
| 496 | /* translators: %s is an IP address */ |
||
| 497 | WP_CLI::success( sprintf( __( '%s has been whitelisted.', 'jetpack' ), $new_ip ) ); |
||
| 498 | break; |
||
| 499 | case 'prompt': |
||
| 500 | WP_CLI::error( |
||
| 501 | __( 'No command found.', 'jetpack' ) . "\n" . |
||
| 502 | __( 'Please enter the IP address you want to whitelist.', 'jetpack' ) . "\n" . |
||
| 503 | _x( 'You can save a range of IPs {low_range}-{high_range}. No spaces allowed. (example: 1.1.1.1-2.2.2.2)', 'Instructions on how to whitelist IP ranges - low_range/high_range should be translated.', 'jetpack' ) . "\n" . |
||
| 504 | _x( "You can also 'list' or 'clear' the whitelist.", "'list' and 'clear' are commands and should not be translated", 'jetpack' ) . "\n" |
||
| 505 | ); |
||
| 506 | break; |
||
| 507 | } |
||
| 508 | } |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Manage Jetpack Options |
||
| 512 | * |
||
| 513 | * ## OPTIONS |
||
| 514 | * |
||
| 515 | * list : List all jetpack options and their values |
||
| 516 | * delete : Delete an option |
||
| 517 | * - can only delete options that are white listed. |
||
| 518 | * update : update an option |
||
| 519 | * - can only update option strings |
||
| 520 | * get : get the value of an option |
||
| 521 | * |
||
| 522 | * ## EXAMPLES |
||
| 523 | * |
||
| 524 | * wp jetpack options list |
||
| 525 | * wp jetpack options get <option_name> |
||
| 526 | * wp jetpack options delete <option_name> |
||
| 527 | * wp jetpack options update <option_name> [<option_value>] |
||
| 528 | * |
||
| 529 | * @synopsis <list|get|delete|update> [<option_name>] [<option_value>] |
||
| 530 | */ |
||
| 531 | public function options( $args, $assoc_args ) { |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Get the status of or start a new Jetpack sync. |
||
| 631 | * |
||
| 632 | * ## OPTIONS |
||
| 633 | * |
||
| 634 | * status : Print the current sync status |
||
| 635 | * start : Start a full sync from this site to WordPress.com |
||
| 636 | * |
||
| 637 | * ## EXAMPLES |
||
| 638 | * |
||
| 639 | * wp jetpack sync status |
||
| 640 | * wp jetpack sync start --modules=functions --sync_wait_time=5 |
||
| 641 | * |
||
| 642 | * @synopsis <status|start> [--<field>=<value>] |
||
| 643 | */ |
||
| 644 | public function sync( $args, $assoc_args ) { |
||
| 645 | if ( ! Jetpack_Sync_Actions::sync_allowed() ) { |
||
| 646 | WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site.', 'jetpack' ) ); |
||
| 647 | } |
||
| 648 | |||
| 649 | $action = isset( $args[0] ) ? $args[0] : 'status'; |
||
| 650 | |||
| 651 | switch ( $action ) { |
||
| 652 | case 'status': |
||
| 653 | $status = Jetpack_Sync_Actions::get_sync_status(); |
||
| 654 | $collection = array(); |
||
| 655 | foreach ( $status as $key => $item ) { |
||
| 656 | $collection[] = array( |
||
| 657 | 'option' => $key, |
||
| 658 | 'value' => is_scalar( $item ) ? $item : json_encode( $item ) |
||
| 659 | ); |
||
| 660 | } |
||
| 661 | |||
| 662 | WP_CLI\Utils\format_items( 'table', $collection, array( 'option', 'value' ) ); |
||
| 663 | break; |
||
| 664 | case 'start': |
||
| 665 | // Get the original settings so that we can restore them later |
||
| 666 | $original_settings = Jetpack_Sync_Settings::get_settings(); |
||
| 667 | |||
| 668 | // Initialize sync settigns so we can sync as quickly as possible |
||
| 669 | $sync_settings = wp_parse_args( |
||
| 670 | array_intersect_key( $assoc_args, Jetpack_Sync_Settings::$valid_settings ), |
||
| 671 | array( |
||
| 672 | 'sync_wait_time' => 0, |
||
| 673 | 'enqueue_wait_time' => 0, |
||
| 674 | 'queue_max_writes_sec' => 10000, |
||
| 675 | 'max_queue_size_full_sync' => 100000 |
||
| 676 | ) |
||
| 677 | ); |
||
| 678 | Jetpack_Sync_Settings::update_settings( $sync_settings ); |
||
| 679 | |||
| 680 | // Convert comma-delimited string of modules to an array |
||
| 681 | View Code Duplication | if ( ! empty( $assoc_args['modules'] ) ) { |
|
| 682 | $modules = array_map( 'trim', explode( ',', $assoc_args['modules'] ) ); |
||
| 683 | |||
| 684 | // Convert the array so that the keys are the module name and the value is true to indicate |
||
| 685 | // that we want to sync the module |
||
| 686 | $modules = array_map( '__return_true', array_flip( $modules ) ); |
||
| 687 | } |
||
| 688 | |||
| 689 | View Code Duplication | foreach ( array( 'posts', 'comments', 'users' ) as $module_name ) { |
|
| 690 | if ( |
||
| 691 | 'users' === $module_name && |
||
| 692 | isset( $assoc_args[ $module_name ] ) && |
||
| 693 | 'initial' === $assoc_args[ $module_name ] |
||
| 694 | ) { |
||
| 695 | $modules[ 'users' ] = 'initial'; |
||
| 696 | } elseif ( isset( $assoc_args[ $module_name ] ) ) { |
||
| 697 | $ids = explode( ',', $assoc_args[ $module_name ] ); |
||
| 698 | if ( count( $ids ) > 0 ) { |
||
| 699 | $modules[ $module_name ] = $ids; |
||
| 700 | } |
||
| 701 | } |
||
| 702 | } |
||
| 703 | |||
| 704 | if ( empty( $modules ) ) { |
||
| 705 | $modules = null; |
||
| 706 | } |
||
| 707 | |||
| 708 | // Kick off a full sync |
||
| 709 | if ( Jetpack_Sync_Actions::do_full_sync( $modules ) ) { |
||
| 710 | if ( $modules ) { |
||
| 711 | WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), join( ', ', array_keys( $modules ) ) ) ); |
||
| 712 | } else { |
||
| 713 | WP_CLI::log( __( 'Initialized a new full sync', 'jetpack' ) ); |
||
| 714 | } |
||
| 715 | View Code Duplication | } else { |
|
| 716 | |||
| 717 | // Reset sync settings to original. |
||
| 718 | Jetpack_Sync_Settings::update_settings( $original_settings ); |
||
| 719 | |||
| 720 | if ( $modules ) { |
||
| 721 | WP_CLI::error( sprintf( __( 'Could not start a new full sync with modules: %s', 'jetpack' ), join( ', ', $modules ) ) ); |
||
| 722 | } else { |
||
| 723 | WP_CLI::error( __( 'Could not start a new full sync', 'jetpack' ) ); |
||
| 724 | } |
||
| 725 | } |
||
| 726 | |||
| 727 | // Keep sending to WPCOM until there's nothing to send |
||
| 728 | $i = 1; |
||
| 729 | do { |
||
| 730 | $result = Jetpack_Sync_Actions::$sender->do_full_sync(); |
||
| 731 | if ( is_wp_error( $result ) ) { |
||
| 732 | $queue_empty_error = ( 'empty_queue_full_sync' == $result->get_error_code() ); |
||
| 733 | if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 == $i ) ) ) { |
||
| 734 | WP_CLI::error( sprintf( __( 'Sync errored with code: %s', 'jetpack' ), $result->get_error_code() ) ); |
||
| 735 | } |
||
| 736 | } else { |
||
| 737 | if ( 1 == $i ) { |
||
| 738 | WP_CLI::log( __( 'Sent data to WordPress.com', 'jetpack' ) ); |
||
| 739 | } else { |
||
| 740 | WP_CLI::log( __( 'Sent more data to WordPress.com', 'jetpack' ) ); |
||
| 741 | } |
||
| 742 | } |
||
| 743 | $i++; |
||
| 744 | } while ( $result && ! is_wp_error( $result ) ); |
||
| 745 | |||
| 746 | // Reset sync settings to original. |
||
| 747 | Jetpack_Sync_Settings::update_settings( $original_settings ); |
||
| 748 | |||
| 749 | WP_CLI::success( __( 'Finished syncing to WordPress.com', 'jetpack' ) ); |
||
| 750 | break; |
||
| 751 | } |
||
| 752 | } |
||
| 753 | |||
| 754 | /** |
||
| 755 | * List the contents of a specific Jetpack sync queue. |
||
| 756 | * |
||
| 757 | * ## OPTIONS |
||
| 758 | * |
||
| 759 | * peek : List the 100 front-most items on the queue. |
||
| 760 | * |
||
| 761 | * ## EXAMPLES |
||
| 762 | * |
||
| 763 | * wp jetpack sync_queue full_sync peek |
||
| 764 | * |
||
| 765 | * @synopsis <incremental|full_sync> <peek> |
||
| 766 | */ |
||
| 767 | public function sync_queue( $args, $assoc_args ) { |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Cancel's the current Jetpack plan granted by this partner, if applicable |
||
| 821 | * |
||
| 822 | * Returns success or error JSON |
||
| 823 | * |
||
| 824 | * <token_json> |
||
| 825 | * : JSON blob of WPCOM API token |
||
| 826 | * [--partner-tracking-id=<partner_tracking_id>] |
||
| 827 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
| 828 | * |
||
| 829 | * * @synopsis <token_json> [--partner-tracking-id=<partner_tracking_id>] |
||
| 830 | */ |
||
| 831 | public function partner_cancel( $args, $named_args ) { |
||
| 876 | |||
| 877 | /** |
||
| 878 | * Provision a site using a Jetpack Partner license |
||
| 879 | * |
||
| 880 | * Returns JSON blob |
||
| 881 | * |
||
| 882 | * ## OPTIONS |
||
| 883 | * |
||
| 884 | * <token_json> |
||
| 885 | * : JSON blob of WPCOM API token |
||
| 886 | * [--plan=<plan_name>] |
||
| 887 | * : Slug of the requested plan, e.g. premium |
||
| 888 | * [--wpcom_user_id=<user_id>] |
||
| 889 | * : WordPress.com ID of user to connect as (must be whitelisted against partner key) |
||
| 890 | * [--wpcom_user_email=<wpcom_user_email>] |
||
| 891 | * : Override the email we send to WordPress.com for registration |
||
| 892 | * [--onboarding=<onboarding>] |
||
| 893 | * : Guide the user through an onboarding wizard |
||
| 894 | * [--force_register=<register>] |
||
| 895 | * : Whether to force a site to register |
||
| 896 | * [--force_connect=<force_connect>] |
||
| 897 | * : Force JPS to not reuse existing credentials |
||
| 898 | * [--home_url=<home_url>] |
||
| 899 | * : Overrides the home option via the home_url filter, or the WP_HOME constant |
||
| 900 | * [--site_url=<site_url>] |
||
| 901 | * : Overrides the siteurl option via the site_url filter, or the WP_SITEURL constant |
||
| 902 | * [--partner-tracking-id=<partner_tracking_id>] |
||
| 903 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
| 904 | * |
||
| 905 | * ## EXAMPLES |
||
| 906 | * |
||
| 907 | * $ wp jetpack partner_provision '{ some: "json" }' premium 1 |
||
| 908 | * { success: true } |
||
| 909 | * |
||
| 910 | * @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>] |
||
| 911 | */ |
||
| 912 | public function partner_provision( $args, $named_args ) { |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Manages your Jetpack sitemap |
||
| 1109 | * |
||
| 1110 | * ## OPTIONS |
||
| 1111 | * |
||
| 1112 | * rebuild : Rebuild all sitemaps |
||
| 1113 | * --purge : if set, will remove all existing sitemap data before rebuilding |
||
| 1114 | * |
||
| 1115 | * ## EXAMPLES |
||
| 1116 | * |
||
| 1117 | * wp jetpack sitemap rebuild |
||
| 1118 | * |
||
| 1119 | * @subcommand sitemap |
||
| 1120 | * @synopsis <rebuild> [--purge] |
||
| 1121 | */ |
||
| 1122 | public function sitemap( $args, $assoc_args ) { |
||
| 1141 | |||
| 1142 | private function get_api_host() { |
||
| 1146 | |||
| 1147 | private function partner_provision_error( $error ) { |
||
| 1155 | } |
||
| 1156 | |||
| 1193 |
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: