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 |
||
11 | class Jetpack_CLI extends WP_CLI_Command { |
||
12 | // Aesthetics |
||
13 | public $green_open = "\033[32m"; |
||
14 | public $red_open = "\033[31m"; |
||
15 | public $yellow_open = "\033[33m"; |
||
16 | public $color_close = "\033[0m"; |
||
17 | |||
18 | /** |
||
19 | * Get Jetpack Details |
||
20 | * |
||
21 | * ## OPTIONS |
||
22 | * |
||
23 | * empty: Leave it empty for basic stats |
||
24 | * |
||
25 | * full: View full stats. It's the data from the heartbeat |
||
26 | * |
||
27 | * ## EXAMPLES |
||
28 | * |
||
29 | * wp jetpack status |
||
30 | * wp jetpack status full |
||
31 | * |
||
32 | */ |
||
33 | public function status( $args, $assoc_args ) { |
||
104 | |||
105 | /** |
||
106 | * Tests the active connection |
||
107 | * |
||
108 | * 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. |
||
109 | * |
||
110 | * ## EXAMPLES |
||
111 | * |
||
112 | * wp jetpack test-connection |
||
113 | * |
||
114 | * @subcommand test-connection |
||
115 | */ |
||
116 | public function test_connection( $args, $assoc_args ) { |
||
149 | |||
150 | /** |
||
151 | * Disconnect Jetpack Blogs or Users |
||
152 | * |
||
153 | * ## OPTIONS |
||
154 | * |
||
155 | * blog: Disconnect the entire blog. |
||
156 | * |
||
157 | * user <user_identifier>: Disconnect a specific user from WordPress.com. |
||
158 | * |
||
159 | * Please note, the primary account that the blog is connected |
||
160 | * to WordPress.com with cannot be disconnected without |
||
161 | * disconnecting the entire blog. |
||
162 | * |
||
163 | * ## EXAMPLES |
||
164 | * |
||
165 | * wp jetpack disconnect blog |
||
166 | * wp jetpack disconnect user 13 |
||
167 | * wp jetpack disconnect user username |
||
168 | * wp jetpack disconnect user [email protected] |
||
169 | * |
||
170 | * @synopsis <blog|user> [<user_identifier>] |
||
171 | */ |
||
172 | public function disconnect( $args, $assoc_args ) { |
||
227 | |||
228 | /** |
||
229 | * Reset Jetpack options and settings to default |
||
230 | * |
||
231 | * ## OPTIONS |
||
232 | * |
||
233 | * modules: Resets modules to default state ( get_default_modules() ) |
||
234 | * |
||
235 | * options: Resets all Jetpack options except: |
||
236 | * - All private options (Blog token, user token, etc...) |
||
237 | * - id (The Client ID/WP.com Blog ID of this site) |
||
238 | * - master_user |
||
239 | * - version |
||
240 | * - activated |
||
241 | * |
||
242 | * ## EXAMPLES |
||
243 | * |
||
244 | * wp jetpack reset options |
||
245 | * wp jetpack reset modules |
||
246 | * |
||
247 | * @synopsis <modules|options> |
||
248 | */ |
||
249 | public function reset( $args, $assoc_args ) { |
||
307 | |||
308 | /** |
||
309 | * Manage Jetpack Modules |
||
310 | * |
||
311 | * ## OPTIONS |
||
312 | * |
||
313 | * <list|activate|deactivate|toggle> |
||
314 | * : The action to take. |
||
315 | * --- |
||
316 | * default: list |
||
317 | * options: |
||
318 | * - list |
||
319 | * - activate |
||
320 | * - deactivate |
||
321 | * - toggle |
||
322 | * --- |
||
323 | * |
||
324 | * [<module_slug>] |
||
325 | * : The slug of the module to perform an action on. |
||
326 | * |
||
327 | * [--format=<format>] |
||
328 | * : Allows overriding the output of the command when listing modules. |
||
329 | * --- |
||
330 | * default: table |
||
331 | * options: |
||
332 | * - table |
||
333 | * - json |
||
334 | * - csv |
||
335 | * - yaml |
||
336 | * - ids |
||
337 | * - count |
||
338 | * --- |
||
339 | * |
||
340 | * ## EXAMPLES |
||
341 | * |
||
342 | * wp jetpack module list |
||
343 | * wp jetpack module list --format=json |
||
344 | * wp jetpack module activate stats |
||
345 | * wp jetpack module deactivate stats |
||
346 | * wp jetpack module toggle stats |
||
347 | * wp jetpack module activate all |
||
348 | * wp jetpack module deactivate all |
||
349 | */ |
||
350 | public function module( $args, $assoc_args ) { |
||
421 | |||
422 | /** |
||
423 | * Manage Protect Settings |
||
424 | * |
||
425 | * ## OPTIONS |
||
426 | * |
||
427 | * whitelist: Whitelist an IP address. You can also read or clear the whitelist. |
||
428 | * |
||
429 | * |
||
430 | * ## EXAMPLES |
||
431 | * |
||
432 | * wp jetpack protect whitelist <ip address> |
||
433 | * wp jetpack protect whitelist list |
||
434 | * wp jetpack protect whitelist clear |
||
435 | * |
||
436 | * @synopsis <whitelist> [<ip|ip_low-ip_high|list|clear>] |
||
437 | */ |
||
438 | public function protect( $args, $assoc_args ) { |
||
439 | $action = isset( $args[0] ) ? $args[0] : 'prompt'; |
||
440 | if ( ! in_array( $action, array( 'whitelist' ) ) ) { |
||
441 | /* translators: %s is a command like "prompt" */ |
||
442 | WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) ); |
||
443 | } |
||
444 | // Check if module is active |
||
445 | if ( ! Jetpack::is_module_active( __FUNCTION__ ) ) { |
||
446 | 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__ ) ); |
||
447 | } |
||
448 | if ( in_array( $action, array( 'whitelist' ) ) ) { |
||
449 | if ( isset( $args[1] ) ) { |
||
450 | $action = 'whitelist'; |
||
451 | } else { |
||
452 | $action = 'prompt'; |
||
453 | } |
||
454 | } |
||
455 | switch ( $action ) { |
||
456 | case 'whitelist': |
||
457 | $whitelist = array(); |
||
458 | $new_ip = $args[1]; |
||
459 | $current_whitelist = get_site_option( 'jetpack_protect_whitelist', array() ); |
||
460 | |||
461 | // Build array of IPs that are already whitelisted. |
||
462 | // Re-build manually instead of using jetpack_protect_format_whitelist() so we can easily get |
||
463 | // low & high range params for jetpack_protect_ip_address_is_in_range(); |
||
464 | foreach( $current_whitelist as $whitelisted ) { |
||
465 | |||
466 | // IP ranges |
||
467 | if ( $whitelisted->range ) { |
||
468 | |||
469 | // Is it already whitelisted? |
||
470 | if ( jetpack_protect_ip_address_is_in_range( $new_ip, $whitelisted->range_low, $whitelisted->range_high ) ) { |
||
471 | /* translators: %s is an IP address */ |
||
472 | WP_CLI::error( sprintf( __( '%s has already been whitelisted', 'jetpack' ), $new_ip ) ); |
||
473 | break; |
||
474 | } |
||
475 | $whitelist[] = $whitelisted->range_low . " - " . $whitelisted->range_high; |
||
476 | |||
477 | } else { // Individual IPs |
||
478 | |||
479 | // Check if the IP is already whitelisted (single IP only) |
||
480 | if ( $new_ip == $whitelisted->ip_address ) { |
||
481 | /* translators: %s is an IP address */ |
||
482 | WP_CLI::error( sprintf( __( '%s has already been whitelisted', 'jetpack' ), $new_ip ) ); |
||
483 | break; |
||
484 | } |
||
485 | $whitelist[] = $whitelisted->ip_address; |
||
486 | |||
487 | } |
||
488 | } |
||
489 | |||
490 | /* |
||
491 | * List the whitelist |
||
492 | * Done here because it's easier to read the $whitelist array after it's been rebuilt |
||
493 | */ |
||
494 | if ( isset( $args[1] ) && 'list' == $args[1] ) { |
||
495 | if ( ! empty( $whitelist ) ) { |
||
496 | WP_CLI::success( __( 'Here are your whitelisted IPs:', 'jetpack' ) ); |
||
497 | foreach ( $whitelist as $ip ) { |
||
498 | WP_CLI::line( "\t" . str_pad( $ip, 24 ) ) ; |
||
499 | } |
||
500 | } else { |
||
501 | WP_CLI::line( __( 'Whitelist is empty.', "jetpack" ) ) ; |
||
502 | } |
||
503 | break; |
||
504 | } |
||
505 | |||
506 | /* |
||
507 | * Clear the whitelist |
||
508 | */ |
||
509 | if ( isset( $args[1] ) && 'clear' == $args[1] ) { |
||
510 | if ( ! empty( $whitelist ) ) { |
||
511 | $whitelist = array(); |
||
512 | jetpack_protect_save_whitelist( $whitelist ); |
||
513 | WP_CLI::success( __( 'Cleared all whitelisted IPs', 'jetpack' ) ); |
||
514 | } else { |
||
515 | WP_CLI::line( __( 'Whitelist is empty.', "jetpack" ) ) ; |
||
516 | } |
||
517 | break; |
||
518 | } |
||
519 | |||
520 | // Append new IP to whitelist array |
||
521 | array_push( $whitelist, $new_ip ); |
||
522 | |||
523 | // Save whitelist if there are no errors |
||
524 | $result = jetpack_protect_save_whitelist( $whitelist ); |
||
525 | if ( is_wp_error( $result ) ) { |
||
526 | WP_CLI::error( __( $result, 'jetpack' ) ); |
||
527 | } |
||
528 | |||
529 | /* translators: %s is an IP address */ |
||
530 | WP_CLI::success( sprintf( __( '%s has been whitelisted.', 'jetpack' ), $new_ip ) ); |
||
531 | break; |
||
532 | case 'prompt': |
||
533 | WP_CLI::error( |
||
534 | __( 'No command found.', 'jetpack' ) . "\n" . |
||
535 | __( 'Please enter the IP address you want to whitelist.', 'jetpack' ) . "\n" . |
||
536 | _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" . |
||
537 | _x( "You can also 'list' or 'clear' the whitelist.", "'list' and 'clear' are commands and should not be translated", 'jetpack' ) . "\n" |
||
538 | ); |
||
539 | break; |
||
540 | } |
||
541 | } |
||
542 | |||
543 | /** |
||
544 | * Manage Jetpack Options |
||
545 | * |
||
546 | * ## OPTIONS |
||
547 | * |
||
548 | * list : List all jetpack options and their values |
||
549 | * delete : Delete an option |
||
550 | * - can only delete options that are white listed. |
||
551 | * update : update an option |
||
552 | * - can only update option strings |
||
553 | * get : get the value of an option |
||
554 | * |
||
555 | * ## EXAMPLES |
||
556 | * |
||
557 | * wp jetpack options list |
||
558 | * wp jetpack options get <option_name> |
||
559 | * wp jetpack options delete <option_name> |
||
560 | * wp jetpack options update <option_name> [<option_value>] |
||
561 | * |
||
562 | * @synopsis <list|get|delete|update> [<option_name>] [<option_value>] |
||
563 | */ |
||
564 | public function options( $args, $assoc_args ) { |
||
661 | |||
662 | /** |
||
663 | * Get the status of or start a new Jetpack sync. |
||
664 | * |
||
665 | * ## OPTIONS |
||
666 | * |
||
667 | * status : Print the current sync status |
||
668 | * start : Start a full sync from this site to WordPress.com |
||
669 | * |
||
670 | * ## EXAMPLES |
||
671 | * |
||
672 | * wp jetpack sync status |
||
673 | * wp jetpack sync start --modules=functions --sync_wait_time=5 |
||
674 | * |
||
675 | * @synopsis <status|start> [--<field>=<value>] |
||
676 | */ |
||
677 | public function sync( $args, $assoc_args ) { |
||
678 | if ( ! Jetpack_Sync_Actions::sync_allowed() ) { |
||
679 | WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site.', 'jetpack' ) ); |
||
680 | } |
||
681 | |||
682 | $action = isset( $args[0] ) ? $args[0] : 'status'; |
||
683 | |||
684 | switch ( $action ) { |
||
685 | case 'status': |
||
686 | $status = Jetpack_Sync_Actions::get_sync_status(); |
||
687 | $collection = array(); |
||
688 | foreach ( $status as $key => $item ) { |
||
689 | $collection[] = array( |
||
690 | 'option' => $key, |
||
691 | 'value' => is_scalar( $item ) ? $item : json_encode( $item ) |
||
692 | ); |
||
693 | } |
||
694 | |||
695 | WP_CLI\Utils\format_items( 'table', $collection, array( 'option', 'value' ) ); |
||
696 | break; |
||
697 | case 'start': |
||
698 | // Get the original settings so that we can restore them later |
||
699 | $original_settings = Jetpack_Sync_Settings::get_settings(); |
||
700 | |||
701 | // Initialize sync settigns so we can sync as quickly as possible |
||
702 | $sync_settings = wp_parse_args( |
||
703 | array_intersect_key( $assoc_args, Jetpack_Sync_Settings::$valid_settings ), |
||
704 | array( |
||
705 | 'sync_wait_time' => 0, |
||
706 | 'enqueue_wait_time' => 0, |
||
707 | 'queue_max_writes_sec' => 10000, |
||
708 | 'max_queue_size_full_sync' => 100000 |
||
709 | ) |
||
710 | ); |
||
711 | Jetpack_Sync_Settings::update_settings( $sync_settings ); |
||
712 | |||
713 | // Convert comma-delimited string of modules to an array |
||
714 | View Code Duplication | if ( ! empty( $assoc_args['modules'] ) ) { |
|
715 | $modules = array_map( 'trim', explode( ',', $assoc_args['modules'] ) ); |
||
716 | |||
717 | // Convert the array so that the keys are the module name and the value is true to indicate |
||
718 | // that we want to sync the module |
||
719 | $modules = array_map( '__return_true', array_flip( $modules ) ); |
||
720 | } |
||
721 | |||
722 | View Code Duplication | foreach ( array( 'posts', 'comments', 'users' ) as $module_name ) { |
|
723 | if ( |
||
724 | 'users' === $module_name && |
||
725 | isset( $assoc_args[ $module_name ] ) && |
||
726 | 'initial' === $assoc_args[ $module_name ] |
||
727 | ) { |
||
728 | $modules[ 'users' ] = 'initial'; |
||
729 | } elseif ( isset( $assoc_args[ $module_name ] ) ) { |
||
730 | $ids = explode( ',', $assoc_args[ $module_name ] ); |
||
731 | if ( count( $ids ) > 0 ) { |
||
732 | $modules[ $module_name ] = $ids; |
||
733 | } |
||
734 | } |
||
735 | } |
||
736 | |||
737 | if ( empty( $modules ) ) { |
||
738 | $modules = null; |
||
739 | } |
||
740 | |||
741 | // Kick off a full sync |
||
742 | if ( Jetpack_Sync_Actions::do_full_sync( $modules ) ) { |
||
743 | View Code Duplication | if ( $modules ) { |
|
744 | WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), join( ', ', array_keys( $modules ) ) ) ); |
||
745 | } else { |
||
746 | WP_CLI::log( __( 'Initialized a new full sync', 'jetpack' ) ); |
||
747 | } |
||
748 | View Code Duplication | } else { |
|
749 | |||
750 | // Reset sync settings to original. |
||
751 | Jetpack_Sync_Settings::update_settings( $original_settings ); |
||
752 | |||
753 | if ( $modules ) { |
||
754 | WP_CLI::error( sprintf( __( 'Could not start a new full sync with modules: %s', 'jetpack' ), join( ', ', $modules ) ) ); |
||
755 | } else { |
||
756 | WP_CLI::error( __( 'Could not start a new full sync', 'jetpack' ) ); |
||
757 | } |
||
758 | } |
||
759 | |||
760 | // Keep sending to WPCOM until there's nothing to send |
||
761 | $i = 1; |
||
762 | do { |
||
763 | $result = Jetpack_Sync_Actions::$sender->do_full_sync(); |
||
764 | if ( is_wp_error( $result ) ) { |
||
765 | $queue_empty_error = ( 'empty_queue_full_sync' == $result->get_error_code() ); |
||
766 | if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 == $i ) ) ) { |
||
767 | WP_CLI::error( sprintf( __( 'Sync errored with code: %s', 'jetpack' ), $result->get_error_code() ) ); |
||
768 | } |
||
769 | } else { |
||
770 | if ( 1 == $i ) { |
||
771 | WP_CLI::log( __( 'Sent data to WordPress.com', 'jetpack' ) ); |
||
772 | } else { |
||
773 | WP_CLI::log( __( 'Sent more data to WordPress.com', 'jetpack' ) ); |
||
774 | } |
||
775 | } |
||
776 | $i++; |
||
777 | } while ( $result && ! is_wp_error( $result ) ); |
||
778 | |||
779 | // Reset sync settings to original. |
||
780 | Jetpack_Sync_Settings::update_settings( $original_settings ); |
||
781 | |||
782 | WP_CLI::success( __( 'Finished syncing to WordPress.com', 'jetpack' ) ); |
||
783 | break; |
||
784 | } |
||
785 | } |
||
786 | |||
787 | /** |
||
788 | * List the contents of a specific Jetpack sync queue. |
||
789 | * |
||
790 | * ## OPTIONS |
||
791 | * |
||
792 | * peek : List the 100 front-most items on the queue. |
||
793 | * |
||
794 | * ## EXAMPLES |
||
795 | * |
||
796 | * wp jetpack sync_queue full_sync peek |
||
797 | * |
||
798 | * @synopsis <incremental|full_sync> <peek> |
||
799 | */ |
||
800 | public function sync_queue( $args, $assoc_args ) { |
||
851 | |||
852 | /** |
||
853 | * Cancel's the current Jetpack plan granted by this partner, if applicable |
||
854 | * |
||
855 | * Returns success or error JSON |
||
856 | * |
||
857 | * <token_json> |
||
858 | * : JSON blob of WPCOM API token |
||
859 | * [--partner_tracking_id=<partner_tracking_id>] |
||
860 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
861 | * |
||
862 | * * @synopsis <token_json> [--partner_tracking_id=<partner_tracking_id>] |
||
863 | */ |
||
864 | public function partner_cancel( $args, $named_args ) { |
||
916 | |||
917 | /** |
||
918 | * Provision a site using a Jetpack Partner license |
||
919 | * |
||
920 | * Returns JSON blob |
||
921 | * |
||
922 | * ## OPTIONS |
||
923 | * |
||
924 | * <token_json> |
||
925 | * : JSON blob of WPCOM API token |
||
926 | * [--plan=<plan_name>] |
||
927 | * : Slug of the requested plan, e.g. premium |
||
928 | * [--wpcom_user_id=<user_id>] |
||
929 | * : WordPress.com ID of user to connect as (must be whitelisted against partner key) |
||
930 | * [--wpcom_user_email=<wpcom_user_email>] |
||
931 | * : Override the email we send to WordPress.com for registration |
||
932 | * [--onboarding=<onboarding>] |
||
933 | * : Guide the user through an onboarding wizard |
||
934 | * [--force_register=<register>] |
||
935 | * : Whether to force a site to register |
||
936 | * [--force_connect=<force_connect>] |
||
937 | * : Force JPS to not reuse existing credentials |
||
938 | * [--home_url=<home_url>] |
||
939 | * : Overrides the home option via the home_url filter, or the WP_HOME constant |
||
940 | * [--site_url=<site_url>] |
||
941 | * : Overrides the siteurl option via the site_url filter, or the WP_SITEURL constant |
||
942 | * [--partner_tracking_id=<partner_tracking_id>] |
||
943 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
944 | * |
||
945 | * ## EXAMPLES |
||
946 | * |
||
947 | * $ wp jetpack partner_provision '{ some: "json" }' premium 1 |
||
948 | * { success: true } |
||
949 | * |
||
950 | * @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>] |
||
951 | */ |
||
952 | public function partner_provision( $args, $named_args ) { |
||
985 | |||
986 | /** |
||
987 | * Manages your Jetpack sitemap |
||
988 | * |
||
989 | * ## OPTIONS |
||
990 | * |
||
991 | * rebuild : Rebuild all sitemaps |
||
992 | * --purge : if set, will remove all existing sitemap data before rebuilding |
||
993 | * |
||
994 | * ## EXAMPLES |
||
995 | * |
||
996 | * wp jetpack sitemap rebuild |
||
997 | * |
||
998 | * @subcommand sitemap |
||
999 | * @synopsis <rebuild> [--purge] |
||
1000 | */ |
||
1001 | public function sitemap( $args, $assoc_args ) { |
||
1020 | |||
1021 | /** |
||
1022 | * Allows authorizing a user via the command line and will activate |
||
1023 | * |
||
1024 | * ## EXAMPLES |
||
1025 | * |
||
1026 | * wp jetpack authorize_user --token=123456789abcdef |
||
1027 | * |
||
1028 | * @synopsis --token=<value> |
||
1029 | */ |
||
1030 | public function authorize_user( $args, $named_args ) { |
||
1064 | |||
1065 | /** |
||
1066 | * Allows calling a WordPress.com API endpoint using the current blog's token. |
||
1067 | * |
||
1068 | * ## OPTIONS |
||
1069 | * --resource=<resource> |
||
1070 | * : The resource to call with the current blog's token, where `%d` represents the current blog's ID. |
||
1071 | * |
||
1072 | * [--api_version=<api_version>] |
||
1073 | * : The API version to query against. |
||
1074 | * |
||
1075 | * [--base_api_path=<base_api_path>] |
||
1076 | * : The base API path to query. |
||
1077 | * --- |
||
1078 | * default: rest |
||
1079 | * --- |
||
1080 | * |
||
1081 | * [--body=<body>] |
||
1082 | * : A JSON encoded string representing arguments to send in the body. |
||
1083 | * |
||
1084 | * [--field=<value>] |
||
1085 | * : Any number of arguments that should be passed to the resource. |
||
1086 | * |
||
1087 | * [--pretty] |
||
1088 | * : Will pretty print the results of a successful API call. |
||
1089 | * |
||
1090 | * [--strip-success] |
||
1091 | * : Will remove the green success label from successful API calls. |
||
1092 | * |
||
1093 | * ## EXAMPLES |
||
1094 | * |
||
1095 | * wp jetpack call_api --resource='/sites/%d' |
||
1096 | */ |
||
1097 | public function call_api( $args, $named_args ) { |
||
1163 | |||
1164 | /** |
||
1165 | * API wrapper for getting stats from the WordPress.com API for the current site. |
||
1166 | * |
||
1167 | * ## OPTIONS |
||
1168 | * |
||
1169 | * [--quantity=<quantity>] |
||
1170 | * : The number of units to include. |
||
1171 | * --- |
||
1172 | * default: 30 |
||
1173 | * --- |
||
1174 | * |
||
1175 | * [--period=<period>] |
||
1176 | * : The unit of time to query stats for. |
||
1177 | * --- |
||
1178 | * default: day |
||
1179 | * options: |
||
1180 | * - day |
||
1181 | * - week |
||
1182 | * - month |
||
1183 | * - year |
||
1184 | * --- |
||
1185 | * |
||
1186 | * [--date=<date>] |
||
1187 | * : The latest date to return stats for. Ex. - 2018-01-01. |
||
1188 | * |
||
1189 | * [--pretty] |
||
1190 | * : Will pretty print the results of a successful API call. |
||
1191 | * |
||
1192 | * [--strip-success] |
||
1193 | * : Will remove the green success label from successful API calls. |
||
1194 | * |
||
1195 | * ## EXAMPLES |
||
1196 | * |
||
1197 | * wp jetpack get_stats |
||
1198 | */ |
||
1199 | public function get_stats( $args, $named_args ) { |
||
1232 | |||
1233 | /** |
||
1234 | * Allows management of publicize connections. |
||
1235 | * |
||
1236 | * ## OPTIONS |
||
1237 | * |
||
1238 | * <list|disconnect> |
||
1239 | * : The action to perform. |
||
1240 | * --- |
||
1241 | * options: |
||
1242 | * - list |
||
1243 | * - disconnect |
||
1244 | * --- |
||
1245 | * |
||
1246 | * [<identifier>] |
||
1247 | * : The connection ID or service to perform an action on. |
||
1248 | * |
||
1249 | * [--format=<format>] |
||
1250 | * : Allows overriding the output of the command when listing connections. |
||
1251 | * --- |
||
1252 | * default: table |
||
1253 | * options: |
||
1254 | * - table |
||
1255 | * - json |
||
1256 | * - csv |
||
1257 | * - yaml |
||
1258 | * - ids |
||
1259 | * - count |
||
1260 | * --- |
||
1261 | * |
||
1262 | * ## EXAMPLES |
||
1263 | * |
||
1264 | * # List all publicize connections. |
||
1265 | * $ wp jetpack publicize list |
||
1266 | * |
||
1267 | * # List publicize connections for a given service. |
||
1268 | * $ wp jetpack publicize list twitter |
||
1269 | * |
||
1270 | * # List all publicize connections for a given user. |
||
1271 | * $ wp --user=1 jetpack publicize list |
||
1272 | * |
||
1273 | * # List all publicize connections for a given user and service. |
||
1274 | * $ wp --user=1 jetpack publicize list twitter |
||
1275 | * |
||
1276 | * # Display details for a given connection. |
||
1277 | * $ wp jetpack publicize list 123456 |
||
1278 | * |
||
1279 | * # Diconnection a given connection. |
||
1280 | * $ wp jetpack publicize disconnect 123456 |
||
1281 | * |
||
1282 | * # Disconnect all connections. |
||
1283 | * $ wp jetpack publicize disconnect all |
||
1284 | * |
||
1285 | * # Disconnect all connections for a given service. |
||
1286 | * $ wp jetpack publicize disconnect twitter |
||
1287 | */ |
||
1288 | public function publicize( $args, $named_args ) { |
||
1461 | |||
1462 | private function get_api_host() { |
||
1466 | |||
1467 | private function partner_provision_error( $error ) { |
||
1475 | } |
||
1476 | |||
1512 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: