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 ) { |
||
34 | jetpack_require_lib( 'debugger' ); |
||
35 | |||
36 | WP_CLI::line( sprintf( __( 'Checking status for %s', 'jetpack' ), esc_url( get_home_url() ) ) ); |
||
37 | |||
38 | View Code Duplication | if ( isset( $args[0] ) && 'full' !== $args[0] ) { |
|
39 | /* translators: %s is a command like "prompt" */ |
||
40 | WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $args[0] ) ); |
||
41 | } |
||
42 | |||
43 | $master_user_email = Jetpack::get_master_user_email(); |
||
44 | |||
45 | $cxntests = new Jetpack_Cxn_Tests(); |
||
46 | |||
47 | if ( $cxntests->pass() ) { |
||
48 | $cxntests->output_results_for_cli(); |
||
49 | |||
50 | WP_CLI::success( __( 'Jetpack is currently connected to WordPress.com', 'jetpack' ) ); |
||
51 | } else { |
||
52 | $error = array(); |
||
53 | foreach ( $cxntests->list_fails() as $fail ) { |
||
|
|||
54 | $error[] = $fail['name'] . ': ' . $fail['message']; |
||
55 | } |
||
56 | WP_CLI::error_multi_line( $error ); |
||
57 | |||
58 | $cxntests->output_results_for_cli(); |
||
59 | |||
60 | WP_CLI::error( __('Jetpack connection is broken.', 'jetpack' ) ); // Exit CLI. |
||
61 | } |
||
62 | |||
63 | WP_CLI::line( sprintf( __( 'The Jetpack Version is %s', 'jetpack' ), JETPACK__VERSION ) ); |
||
64 | WP_CLI::line( sprintf( __( 'The WordPress.com blog_id is %d', 'jetpack' ), Jetpack_Options::get_option( 'id' ) ) ); |
||
65 | WP_CLI::line( sprintf( __( 'The WordPress.com account for the primary connection is %s', 'jetpack' ), $master_user_email ) ); |
||
66 | |||
67 | /* |
||
68 | * Are they asking for all data? |
||
69 | * |
||
70 | * Loop through heartbeat data and organize by priority. |
||
71 | */ |
||
72 | $all_data = ( isset( $args[0] ) && 'full' == $args[0] ) ? 'full' : false; |
||
73 | if ( $all_data ) { |
||
74 | // Heartbeat data |
||
75 | WP_CLI::line( "\n" . __( 'Additional data: ', 'jetpack' ) ); |
||
76 | |||
77 | // Get the filtered heartbeat data. |
||
78 | // Filtered so we can color/list by severity |
||
79 | $stats = Jetpack::jetpack_check_heartbeat_data(); |
||
80 | |||
81 | // Display red flags first |
||
82 | foreach ( $stats['bad'] as $stat => $value ) { |
||
83 | printf( "$this->red_open%-'.16s %s $this->color_close\n", $stat, $value ); |
||
84 | } |
||
85 | |||
86 | // Display caution warnings next |
||
87 | foreach ( $stats['caution'] as $stat => $value ) { |
||
88 | printf( "$this->yellow_open%-'.16s %s $this->color_close\n", $stat, $value ); |
||
89 | } |
||
90 | |||
91 | // The rest of the results are good! |
||
92 | foreach ( $stats['good'] as $stat => $value ) { |
||
93 | |||
94 | // Modules should get special spacing for aestetics |
||
95 | if ( strpos( $stat, 'odule-' ) ) { |
||
96 | printf( "%-'.30s %s\n", $stat, $value ); |
||
97 | usleep( 4000 ); // For dramatic effect lolz |
||
98 | continue; |
||
99 | } |
||
100 | printf( "%-'.16s %s\n", $stat, $value ); |
||
101 | usleep( 4000 ); // For dramatic effect lolz |
||
102 | } |
||
103 | } else { |
||
104 | // Just the basics |
||
105 | WP_CLI::line( "\n" . _x( "View full status with 'wp jetpack status full'", '"wp jetpack status full" is a command - do not translate', 'jetpack' ) ); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Tests the active connection |
||
111 | * |
||
112 | * 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. |
||
113 | * |
||
114 | * ## EXAMPLES |
||
115 | * |
||
116 | * wp jetpack test-connection |
||
117 | * |
||
118 | * @subcommand test-connection |
||
119 | */ |
||
120 | public function test_connection( $args, $assoc_args ) { |
||
153 | |||
154 | /** |
||
155 | * Disconnect Jetpack Blogs or Users |
||
156 | * |
||
157 | * ## OPTIONS |
||
158 | * |
||
159 | * blog: Disconnect the entire blog. |
||
160 | * |
||
161 | * user <user_identifier>: Disconnect a specific user from WordPress.com. |
||
162 | * |
||
163 | * Please note, the primary account that the blog is connected |
||
164 | * to WordPress.com with cannot be disconnected without |
||
165 | * disconnecting the entire blog. |
||
166 | * |
||
167 | * ## EXAMPLES |
||
168 | * |
||
169 | * wp jetpack disconnect blog |
||
170 | * wp jetpack disconnect user 13 |
||
171 | * wp jetpack disconnect user username |
||
172 | * wp jetpack disconnect user [email protected] |
||
173 | * |
||
174 | * @synopsis <blog|user> [<user_identifier>] |
||
175 | */ |
||
176 | public function disconnect( $args, $assoc_args ) { |
||
231 | |||
232 | /** |
||
233 | * Reset Jetpack options and settings to default |
||
234 | * |
||
235 | * ## OPTIONS |
||
236 | * |
||
237 | * modules: Resets modules to default state ( get_default_modules() ) |
||
238 | * |
||
239 | * options: Resets all Jetpack options except: |
||
240 | * - All private options (Blog token, user token, etc...) |
||
241 | * - id (The Client ID/WP.com Blog ID of this site) |
||
242 | * - master_user |
||
243 | * - version |
||
244 | * - activated |
||
245 | * |
||
246 | * ## EXAMPLES |
||
247 | * |
||
248 | * wp jetpack reset options |
||
249 | * wp jetpack reset modules |
||
250 | * |
||
251 | * @synopsis <modules|options> |
||
252 | */ |
||
253 | public function reset( $args, $assoc_args ) { |
||
311 | |||
312 | /** |
||
313 | * Manage Jetpack Modules |
||
314 | * |
||
315 | * ## OPTIONS |
||
316 | * |
||
317 | * <list|activate|deactivate|toggle> |
||
318 | * : The action to take. |
||
319 | * --- |
||
320 | * default: list |
||
321 | * options: |
||
322 | * - list |
||
323 | * - activate |
||
324 | * - deactivate |
||
325 | * - toggle |
||
326 | * --- |
||
327 | * |
||
328 | * [<module_slug>] |
||
329 | * : The slug of the module to perform an action on. |
||
330 | * |
||
331 | * [--format=<format>] |
||
332 | * : Allows overriding the output of the command when listing modules. |
||
333 | * --- |
||
334 | * default: table |
||
335 | * options: |
||
336 | * - table |
||
337 | * - json |
||
338 | * - csv |
||
339 | * - yaml |
||
340 | * - ids |
||
341 | * - count |
||
342 | * --- |
||
343 | * |
||
344 | * ## EXAMPLES |
||
345 | * |
||
346 | * wp jetpack module list |
||
347 | * wp jetpack module list --format=json |
||
348 | * wp jetpack module activate stats |
||
349 | * wp jetpack module deactivate stats |
||
350 | * wp jetpack module toggle stats |
||
351 | * wp jetpack module activate all |
||
352 | * wp jetpack module deactivate all |
||
353 | */ |
||
354 | public function module( $args, $assoc_args ) { |
||
425 | |||
426 | /** |
||
427 | * Manage Protect Settings |
||
428 | * |
||
429 | * ## OPTIONS |
||
430 | * |
||
431 | * whitelist: Whitelist an IP address. You can also read or clear the whitelist. |
||
432 | * |
||
433 | * |
||
434 | * ## EXAMPLES |
||
435 | * |
||
436 | * wp jetpack protect whitelist <ip address> |
||
437 | * wp jetpack protect whitelist list |
||
438 | * wp jetpack protect whitelist clear |
||
439 | * |
||
440 | * @synopsis <whitelist> [<ip|ip_low-ip_high|list|clear>] |
||
441 | */ |
||
442 | public function protect( $args, $assoc_args ) { |
||
546 | |||
547 | /** |
||
548 | * Manage Jetpack Options |
||
549 | * |
||
550 | * ## OPTIONS |
||
551 | * |
||
552 | * list : List all jetpack options and their values |
||
553 | * delete : Delete an option |
||
554 | * - can only delete options that are white listed. |
||
555 | * update : update an option |
||
556 | * - can only update option strings |
||
557 | * get : get the value of an option |
||
558 | * |
||
559 | * ## EXAMPLES |
||
560 | * |
||
561 | * wp jetpack options list |
||
562 | * wp jetpack options get <option_name> |
||
563 | * wp jetpack options delete <option_name> |
||
564 | * wp jetpack options update <option_name> [<option_value>] |
||
565 | * |
||
566 | * @synopsis <list|get|delete|update> [<option_name>] [<option_value>] |
||
567 | */ |
||
568 | public function options( $args, $assoc_args ) { |
||
569 | $action = isset( $args[0] ) ? $args[0] : 'list'; |
||
570 | $safe_to_modify = Jetpack_Options::get_options_for_reset(); |
||
571 | |||
572 | // Jumpstart is special |
||
573 | array_push( $safe_to_modify, 'jumpstart' ); |
||
574 | |||
575 | // Is the option flagged as unsafe? |
||
576 | $flagged = ! in_array( $args[1], $safe_to_modify ); |
||
577 | |||
578 | View Code Duplication | if ( ! in_array( $action, array( 'list', 'get', 'delete', 'update' ) ) ) { |
|
579 | /* translators: %s is a command like "prompt" */ |
||
580 | WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) ); |
||
581 | } |
||
582 | |||
583 | if ( isset( $args[0] ) ) { |
||
584 | if ( 'get' == $args[0] && isset( $args[1] ) ) { |
||
585 | $action = 'get'; |
||
586 | } else if ( 'delete' == $args[0] && isset( $args[1] ) ) { |
||
587 | $action = 'delete'; |
||
588 | View Code Duplication | } else if ( 'update' == $args[0] && isset( $args[1] ) ) { |
|
589 | $action = 'update'; |
||
590 | } else { |
||
591 | $action = 'list'; |
||
592 | } |
||
593 | } |
||
594 | |||
595 | // Bail if the option isn't found |
||
596 | $option = isset( $args[1] ) ? Jetpack_Options::get_option( $args[1] ) : false; |
||
597 | if ( isset( $args[1] ) && ! $option && 'update' !== $args[0] ) { |
||
598 | WP_CLI::error( __( 'Option not found or is empty. Use "list" to list option names', 'jetpack' ) ); |
||
599 | } |
||
600 | |||
601 | // Let's print_r the option if it's an array |
||
602 | // Used in the 'get' and 'list' actions |
||
603 | $option = is_array( $option ) ? print_r( $option ) : $option; |
||
604 | |||
605 | switch ( $action ) { |
||
606 | case 'get': |
||
607 | WP_CLI::success( "\t" . $option ); |
||
608 | break; |
||
609 | case 'delete': |
||
610 | jetpack_cli_are_you_sure( $flagged ); |
||
611 | |||
612 | Jetpack_Options::delete_option( $args[1] ); |
||
613 | WP_CLI::success( sprintf( __( 'Deleted option: %s', 'jetpack' ), $args[1] ) ); |
||
614 | break; |
||
615 | case 'update': |
||
616 | jetpack_cli_are_you_sure( $flagged ); |
||
617 | |||
618 | // Updating arrays would get pretty tricky... |
||
619 | $value = Jetpack_Options::get_option( $args[1] ); |
||
620 | if ( $value && is_array( $value ) ) { |
||
621 | WP_CLI::error( __( 'Sorry, no updating arrays at this time', 'jetpack' ) ); |
||
622 | } |
||
623 | |||
624 | Jetpack_Options::update_option( $args[1], $args[2] ); |
||
625 | WP_CLI::success( sprintf( _x( 'Updated option: %s to "%s"', 'Updating an option from "this" to "that".', 'jetpack' ), $args[1], $args[2] ) ); |
||
626 | break; |
||
627 | case 'list': |
||
628 | $options_compact = Jetpack_Options::get_option_names(); |
||
629 | $options_non_compact = Jetpack_Options::get_option_names( 'non_compact' ); |
||
630 | $options_private = Jetpack_Options::get_option_names( 'private' ); |
||
631 | $options = array_merge( $options_compact, $options_non_compact, $options_private ); |
||
632 | |||
633 | // Table headers |
||
634 | WP_CLI::line( "\t" . str_pad( __( 'Option', 'jetpack' ), 30 ) . __( 'Value', 'jetpack' ) ); |
||
635 | |||
636 | // List out the options and their values |
||
637 | // Tell them if the value is empty or not |
||
638 | // Tell them if it's an array |
||
639 | foreach ( $options as $option ) { |
||
640 | $value = Jetpack_Options::get_option( $option ); |
||
641 | if ( ! $value ) { |
||
642 | WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Empty' ); |
||
643 | continue; |
||
644 | } |
||
645 | |||
646 | if ( ! is_array( $value ) ) { |
||
647 | WP_CLI::line( "\t" . str_pad( $option, 30 ) . $value ); |
||
648 | } else if ( is_array( $value ) ) { |
||
649 | WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Array - Use "get <option>" to read option array.' ); |
||
650 | } |
||
651 | } |
||
652 | $option_text = '{' . _x( 'option', 'a variable command that a user can write, provided in the printed instructions', 'jetpack' ) . '}'; |
||
653 | $value_text = '{' . _x( 'value', 'the value that they want to update the option to', 'jetpack' ) . '}'; |
||
654 | |||
655 | WP_CLI::success( |
||
656 | _x( "Above are your options. You may 'get', 'delete', and 'update' them.", "'get', 'delete', and 'update' are commands - do not translate.", 'jetpack' ) . "\n" . |
||
657 | str_pad( 'wp jetpack options get', 26 ) . $option_text . "\n" . |
||
658 | str_pad( 'wp jetpack options delete', 26 ) . $option_text . "\n" . |
||
659 | str_pad( 'wp jetpack options update', 26 ) . "$option_text $value_text" . "\n" . |
||
660 | _x( "Type 'wp jetpack options' for more info.", "'wp jetpack options' is a command - do not translate.", 'jetpack' ) . "\n" |
||
661 | ); |
||
662 | break; |
||
663 | } |
||
664 | } |
||
665 | |||
666 | /** |
||
667 | * Get the status of or start a new Jetpack sync. |
||
668 | * |
||
669 | * ## OPTIONS |
||
670 | * |
||
671 | * status : Print the current sync status |
||
672 | * start : Start a full sync from this site to WordPress.com |
||
673 | * |
||
674 | * ## EXAMPLES |
||
675 | * |
||
676 | * wp jetpack sync status |
||
677 | * wp jetpack sync start --modules=functions --sync_wait_time=5 |
||
678 | * |
||
679 | * @synopsis <status|start> [--<field>=<value>] |
||
680 | */ |
||
681 | public function sync( $args, $assoc_args ) { |
||
790 | |||
791 | /** |
||
792 | * List the contents of a specific Jetpack sync queue. |
||
793 | * |
||
794 | * ## OPTIONS |
||
795 | * |
||
796 | * peek : List the 100 front-most items on the queue. |
||
797 | * |
||
798 | * ## EXAMPLES |
||
799 | * |
||
800 | * wp jetpack sync_queue full_sync peek |
||
801 | * |
||
802 | * @synopsis <incremental|full_sync> <peek> |
||
803 | */ |
||
804 | public function sync_queue( $args, $assoc_args ) { |
||
855 | |||
856 | /** |
||
857 | * Cancel's the current Jetpack plan granted by this partner, if applicable |
||
858 | * |
||
859 | * Returns success or error JSON |
||
860 | * |
||
861 | * <token_json> |
||
862 | * : JSON blob of WPCOM API token |
||
863 | * [--partner_tracking_id=<partner_tracking_id>] |
||
864 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
865 | * |
||
866 | * * @synopsis <token_json> [--partner_tracking_id=<partner_tracking_id>] |
||
867 | */ |
||
868 | public function partner_cancel( $args, $named_args ) { |
||
920 | |||
921 | /** |
||
922 | * Provision a site using a Jetpack Partner license |
||
923 | * |
||
924 | * Returns JSON blob |
||
925 | * |
||
926 | * ## OPTIONS |
||
927 | * |
||
928 | * <token_json> |
||
929 | * : JSON blob of WPCOM API token |
||
930 | * [--plan=<plan_name>] |
||
931 | * : Slug of the requested plan, e.g. premium |
||
932 | * [--wpcom_user_id=<user_id>] |
||
933 | * : WordPress.com ID of user to connect as (must be whitelisted against partner key) |
||
934 | * [--wpcom_user_email=<wpcom_user_email>] |
||
935 | * : Override the email we send to WordPress.com for registration |
||
936 | * [--onboarding=<onboarding>] |
||
937 | * : Guide the user through an onboarding wizard |
||
938 | * [--force_register=<register>] |
||
939 | * : Whether to force a site to register |
||
940 | * [--force_connect=<force_connect>] |
||
941 | * : Force JPS to not reuse existing credentials |
||
942 | * [--home_url=<home_url>] |
||
943 | * : Overrides the home option via the home_url filter, or the WP_HOME constant |
||
944 | * [--site_url=<site_url>] |
||
945 | * : Overrides the siteurl option via the site_url filter, or the WP_SITEURL constant |
||
946 | * [--partner_tracking_id=<partner_tracking_id>] |
||
947 | * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com |
||
948 | * |
||
949 | * ## EXAMPLES |
||
950 | * |
||
951 | * $ wp jetpack partner_provision '{ some: "json" }' premium 1 |
||
952 | * { success: true } |
||
953 | * |
||
954 | * @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>] |
||
955 | */ |
||
956 | public function partner_provision( $args, $named_args ) { |
||
989 | |||
990 | /** |
||
991 | * Manages your Jetpack sitemap |
||
992 | * |
||
993 | * ## OPTIONS |
||
994 | * |
||
995 | * rebuild : Rebuild all sitemaps |
||
996 | * --purge : if set, will remove all existing sitemap data before rebuilding |
||
997 | * |
||
998 | * ## EXAMPLES |
||
999 | * |
||
1000 | * wp jetpack sitemap rebuild |
||
1001 | * |
||
1002 | * @subcommand sitemap |
||
1003 | * @synopsis <rebuild> [--purge] |
||
1004 | */ |
||
1005 | public function sitemap( $args, $assoc_args ) { |
||
1024 | |||
1025 | /** |
||
1026 | * Allows authorizing a user via the command line and will activate |
||
1027 | * |
||
1028 | * ## EXAMPLES |
||
1029 | * |
||
1030 | * wp jetpack authorize_user --token=123456789abcdef |
||
1031 | * |
||
1032 | * @synopsis --token=<value> |
||
1033 | */ |
||
1034 | public function authorize_user( $args, $named_args ) { |
||
1068 | |||
1069 | /** |
||
1070 | * Allows calling a WordPress.com API endpoint using the current blog's token. |
||
1071 | * |
||
1072 | * ## OPTIONS |
||
1073 | * --resource=<resource> |
||
1074 | * : The resource to call with the current blog's token, where `%d` represents the current blog's ID. |
||
1075 | * |
||
1076 | * [--api_version=<api_version>] |
||
1077 | * : The API version to query against. |
||
1078 | * |
||
1079 | * [--base_api_path=<base_api_path>] |
||
1080 | * : The base API path to query. |
||
1081 | * --- |
||
1082 | * default: rest |
||
1083 | * --- |
||
1084 | * |
||
1085 | * [--body=<body>] |
||
1086 | * : A JSON encoded string representing arguments to send in the body. |
||
1087 | * |
||
1088 | * [--field=<value>] |
||
1089 | * : Any number of arguments that should be passed to the resource. |
||
1090 | * |
||
1091 | * [--pretty] |
||
1092 | * : Will pretty print the results of a successful API call. |
||
1093 | * |
||
1094 | * [--strip-success] |
||
1095 | * : Will remove the green success label from successful API calls. |
||
1096 | * |
||
1097 | * ## EXAMPLES |
||
1098 | * |
||
1099 | * wp jetpack call_api --resource='/sites/%d' |
||
1100 | */ |
||
1101 | public function call_api( $args, $named_args ) { |
||
1167 | |||
1168 | /** |
||
1169 | * API wrapper for getting stats from the WordPress.com API for the current site. |
||
1170 | * |
||
1171 | * ## OPTIONS |
||
1172 | * |
||
1173 | * [--quantity=<quantity>] |
||
1174 | * : The number of units to include. |
||
1175 | * --- |
||
1176 | * default: 30 |
||
1177 | * --- |
||
1178 | * |
||
1179 | * [--period=<period>] |
||
1180 | * : The unit of time to query stats for. |
||
1181 | * --- |
||
1182 | * default: day |
||
1183 | * options: |
||
1184 | * - day |
||
1185 | * - week |
||
1186 | * - month |
||
1187 | * - year |
||
1188 | * --- |
||
1189 | * |
||
1190 | * [--date=<date>] |
||
1191 | * : The latest date to return stats for. Ex. - 2018-01-01. |
||
1192 | * |
||
1193 | * [--pretty] |
||
1194 | * : Will pretty print the results of a successful API call. |
||
1195 | * |
||
1196 | * [--strip-success] |
||
1197 | * : Will remove the green success label from successful API calls. |
||
1198 | * |
||
1199 | * ## EXAMPLES |
||
1200 | * |
||
1201 | * wp jetpack get_stats |
||
1202 | */ |
||
1203 | public function get_stats( $args, $named_args ) { |
||
1236 | |||
1237 | /** |
||
1238 | * Allows management of publicize connections. |
||
1239 | * |
||
1240 | * ## OPTIONS |
||
1241 | * |
||
1242 | * <list|disconnect> |
||
1243 | * : The action to perform. |
||
1244 | * --- |
||
1245 | * options: |
||
1246 | * - list |
||
1247 | * - disconnect |
||
1248 | * --- |
||
1249 | * |
||
1250 | * [<identifier>] |
||
1251 | * : The connection ID or service to perform an action on. |
||
1252 | * |
||
1253 | * [--format=<format>] |
||
1254 | * : Allows overriding the output of the command when listing connections. |
||
1255 | * --- |
||
1256 | * default: table |
||
1257 | * options: |
||
1258 | * - table |
||
1259 | * - json |
||
1260 | * - csv |
||
1261 | * - yaml |
||
1262 | * - ids |
||
1263 | * - count |
||
1264 | * --- |
||
1265 | * |
||
1266 | * ## EXAMPLES |
||
1267 | * |
||
1268 | * # List all publicize connections. |
||
1269 | * $ wp jetpack publicize list |
||
1270 | * |
||
1271 | * # List publicize connections for a given service. |
||
1272 | * $ wp jetpack publicize list twitter |
||
1273 | * |
||
1274 | * # List all publicize connections for a given user. |
||
1275 | * $ wp --user=1 jetpack publicize list |
||
1276 | * |
||
1277 | * # List all publicize connections for a given user and service. |
||
1278 | * $ wp --user=1 jetpack publicize list twitter |
||
1279 | * |
||
1280 | * # Display details for a given connection. |
||
1281 | * $ wp jetpack publicize list 123456 |
||
1282 | * |
||
1283 | * # Diconnection a given connection. |
||
1284 | * $ wp jetpack publicize disconnect 123456 |
||
1285 | * |
||
1286 | * # Disconnect all connections. |
||
1287 | * $ wp jetpack publicize disconnect all |
||
1288 | * |
||
1289 | * # Disconnect all connections for a given service. |
||
1290 | * $ wp jetpack publicize disconnect twitter |
||
1291 | */ |
||
1292 | public function publicize( $args, $named_args ) { |
||
1465 | |||
1466 | private function get_api_host() { |
||
1470 | |||
1471 | private function partner_provision_error( $error ) { |
||
1479 | |||
1480 | /** |
||
1481 | * Creates the essential files in Jetpack to start building a Gutenberg block. |
||
1482 | * |
||
1483 | * All files will be created in a directory under extensions/blocks named based on the block title or a specific given slug. |
||
1484 | * |
||
1485 | * ## OPTIONS |
||
1486 | * |
||
1487 | * title : Block name, also used to create the slug and the edit PHP class name. |
||
1488 | * If it's something like "Logo gallery", the slug will be 'logo-gallery' and the class name will be LogoGalleryEdit. |
||
1489 | * --slug: Specific slug to identify the block that overrides the one generated based on the title. |
||
1490 | * --description: Allows to provide a text description of the block. |
||
1491 | * --keywords: Provide up to three keywords separated by comma so users when they search for a block in the editor. |
||
1492 | * |
||
1493 | * ## EXAMPLES |
||
1494 | * |
||
1495 | * wp jetpack block "Cool Block" |
||
1496 | * wp jetpack block "Amazing Rock" --slug="good-music" --description="Rock the best music on your site" |
||
1497 | * wp jetpack block "Jukebox" --keywords="music, audio, media" |
||
1498 | * |
||
1499 | * @subcommand block |
||
1500 | * @synopsis <title> [--slug] [--description] [--keywords] |
||
1501 | */ |
||
1502 | public function block( $args, $assoc_args ) { |
||
1585 | |||
1586 | /** |
||
1587 | * Built the file replacing the placeholders in the template with the data supplied. |
||
1588 | * |
||
1589 | * @param string $template |
||
1590 | * @param array $data |
||
1591 | * |
||
1592 | * @return string mixed |
||
1593 | */ |
||
1594 | private static function render_block_file( $template, $data = array() ) { |
||
1597 | } |
||
1598 | |||
1634 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.