PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 10.5.3
Jetpack – WP Security, Backup, Speed, & Growth v10.5.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
← All changes | class.jetpack-cli.php +131 -224 12.6.410.5.3 View file →
@@ -1,16 +1,10 @@
1 -<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 -/**
3 - * WP-CLI command class.
4 - *
5 - * @package automattic/jetpack
6 - */
1 +<?php
7 2
8 3 use Automattic\Jetpack\Connection\Client;
9 4 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
10 5 use Automattic\Jetpack\Connection\Tokens;
11 6 use Automattic\Jetpack\Identity_Crisis;
12 -use Automattic\Jetpack\IP\Utils as IP_Utils;
13 7 use Automattic\Jetpack\Status;
14 8 use Automattic\Jetpack\Sync\Actions;
15 9 use Automattic\Jetpack\Sync\Listener;
16 10 use Automattic\Jetpack\Sync\Modules;
@@ -15,14 +9,9 @@
15 9 use Automattic\Jetpack\Sync\Listener;
16 10 use Automattic\Jetpack\Sync\Modules;
17 11 use Automattic\Jetpack\Sync\Queue;
18 12 use Automattic\Jetpack\Sync\Settings;
19 -use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection_Shared_Functions;
20 13
21 -if ( ! class_exists( 'WP_CLI_Command' ) ) {
22 - return;
23 -}
24 -
25 14 WP_CLI::add_command( 'jetpack', 'Jetpack_CLI' );
26 15
27 16 /**
28 17 * Control your local Jetpack installation.
@@ -27,34 +16,12 @@
27 16 /**
28 17 * Control your local Jetpack installation.
29 18 */
30 19 class Jetpack_CLI extends WP_CLI_Command {
31 - /**
32 - * Console escape code for green.
33 - *
34 - * @var string
35 - */
36 - public $green_open = "\033[32m";
37 -
38 - /**
39 - * Console escape code for red.
40 - *
41 - * @var string
42 - */
43 - public $red_open = "\033[31m";
44 -
45 - /**
46 - * Console escape code for yellow.
47 - *
48 - * @var string
49 - */
20 + // Aesthetics.
21 + public $green_open = "\033[32m";
22 + public $red_open = "\033[31m";
50 23 public $yellow_open = "\033[33m";
51 -
52 - /**
53 - * Console escape code to reset coloring.
54 - *
55 - * @var string
56 - */
57 24 public $color_close = "\033[0m";
58 25
59 26 /**
60 27 * Get Jetpack Details
@@ -68,13 +35,11 @@
68 35 * ## EXAMPLES
69 36 *
70 37 * wp jetpack status
71 38 * wp jetpack status full
72 - *
73 - * @param array $args Positional args.
74 39 */
75 - public function status( $args ) {
76 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
40 + public function status( $args, $assoc_args ) {
41 + jetpack_require_lib( 'debugger' );
77 42
78 43 /* translators: %s is the site URL */
79 44 WP_CLI::line( sprintf( __( 'Checking status for %s', 'jetpack' ), esc_url( get_home_url() ) ) );
80 45
@@ -93,9 +58,9 @@
93 58 WP_CLI::success( __( 'Jetpack is currently connected to WordPress.com', 'jetpack' ) );
94 59 } else {
95 60 $error = array();
96 61 foreach ( $cxntests->list_fails() as $fail ) {
97 - $error[] = $fail['name'] . ( empty( $fail['message'] ) ? '' : ': ' . $fail['message'] );
62 + $error[] = $fail['name'] . ': ' . $fail['message'];
98 63 }
99 64 WP_CLI::error_multi_line( $error );
100 65
101 66 $cxntests->output_results_for_cli();
@@ -114,41 +79,41 @@
114 79 * Are they asking for all data?
115 80 *
116 81 * Loop through heartbeat data and organize by priority.
117 82 */
118 - $all_data = ( isset( $args[0] ) && 'full' === $args[0] ) ? 'full' : false;
83 + $all_data = ( isset( $args[0] ) && 'full' == $args[0] ) ? 'full' : false;
119 84 if ( $all_data ) {
120 - // Heartbeat data.
85 + // Heartbeat data
121 86 WP_CLI::line( "\n" . __( 'Additional data: ', 'jetpack' ) );
122 87
123 88 // Get the filtered heartbeat data.
124 - // Filtered so we can color/list by severity.
89 + // Filtered so we can color/list by severity
125 90 $stats = Jetpack::jetpack_check_heartbeat_data();
126 91
127 - // Display red flags first.
92 + // Display red flags first
128 93 foreach ( $stats['bad'] as $stat => $value ) {
129 - WP_CLI::line( sprintf( "$this->red_open%-'.16s %s $this->color_close", $stat, $value ) );
94 + printf( "$this->red_open%-'.16s %s $this->color_close\n", $stat, $value );
130 95 }
131 96
132 - // Display caution warnings next.
97 + // Display caution warnings next
133 98 foreach ( $stats['caution'] as $stat => $value ) {
134 - WP_CLI::line( sprintf( "$this->yellow_open%-'.16s %s $this->color_close", $stat, $value ) );
99 + printf( "$this->yellow_open%-'.16s %s $this->color_close\n", $stat, $value );
135 100 }
136 101
137 102 // The rest of the results are good!
138 103 foreach ( $stats['good'] as $stat => $value ) {
139 104
140 - // Modules should get special spacing for aestetics.
105 + // Modules should get special spacing for aestetics
141 106 if ( strpos( $stat, 'odule-' ) ) {
142 - WP_CLI::line( sprintf( "%-'.30s %s", $stat, $value ) );
143 - usleep( 4000 ); // For dramatic effect lolz.
107 + printf( "%-'.30s %s\n", $stat, $value );
108 + usleep( 4000 ); // For dramatic effect lolz
144 109 continue;
145 110 }
146 - WP_CLI::line( sprintf( "%-'.16s %s", $stat, $value ) );
147 - usleep( 4000 ); // For dramatic effect lolz.
111 + printf( "%-'.16s %s\n", $stat, $value );
112 + usleep( 4000 ); // For dramatic effect lolz
148 113 }
149 114 } else {
150 - // Just the basics.
115 + // Just the basics
151 116 WP_CLI::line( "\n" . _x( "View full status with 'wp jetpack status full'", '"wp jetpack status full" is a command - do not translate', 'jetpack' ) );
152 117 }
153 118 }
154 119
@@ -162,9 +127,9 @@
162 127 * wp jetpack test-connection
163 128 *
164 129 * @subcommand test-connection
165 130 */
166 - public function test_connection() {
131 + public function test_connection( $args, $assoc_args ) {
167 132
168 133 /* translators: %s is the site URL */
169 134 WP_CLI::line( sprintf( __( 'Testing connection for %s', 'jetpack' ), esc_url( get_site_url() ) ) );
170 135
@@ -218,14 +183,10 @@
218 183 * wp jetpack disconnect user username
219 184 * wp jetpack disconnect user email@domain.com
220 185 *
221 186 * @synopsis <blog|user> [<user_identifier>] [--force]
222 - *
223 - * @param array $args Positional args.
224 - * @param array $assoc_args Named args.
225 187 */
226 188 public function disconnect( $args, $assoc_args ) {
227 - $user = null;
228 189 if ( ! Jetpack::is_connection_ready() ) {
229 190 WP_CLI::success( __( 'The site is not currently connected, so nothing to do!', 'jetpack' ) );
230 191 return;
231 192 }
@@ -230,14 +191,14 @@
230 191 return;
231 192 }
232 193
233 194 $action = isset( $args[0] ) ? $args[0] : 'prompt';
234 - if ( ! in_array( $action, array( 'blog', 'user', 'prompt' ), true ) ) {
195 + if ( ! in_array( $action, array( 'blog', 'user', 'prompt' ) ) ) {
235 196 /* translators: %s is a command like "prompt" */
236 197 WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) );
237 198 }
238 199
239 - if ( in_array( $action, array( 'user' ), true ) ) {
200 + if ( in_array( $action, array( 'user' ) ) ) {
240 201 if ( isset( $args[1] ) ) {
241 202 $user_id = $args[1];
242 203 if ( ctype_digit( $user_id ) ) {
243 204 $field = 'id';
@@ -248,10 +209,9 @@
248 209 } else {
249 210 $field = 'login';
250 211 $user_id = sanitize_user( $user_id, true );
251 212 }
252 - $user = get_user_by( $field, $user_id );
253 - if ( ! $user ) {
213 + if ( ! $user = get_user_by( $field, $user_id ) ) {
254 214 WP_CLI::error( __( 'Please specify a valid user.', 'jetpack' ) );
255 215 }
256 216 } else {
257 217 WP_CLI::error( __( 'Please specify a user by either ID, username, or email.', 'jetpack' ) );
@@ -262,9 +222,9 @@
262 222
263 223 switch ( $action ) {
264 224 case 'blog':
265 225 Jetpack::log( 'disconnect' );
266 - ( new Connection_Manager( 'jetpack' ) )->disconnect_site();
226 + Jetpack::disconnect();
267 227 WP_CLI::success(
268 228 sprintf(
269 229 /* translators: %s is the site URL */
270 230 __( 'Jetpack has been successfully disconnected for %s.', 'jetpack' ),
@@ -318,11 +278,8 @@
318 278 * wp jetpack reset modules
319 279 * wp jetpack reset sync-checksum --dry-run --offset=0
320 280 *
321 281 * @synopsis <modules|options|sync-checksum> [--dry-run] [--offset=<offset>]
322 - *
323 - * @param array $args Positional args.
324 - * @param array $assoc_args Named args.
325 282 */
326 283 public function reset( $args, $assoc_args ) {
327 284 $action = isset( $args[0] ) ? $args[0] : 'prompt';
328 285 if ( ! in_array( $action, array( 'options', 'modules', 'sync-checksum' ), true ) ) {
@@ -345,9 +302,9 @@
345 302
346 303 switch ( $action ) {
347 304 case 'options':
348 305 $options_to_reset = Jetpack_Options::get_options_for_reset();
349 - // Reset the Jetpack options.
306 + // Reset the Jetpack options
350 307 WP_CLI::line(
351 308 sprintf(
352 309 /* translators: %s is the site URL */
353 310 __( "Resetting Jetpack Options for %s...\n", 'jetpack' ),
@@ -353,9 +310,9 @@
353 310 __( "Resetting Jetpack Options for %s...\n", 'jetpack' ),
354 311 esc_url( get_site_url() )
355 312 )
356 313 );
357 - sleep( 1 ); // Take a breath.
314 + sleep( 1 ); // Take a breath
358 315 foreach ( $options_to_reset['jp_options'] as $option_to_reset ) {
359 316 if ( ! $is_dry_run ) {
360 317 Jetpack_Options::delete_option( $option_to_reset );
361 318 usleep( 100000 );
@@ -364,11 +321,11 @@
364 321 /* translators: This is the result of an action. The option named %s was reset */
365 322 WP_CLI::success( sprintf( __( '%s option reset', 'jetpack' ), $option_to_reset ) );
366 323 }
367 324
368 - // Reset the WP options.
325 + // Reset the WP options
369 326 WP_CLI::line( __( "Resetting the jetpack options stored in wp_options...\n", 'jetpack' ) );
370 - usleep( 500000 ); // Take a breath.
327 + usleep( 500000 ); // Take a breath
371 328 foreach ( $options_to_reset['wp_options'] as $option_to_reset ) {
372 329 if ( ! $is_dry_run ) {
373 330 delete_option( $option_to_reset );
374 331 usleep( 100000 );
@@ -376,11 +333,11 @@
376 333 /* translators: This is the result of an action. The option named %s was reset */
377 334 WP_CLI::success( sprintf( __( '%s option reset', 'jetpack' ), $option_to_reset ) );
378 335 }
379 336
380 - // Reset to default modules.
337 + // Reset to default modules
381 338 WP_CLI::line( __( "Resetting default modules...\n", 'jetpack' ) );
382 - usleep( 500000 ); // Take a breath.
339 + usleep( 500000 ); // Take a breath
383 340 $default_modules = Jetpack::get_default_modules();
384 341 if ( ! $is_dry_run ) {
385 342 Jetpack::update_active_modules( $default_modules );
386 343 }
@@ -429,9 +386,9 @@
429 386 $option,
430 387 "{$site->domain}{$site->path}"
431 388 )
432 389 );
433 - ++$count_fixes;
390 + $count_fixes++;
434 391 if ( ! $is_dry_run ) {
435 392 /*
436 393 * We could be deleting a lot of options rows at the same time.
437 394 * Allow some time for replication to catch up.
@@ -495,8 +452,9 @@
495 452 "SELECT COUNT(*) FROM $wpdb->options WHERE option_name = %s",
496 453 $option
497 454 )
498 455 );
456 +
499 457 }
500 458
501 459 /**
502 460 * Manage Jetpack Modules
@@ -538,15 +496,11 @@
538 496 * wp jetpack module deactivate stats
539 497 * wp jetpack module toggle stats
540 498 * wp jetpack module activate all
541 499 * wp jetpack module deactivate all
542 - *
543 - * @param array $args Positional args.
544 - * @param array $assoc_args Named args.
545 500 */
546 501 public function module( $args, $assoc_args ) {
547 - $module_slug = null;
548 - $action = isset( $args[0] ) ? $args[0] : 'list';
502 + $action = isset( $args[0] ) ? $args[0] : 'list';
549 503
550 504 if ( isset( $args[1] ) ) {
551 505 $module_slug = $args[1];
552 506 if ( 'all' !== $module_slug && ! Jetpack::is_module( $module_slug ) ) {
@@ -633,18 +587,16 @@
633 587 * wp jetpack protect allow list
634 588 * wp jetpack protect allow clear
635 589 *
636 590 * @synopsis <allow> [<ip|ip_low-ip_high|list|clear>]
637 - *
638 - * @param array $args Positional args.
639 591 */
640 - public function protect( $args ) {
592 + public function protect( $args, $assoc_args ) {
641 593 $action = isset( $args[0] ) ? $args[0] : 'prompt';
642 594 if ( ! in_array( $action, array( 'whitelist', 'allow' ), true ) ) { // Still allow "whitelist" for legacy support.
643 595 /* translators: %s is a command like "prompt" */
644 596 WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) );
645 597 }
646 - // Check if module is active.
598 + // Check if module is active
647 599 if ( ! Jetpack::is_module_active( __FUNCTION__ ) ) {
648 600 /* translators: %s is a module name */
649 601 WP_CLI::error( sprintf( _x( '%1$s is not active. You can activate it with "wp jetpack module activate %2$s"', '"wp jetpack module activate" is a command - do not translate', 'jetpack' ), __FUNCTION__, __FUNCTION__ ) );
650 602 }
@@ -661,17 +613,17 @@
661 613 $new_ip = $args[1];
662 614 $current_allow = get_site_option( 'jetpack_protect_whitelist', array() ); // @todo Update the option name.
663 615
664 616 // Build array of IPs that are already on the allowed list.
665 - // Re-build manually instead of using jetpack_protect_format_allow_list() so we can easily get
666 - // low & high range params for IP_Utils::ip_address_is_in_range().
617 + // Re-build manually instead of using jetpack_protect_format_whitelist() so we can easily get
618 + // low & high range params for jetpack_protect_ip_address_is_in_range();
667 619 foreach ( $current_allow as $allowed ) {
668 620
669 - // IP ranges.
621 + // IP ranges
670 622 if ( $allowed->range ) {
671 623
672 624 // Is it already on the allowed list?
673 - if ( IP_Utils::ip_address_is_in_range( $new_ip, $allowed->range_low, $allowed->range_high ) ) {
625 + if ( jetpack_protect_ip_address_is_in_range( $new_ip, $allowed->range_low, $allowed->range_high ) ) {
674 626 /* translators: %s is an IP address */
675 627 WP_CLI::error( sprintf( __( '%s is already on the always allow list.', 'jetpack' ), $new_ip ) );
676 628 break;
677 629 }
@@ -676,9 +628,9 @@
676 628 break;
677 629 }
678 630 $allow[] = $allowed->range_low . ' - ' . $allowed->range_high;
679 631
680 - } else { // Individual IPs.
632 + } else { // Individual IPs
681 633
682 634 // Check if the IP is already on the allow list (single IP only).
683 635 if ( $new_ip === $allowed->ip_address ) {
684 636 /* translators: %s is an IP address */
@@ -693,9 +645,9 @@
693 645 /*
694 646 * List the allowed IPs.
695 647 * Done here because it's easier to read the $allow array after it's been rebuilt.
696 648 */
697 - if ( isset( $args[1] ) && 'list' === $args[1] ) {
649 + if ( isset( $args[1] ) && 'list' == $args[1] ) {
698 650 if ( ! empty( $allow ) ) {
699 651 WP_CLI::success( __( 'Here are your always allowed IPs:', 'jetpack' ) );
700 652 foreach ( $allow as $ip ) {
701 653 WP_CLI::line( "\t" . str_pad( $ip, 24 ) );
@@ -708,12 +660,12 @@
708 660
709 661 /*
710 662 * Clear the always allow list.
711 663 */
712 - if ( isset( $args[1] ) && 'clear' === $args[1] ) {
664 + if ( isset( $args[1] ) && 'clear' == $args[1] ) {
713 665 if ( ! empty( $allow ) ) {
714 666 $allow = array();
715 - Brute_Force_Protection_Shared_Functions::save_allow_list( $allow ); // @todo Need to update function name in the Protect module.
667 + jetpack_protect_save_whitelist( $allow ); // @todo Need to update function name in the Protect module.
716 668 WP_CLI::success( __( 'Cleared all IPs from the always allow list.', 'jetpack' ) );
717 669 } else {
718 670 WP_CLI::line( __( 'Always allow list is empty.', 'jetpack' ) );
719 671 }
@@ -723,9 +675,9 @@
723 675 // Append new IP to allow array.
724 676 array_push( $allow, $new_ip );
725 677
726 678 // Save allow list if there are no errors.
727 - $result = Brute_Force_Protection_Shared_Functions::save_allow_list( $allow ); // @todo Need to update function name in the Protect module.
679 + $result = jetpack_protect_save_whitelist( $allow ); // @todo Need to update function name in the Protect module.
728 680 if ( is_wp_error( $result ) ) {
729 681 WP_CLI::error( $result );
730 682 }
731 683
@@ -762,29 +714,27 @@
762 714 * wp jetpack options delete <option_name>
763 715 * wp jetpack options update <option_name> [<option_value>]
764 716 *
765 717 * @synopsis <list|get|delete|update> [<option_name>] [<option_value>]
766 - *
767 - * @param array $args Positional args.
768 718 */
769 - public function options( $args ) {
719 + public function options( $args, $assoc_args ) {
770 720 $action = isset( $args[0] ) ? $args[0] : 'list';
771 721 $safe_to_modify = Jetpack_Options::get_options_for_reset();
772 722
773 723 // Is the option flagged as unsafe?
774 - $flagged = ! in_array( $args[1], $safe_to_modify, true );
724 + $flagged = ! in_array( $args[1], $safe_to_modify );
775 725
776 - if ( ! in_array( $action, array( 'list', 'get', 'delete', 'update' ), true ) ) {
726 + if ( ! in_array( $action, array( 'list', 'get', 'delete', 'update' ) ) ) {
777 727 /* translators: %s is a command like "prompt" */
778 728 WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) );
779 729 }
780 730
781 731 if ( isset( $args[0] ) ) {
782 - if ( 'get' === $args[0] && isset( $args[1] ) ) {
732 + if ( 'get' == $args[0] && isset( $args[1] ) ) {
783 733 $action = 'get';
784 - } elseif ( 'delete' === $args[0] && isset( $args[1] ) ) {
734 + } elseif ( 'delete' == $args[0] && isset( $args[1] ) ) {
785 735 $action = 'delete';
786 - } elseif ( 'update' === $args[0] && isset( $args[1] ) ) {
736 + } elseif ( 'update' == $args[0] && isset( $args[1] ) ) {
787 737 $action = 'update';
788 738 } else {
789 739 $action = 'list';
790 740 }
@@ -789,18 +739,17 @@
789 739 $action = 'list';
790 740 }
791 741 }
792 742
793 - // Bail if the option isn't found.
743 + // Bail if the option isn't found
794 744 $option = isset( $args[1] ) ? Jetpack_Options::get_option( $args[1] ) : false;
795 745 if ( isset( $args[1] ) && ! $option && 'update' !== $args[0] ) {
796 746 WP_CLI::error( __( 'Option not found or is empty. Use "list" to list option names', 'jetpack' ) );
797 747 }
798 748
799 - // Let's print_r the option if it's an array.
800 - // Used in the 'get' and 'list' actions.
801 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
802 - $option = is_array( $option ) ? print_r( $option, true ) : $option;
749 + // Let's print_r the option if it's an array
750 + // Used in the 'get' and 'list' actions
751 + $option = is_array( $option ) ? print_r( $option ) : $option;
803 752
804 753 switch ( $action ) {
805 754 case 'get':
806 755 WP_CLI::success( "\t" . $option );
@@ -830,14 +779,14 @@
830 779 $options_non_compact = Jetpack_Options::get_option_names( 'non_compact' );
831 780 $options_private = Jetpack_Options::get_option_names( 'private' );
832 781 $options = array_merge( $options_compact, $options_non_compact, $options_private );
833 782
834 - // Table headers.
783 + // Table headers
835 784 WP_CLI::line( "\t" . str_pad( __( 'Option', 'jetpack' ), 30 ) . __( 'Value', 'jetpack' ) );
836 785
837 - // List out the options and their values.
838 - // Tell them if the value is empty or not.
839 - // Tell them if it's an array.
786 + // List out the options and their values
787 + // Tell them if the value is empty or not
788 + // Tell them if it's an array
840 789 foreach ( $options as $option ) {
841 790 $value = Jetpack_Options::get_option( $option );
842 791 if ( ! $value ) {
843 792 WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Empty' );
@@ -856,9 +805,9 @@
856 805 WP_CLI::success(
857 806 _x( "Above are your options. You may 'get', 'delete', and 'update' them.", "'get', 'delete', and 'update' are commands - do not translate.", 'jetpack' ) . "\n" .
858 807 str_pad( 'wp jetpack options get', 26 ) . $option_text . "\n" .
859 808 str_pad( 'wp jetpack options delete', 26 ) . $option_text . "\n" .
860 - str_pad( 'wp jetpack options update', 26 ) . "$option_text $value_text\n" .
809 + str_pad( 'wp jetpack options update', 26 ) . "$option_text $value_text" . "\n" .
861 810 _x( "Type 'wp jetpack options' for more info.", "'wp jetpack options' is a command - do not translate.", 'jetpack' ) . "\n"
862 811 );
863 812 break;
864 813 }
@@ -886,11 +835,8 @@
886 835 * wp jetpack sync reset
887 836 * wp jetpack sync reset --queue=full or regular
888 837 *
889 838 * @synopsis <status|start> [--<field>=<value>]
890 - *
891 - * @param array $args Positional args.
892 - * @param array $assoc_args Named args.
893 839 */
894 840 public function sync( $args, $assoc_args ) {
895 841
896 842 $action = isset( $args[0] ) ? $args[0] : 'status';
@@ -901,9 +847,9 @@
901 847 $collection = array();
902 848 foreach ( $status as $key => $item ) {
903 849 $collection[] = array(
904 850 'option' => $key,
905 - 'value' => is_scalar( $item ) ? $item : wp_json_encode( $item ),
851 + 'value' => is_scalar( $item ) ? $item : json_encode( $item ),
906 852 );
907 853 }
908 854 WP_CLI::log( __( 'Sync Status:', 'jetpack' ) );
909 855 WP_CLI\Utils\format_items( 'table', $collection, array( 'option', 'value' ) );
@@ -909,17 +855,16 @@
909 855 WP_CLI\Utils\format_items( 'table', $collection, array( 'option', 'value' ) );
910 856 break;
911 857 case 'settings':
912 858 WP_CLI::log( __( 'Sync Settings:', 'jetpack' ) );
913 - $settings = array();
914 859 foreach ( Settings::get_settings() as $setting => $item ) {
915 860 $settings[] = array(
916 861 'setting' => $setting,
917 - 'value' => is_scalar( $item ) ? $item : wp_json_encode( $item ),
862 + 'value' => is_scalar( $item ) ? $item : json_encode( $item ),
918 863 );
919 864 }
920 865 WP_CLI\Utils\format_items( 'table', $settings, array( 'setting', 'value' ) );
921 - break;
866 +
922 867 case 'disable':
923 868 // Don't set it via the Settings since that also resets the queues.
924 869 update_option( 'jetpack_sync_settings_disable', 1 );
925 870 /* translators: %s is the site URL */
@@ -988,12 +933,12 @@
988 933 WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. The site is in staging mode.', 'jetpack' ) );
989 934 return;
990 935 }
991 936 }
992 - // Get the original settings so that we can restore them later.
937 + // Get the original settings so that we can restore them later
993 938 $original_settings = Settings::get_settings();
994 939
995 - // Initialize sync settigns so we can sync as quickly as possible.
940 + // Initialize sync settigns so we can sync as quickly as possible
996 941 $sync_settings = wp_parse_args(
997 942 array_intersect_key( $assoc_args, Settings::$valid_settings ),
998 943 array(
999 944 'sync_wait_time' => 0,
@@ -1004,14 +949,14 @@
1004 949 )
1005 950 );
1006 951 Settings::update_settings( $sync_settings );
1007 952
1008 - // Convert comma-delimited string of modules to an array.
953 + // Convert comma-delimited string of modules to an array
1009 954 if ( ! empty( $assoc_args['modules'] ) ) {
1010 955 $modules = array_map( 'trim', explode( ',', $assoc_args['modules'] ) );
1011 956
1012 957 // Convert the array so that the keys are the module name and the value is true to indicate
1013 - // that we want to sync the module.
958 + // that we want to sync the module
1014 959 $modules = array_map( '__return_true', array_flip( $modules ) );
1015 960 }
1016 961
1017 962 foreach ( array( 'posts', 'comments', 'users' ) as $module_name ) {
@@ -1022,9 +967,9 @@
1022 967 ) {
1023 968 $modules['users'] = 'initial';
1024 969 } elseif ( isset( $assoc_args[ $module_name ] ) ) {
1025 970 $ids = explode( ',', $assoc_args[ $module_name ] );
1026 - if ( $ids !== array() ) {
971 + if ( count( $ids ) > 0 ) {
1027 972 $modules[ $module_name ] = $ids;
1028 973 }
1029 974 }
1030 975 }
@@ -1032,13 +977,13 @@
1032 977 if ( empty( $modules ) ) {
1033 978 $modules = null;
1034 979 }
1035 980
1036 - // Kick off a full sync.
981 + // Kick off a full sync
1037 982 if ( Actions::do_full_sync( $modules ) ) {
1038 983 if ( $modules ) {
1039 984 /* translators: %s is a comma separated list of Jetpack modules */
1040 - WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), implode( ', ', array_keys( $modules ) ) ) );
985 + WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), join( ', ', array_keys( $modules ) ) ) );
1041 986 } else {
1042 987 WP_CLI::log( __( 'Initialized a new full sync', 'jetpack' ) );
1043 988 }
1044 989 } else {
@@ -1047,26 +992,26 @@
1047 992 Settings::update_settings( $original_settings );
1048 993
1049 994 if ( $modules ) {
1050 995 /* translators: %s is a comma separated list of Jetpack modules */
1051 - WP_CLI::error( sprintf( __( 'Could not start a new full sync with modules: %s', 'jetpack' ), implode( ', ', $modules ) ) );
996 + WP_CLI::error( sprintf( __( 'Could not start a new full sync with modules: %s', 'jetpack' ), join( ', ', $modules ) ) );
1052 997 } else {
1053 998 WP_CLI::error( __( 'Could not start a new full sync', 'jetpack' ) );
1054 999 }
1055 1000 }
1056 1001
1057 - // Keep sending to WPCOM until there's nothing to send.
1002 + // Keep sending to WPCOM until there's nothing to send
1058 1003 $i = 1;
1059 1004 do {
1060 1005 $result = Actions::$sender->do_full_sync();
1061 1006 if ( is_wp_error( $result ) ) {
1062 - $queue_empty_error = ( 'empty_queue_full_sync' === $result->get_error_code() );
1063 - if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 === $i ) ) ) {
1007 + $queue_empty_error = ( 'empty_queue_full_sync' == $result->get_error_code() );
1008 + if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 == $i ) ) ) {
1064 1009 /* translators: %s is an error code */
1065 1010 WP_CLI::error( sprintf( __( 'Sync errored with code: %s', 'jetpack' ), $result->get_error_code() ) );
1066 1011 }
1067 1012 } else {
1068 - if ( 1 === $i ) {
1013 + if ( 1 == $i ) {
1069 1014 WP_CLI::log( __( 'Sent data to WordPress.com', 'jetpack' ) );
1070 1015 } else {
1071 1016 WP_CLI::log( __( 'Sent more data to WordPress.com', 'jetpack' ) );
1072 1017 }
@@ -1075,9 +1020,9 @@
1075 1020 if ( false !== strpos( get_class( Modules::get_module( 'full-sync' ) ), 'Full_Sync_Immediately' ) ) {
1076 1021 sleep( 15 );
1077 1022 }
1078 1023 }
1079 - ++$i;
1024 + $i++;
1080 1025 } while ( $result && ! is_wp_error( $result ) );
1081 1026
1082 1027 // Reset sync settings to original.
1083 1028 Settings::update_settings( $original_settings );
@@ -1098,12 +1043,10 @@
1098 1043 *
1099 1044 * wp jetpack sync_queue full_sync peek
1100 1045 *
1101 1046 * @synopsis <incremental|full_sync> <peek>
1102 - *
1103 - * @param array $args Positional args.
1104 1047 */
1105 - public function sync_queue( $args ) {
1048 + public function sync_queue( $args, $assoc_args ) {
1106 1049 if ( ! Actions::sync_allowed() ) {
1107 1050 WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site.', 'jetpack' ) );
1108 1051 }
1109 1052
@@ -1111,13 +1054,12 @@
1111 1054 $action = isset( $args[1] ) ? $args[1] : 'peek';
1112 1055
1113 1056 // We map the queue name that way we can support more friendly queue names in the commands, but still use
1114 1057 // the queue name that the code expects.
1115 - $allowed_queues = array(
1058 + $queue_name_map = $allowed_queues = array(
1116 1059 'incremental' => 'sync',
1117 1060 'full' => 'full_sync',
1118 1061 );
1119 - $queue_name_map = $allowed_queues;
1120 1062 $mapped_queue_name = isset( $queue_name_map[ $queue_name ] ) ? $queue_name_map[ $queue_name ] : $queue_name;
1121 1063
1122 1064 switch ( $action ) {
1123 1065 case 'peek':
@@ -1131,9 +1073,9 @@
1131 1073 $collection = array();
1132 1074 foreach ( $items as $item ) {
1133 1075 $collection[] = array(
1134 1076 'action' => $item[0],
1135 - 'args' => wp_json_encode( $item[1] ),
1077 + 'args' => json_encode( $item[1] ),
1136 1078 'current_user_id' => $item[2],
1137 1079 'microtime' => $item[3],
1138 1080 'importing' => (string) $item[4],
1139 1081 );
@@ -1163,18 +1105,14 @@
1163 1105 * : JSON blob of WPCOM API token
1164 1106 * [--partner_tracking_id=<partner_tracking_id>]
1165 1107 * : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com
1166 1108 *
1167 - * @synopsis <token_json> [--partner_tracking_id=<partner_tracking_id>]
1168 - *
1169 - * @param array $args Positional args.
1170 - * @param array $named_args Named args.
1109 + * * @synopsis <token_json> [--partner_tracking_id=<partner_tracking_id>]
1171 1110 */
1172 1111 public function partner_cancel( $args, $named_args ) {
1173 1112 list( $token_json ) = $args;
1174 1113
1175 - $token = $token_json ? json_decode( $token_json ) : null;
1176 - if ( ! $token ) {
1114 + if ( ! $token_json || ! ( $token = json_decode( $token_json ) ) ) {
1177 1115 /* translators: %s is the invalid JSON string */
1178 1116 $this->partner_provision_error( new WP_Error( 'missing_access_token', sprintf( __( 'Invalid token JSON: %s', 'jetpack' ), $token_json ) ) );
1179 1117 }
1180 1118
@@ -1260,17 +1198,13 @@
1260 1198 * $ wp jetpack partner_provision '{ some: "json" }' premium 1
1261 1199 * { success: true }
1262 1200 *
1263 1201 * @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>]
1264 - *
1265 - * @param array $args Positional args.
1266 - * @param array $named_args Named args.
1267 1202 */
1268 1203 public function partner_provision( $args, $named_args ) {
1269 1204 list( $token_json ) = $args;
1270 1205
1271 - $token = $token_json ? json_decode( $token_json ) : null;
1272 - if ( ! $token ) {
1206 + if ( ! $token_json || ! ( $token = json_decode( $token_json ) ) ) {
1273 1207 /* translators: %s is the invalid JSON string */
1274 1208 $this->partner_provision_error( new WP_Error( 'missing_access_token', sprintf( __( 'Invalid token JSON: %s', 'jetpack' ), $token_json ) ) );
1275 1209 }
1276 1210
@@ -1289,10 +1223,10 @@
1289 1223
1290 1224 $body_json = Jetpack_Provision::partner_provision( $token->access_token, $named_args );
1291 1225
1292 1226 if ( is_wp_error( $body_json ) ) {
1293 - WP_CLI::error(
1294 - wp_json_encode(
1227 + error_log(
1228 + json_encode(
1295 1229 array(
1296 1230 'success' => false,
1297 1231 'error_code' => $body_json->get_error_code(),
1298 1232 'error_message' => $body_json->get_error_message(),
@@ -1301,9 +1235,9 @@
1301 1235 );
1302 1236 exit( 1 );
1303 1237 }
1304 1238
1305 - WP_CLI::log( wp_json_encode( $body_json ) );
1239 + WP_CLI::log( json_encode( $body_json ) );
1306 1240 }
1307 1241
1308 1242 /**
1309 1243 * Manages your Jetpack sitemap
@@ -1318,11 +1252,8 @@
1318 1252 * wp jetpack sitemap rebuild
1319 1253 *
1320 1254 * @subcommand sitemap
1321 1255 * @synopsis <rebuild> [--purge]
1322 - *
1323 - * @param array $args Positional args.
1324 - * @param array $assoc_args Named args.
1325 1256 */
1326 1257 public function sitemap( $args, $assoc_args ) {
1327 1258 if ( ! Jetpack::is_connection_ready() ) {
1328 1259 WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) );
@@ -1350,11 +1281,8 @@
1350 1281 *
1351 1282 * wp jetpack authorize_user --token=123456789abcdef
1352 1283 *
1353 1284 * @synopsis --token=<value>
1354 - *
1355 - * @param array $args Positional args.
1356 - * @param array $named_args Named args.
1357 1285 */
1358 1286 public function authorize_user( $args, $named_args ) {
1359 1287 if ( ! is_user_logged_in() ) {
1360 1288 WP_CLI::error( __( 'Please select a user to authorize via the --user global argument.', 'jetpack' ) );
@@ -1420,11 +1348,8 @@
1420 1348 *
1421 1349 * ## EXAMPLES
1422 1350 *
1423 1351 * wp jetpack call_api --resource='/sites/%d'
1424 - *
1425 - * @param array $args Positional args.
1426 - * @param array $named_args Named args.
1427 1352 */
1428 1353 public function call_api( $args, $named_args ) {
1429 1354 if ( ! Jetpack::is_connection_ready() ) {
1430 1355 WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) );
@@ -1522,11 +1447,8 @@
1522 1447 * ## EXAMPLES
1523 1448 *
1524 1449 * wp jetpack upload_ssh_creds --host=example.com --ssh-user=example --pass=password
1525 1450 * wp jetpack updload_ssh_creds --host=example.com --ssh-user=example --kpri=key
1526 - *
1527 - * @param array $args Positional args.
1528 - * @param array $named_args Named args.
1529 1451 */
1530 1452 public function upload_ssh_creds( $args, $named_args ) {
1531 1453 if ( ! Jetpack::is_connection_ready() ) {
1532 1454 WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) );
@@ -1614,11 +1536,8 @@
1614 1536 *
1615 1537 * ## EXAMPLES
1616 1538 *
1617 1539 * wp jetpack get_stats
1618 - *
1619 - * @param array $args Positional args.
1620 - * @param array $named_args Named args.
1621 1540 */
1622 1541 public function get_stats( $args, $named_args ) {
1623 1542 $selected_args = array_intersect_key(
1624 1543 $named_args,
@@ -1689,15 +1608,15 @@
1689 1608 * # List all publicize connections.
1690 1609 * $ wp jetpack publicize list
1691 1610 *
1692 1611 * # List publicize connections for a given service.
1693 - * $ wp jetpack publicize list linkedin
1612 + * $ wp jetpack publicize list twitter
1694 1613 *
1695 1614 * # List all publicize connections for a given user.
1696 1615 * $ wp --user=1 jetpack publicize list
1697 1616 *
1698 1617 * # List all publicize connections for a given user and service.
1699 - * $ wp --user=1 jetpack publicize list linkedin
1618 + * $ wp --user=1 jetpack publicize list twitter
1700 1619 *
1701 1620 * # Display details for a given connection.
1702 1621 * $ wp jetpack publicize list 123456
1703 1622 *
@@ -1707,20 +1626,17 @@
1707 1626 * # Disconnect all connections.
1708 1627 * $ wp jetpack publicize disconnect all
1709 1628 *
1710 1629 * # Disconnect all connections for a given service.
1711 - * $ wp jetpack publicize disconnect linkedin
1712 - *
1713 - * @param array $args Positional args.
1714 - * @param array $named_args Named args.
1630 + * $ wp jetpack publicize disconnect twitter
1715 1631 */
1716 1632 public function publicize( $args, $named_args ) {
1717 1633 if ( ! Jetpack::connection()->has_connected_owner() ) {
1718 - WP_CLI::error( __( 'Jetpack Social requires a user-level connection to WordPress.com', 'jetpack' ) );
1634 + WP_CLI::error( __( 'Publicize requires a user-level connection to WordPress.com', 'jetpack' ) );
1719 1635 }
1720 1636
1721 1637 if ( ! Jetpack::is_module_active( 'publicize' ) ) {
1722 - WP_CLI::error( __( 'The Jetpack Social module is not active.', 'jetpack' ) );
1638 + WP_CLI::error( __( 'The publicize module is not active.', 'jetpack' ) );
1723 1639 }
1724 1640
1725 1641 if ( ( new Status() )->is_offline_mode() ) {
1726 1642 if (
@@ -1728,16 +1644,16 @@
1728 1644 ! has_filter( 'jetpack_development_mode' ) &&
1729 1645 ! has_filter( 'jetpack_offline_mode' ) &&
1730 1646 false === strpos( site_url(), '.' )
1731 1647 ) {
1732 - WP_CLI::error( __( "Jetpack is current in offline mode because the site url does not contain a '.', which often occurs when dynamically setting the WP_SITEURL constant. While in offline mode, the Jetpack Social module will not load.", 'jetpack' ) );
1648 + WP_CLI::error( __( "Jetpack is current in offline mode because the site url does not contain a '.', which often occurs when dynamically setting the WP_SITEURL constant. While in offline mode, the publicize module will not load.", 'jetpack' ) );
1733 1649 }
1734 1650
1735 - WP_CLI::error( __( 'Jetpack is currently in offline mode, so the Jetpack Social module will not load.', 'jetpack' ) );
1651 + WP_CLI::error( __( 'Jetpack is currently in offline mode, so the publicize module will not load.', 'jetpack' ) );
1736 1652 }
1737 1653
1738 1654 if ( ! class_exists( 'Publicize' ) ) {
1739 - WP_CLI::error( __( 'The Jetpack Social module is not loaded.', 'jetpack' ) );
1655 + WP_CLI::error( __( 'The publicize module is not loaded.', 'jetpack' ) );
1740 1656 }
1741 1657
1742 1658 $action = $args[0];
1743 1659 $publicize = new Publicize();
@@ -1820,12 +1736,12 @@
1820 1736 // If the connection ID is 'all' then delete all connections. If the connection ID
1821 1737 // matches a service, delete all connections for that service.
1822 1738 if ( 'all' === $identifier || $id_is_service ) {
1823 1739 if ( 'all' === $identifier ) {
1824 - WP_CLI::log( __( "You're about to delete all Jetpack Social connections.", 'jetpack' ) );
1740 + WP_CLI::log( __( "You're about to delete all publicize connections.", 'jetpack' ) );
1825 1741 } else {
1826 1742 /* translators: %s is a lowercase string for a social network. */
1827 - WP_CLI::log( sprintf( __( "You're about to delete all Jetpack Social connections to %s.", 'jetpack' ), $identifier ) );
1743 + WP_CLI::log( sprintf( __( "You're about to delete all publicize connections to %s.", 'jetpack' ), $identifier ) );
1828 1744 }
1829 1745
1830 1746 jetpack_cli_are_you_sure();
1831 1747
@@ -1846,9 +1762,9 @@
1846 1762 $connections = $option_connections[ $service ];
1847 1763 }
1848 1764
1849 1765 if ( ! empty( $connections ) ) {
1850 - $count = is_countable( $connections ) ? count( $connections ) : 0;
1766 + $count = count( $connections );
1851 1767 $progress = \WP_CLI\Utils\make_progress_bar(
1852 1768 /* translators: %s is a lowercase string for a social network. */
1853 1769 sprintf( __( 'Disconnecting all connections to %s.', 'jetpack' ), $service ),
1854 1770 $count
@@ -1858,9 +1774,9 @@
1858 1774 if ( false === $publicize->disconnect( false, $id ) ) {
1859 1775 WP_CLI::error(
1860 1776 sprintf(
1861 1777 /* translators: %1$d is a numeric ID and %2$s is a lowercase string for a social network. */
1862 - __( 'Jetpack Social connection %d could not be disconnected', 'jetpack' ),
1778 + __( 'Publicize connection %d could not be disconnected', 'jetpack' ),
1863 1779 $id
1864 1780 )
1865 1781 );
1866 1782 }
@@ -1870,43 +1786,35 @@
1870 1786
1871 1787 $progress->finish();
1872 1788
1873 1789 if ( 'all' === $service ) {
1874 - WP_CLI::success( __( 'All Jetpack Social connections were successfully disconnected.', 'jetpack' ) );
1790 + WP_CLI::success( __( 'All publicize connections were successfully disconnected.', 'jetpack' ) );
1875 1791 } else {
1876 1792 /* translators: %s is a lowercase string for a social network. */
1877 - WP_CLI::success( __( 'All Jetpack Social connections to %s were successfully disconnected.', 'jetpack' ), $service );
1793 + WP_CLI::success( __( 'All publicize connections to %s were successfully disconnected.', 'jetpack' ), $service );
1878 1794 }
1879 1795 }
1880 - } elseif ( false !== $publicize->disconnect( false, $identifier ) ) {
1881 - /* translators: %d is a numeric ID. Example: 1234. */
1882 - WP_CLI::success( sprintf( __( 'Jetpack Social connection %d has been disconnected.', 'jetpack' ), $identifier ) );
1883 1796 } else {
1884 - /* translators: %d is a numeric ID. Example: 1234. */
1885 - WP_CLI::error( sprintf( __( 'Jetpack Social connection %d could not be disconnected.', 'jetpack' ), $identifier ) );
1797 + if ( false !== $publicize->disconnect( false, $identifier ) ) {
1798 + /* translators: %d is a numeric ID. Example: 1234. */
1799 + WP_CLI::success( sprintf( __( 'Publicize connection %d has been disconnected.', 'jetpack' ), $identifier ) );
1800 + } else {
1801 + /* translators: %d is a numeric ID. Example: 1234. */
1802 + WP_CLI::error( sprintf( __( 'Publicize connection %d could not be disconnected.', 'jetpack' ), $identifier ) );
1803 + }
1886 1804 }
1887 1805 break; // disconnect.
1888 1806 }
1889 1807 }
1890 1808
1891 - /**
1892 - * Get the API host.
1893 - *
1894 - * @return string URL.
1895 - */
1896 1809 private function get_api_host() {
1897 1810 $env_api_host = getenv( 'JETPACK_START_API_HOST', true );
1898 1811 return $env_api_host ? 'https://' . $env_api_host : JETPACK__WPCOM_JSON_API_BASE;
1899 1812 }
1900 1813
1901 - /**
1902 - * Log and exit on a partner provision error.
1903 - *
1904 - * @param WP_Error $error Error.
1905 - */
1906 1814 private function partner_provision_error( $error ) {
1907 1815 WP_CLI::log(
1908 - wp_json_encode(
1816 + json_encode(
1909 1817 array(
1910 1818 'success' => false,
1911 1819 'error_code' => $error->get_error_code(),
1912 1820 'error_message' => $error->get_error_message(),
@@ -2003,22 +1911,22 @@
2003 1911 }
2004 1912
2005 1913 $wp_filesystem->mkdir( $path );
2006 1914
2007 - $has_keywords = isset( $assoc_args['keywords'] );
1915 + $hasKeywords = isset( $assoc_args['keywords'] );
2008 1916
2009 1917 $files = array(
2010 - "$path/$slug.php" => self::render_block_file(
1918 + "$path/$slug.php" => $this->render_block_file(
2011 1919 'block-register-php',
2012 1920 array(
2013 - 'nextVersion' => "\x24\x24next-version$$", // Escapes to hide the string from tools/replace-next-version-tag.sh
2014 1921 'slug' => $slug,
2015 1922 'title' => $title,
2016 1923 'underscoredSlug' => str_replace( '-', '_', $slug ),
2017 1924 'underscoredTitle' => str_replace( ' ', '_', $title ),
1925 + 'jetpackVersion' => substr( JETPACK__VERSION, 0, strpos( JETPACK__VERSION, '.' ) ) . '.x',
2018 1926 )
2019 1927 ),
2020 - "$path/index.js" => self::render_block_file(
1928 + "$path/index.js" => $this->render_block_file(
2021 1929 'block-index-js',
2022 1930 array(
2023 1931 'slug' => $slug,
2024 1932 'title' => $title,
@@ -2024,22 +1932,22 @@
2024 1932 'title' => $title,
2025 1933 'description' => isset( $assoc_args['description'] )
2026 1934 ? $assoc_args['description']
2027 1935 : $title,
2028 - 'keywords' => $has_keywords
1936 + 'keywords' => $hasKeywords
2029 1937 ? array_map(
2030 - function ( $keyword ) {
2031 - // Construction necessary for Mustache lists.
1938 + function( $keyword ) {
1939 + // Construction necessary for Mustache lists
2032 1940 return array( 'keyword' => trim( $keyword ) );
2033 1941 },
2034 1942 explode( ',', $assoc_args['keywords'], 3 )
2035 1943 )
2036 1944 : '',
2037 - 'hasKeywords' => $has_keywords,
1945 + 'hasKeywords' => $hasKeywords,
2038 1946 )
2039 1947 ),
2040 - "$path/editor.js" => self::render_block_file( 'block-editor-js' ),
2041 - "$path/editor.scss" => self::render_block_file(
1948 + "$path/editor.js" => $this->render_block_file( 'block-editor-js' ),
1949 + "$path/editor.scss" => $this->render_block_file(
2042 1950 'block-editor-scss',
2043 1951 array(
2044 1952 'slug' => $slug,
2045 1953 'title' => $title,
@@ -2044,9 +1952,9 @@
2044 1952 'slug' => $slug,
2045 1953 'title' => $title,
2046 1954 )
2047 1955 ),
2048 - "$path/edit.js" => self::render_block_file(
1956 + "$path/edit.js" => $this->render_block_file(
2049 1957 'block-edit-js',
2050 1958 array(
2051 1959 'title' => $title,
2052 1960 'className' => str_replace( ' ', '', ucwords( str_replace( '-', ' ', $slug ) ) ),
@@ -2051,10 +1959,10 @@
2051 1959 'title' => $title,
2052 1960 'className' => str_replace( ' ', '', ucwords( str_replace( '-', ' ', $slug ) ) ),
2053 1961 )
2054 1962 ),
2055 - "$path/icon.js" => self::render_block_file( 'block-icon-js' ),
2056 - "$path/attributes.js" => self::render_block_file( 'block-attributes-js' ),
1963 + "$path/icon.js" => $this->render_block_file( 'block-icon-js' ),
1964 + "$path/attributes.js" => $this->render_block_file( 'block-attributes-js' ),
2057 1965 );
2058 1966
2059 1967 $files_written = array();
2060 1968
@@ -2100,10 +2008,10 @@
2100 2008
2101 2009 if ( 'beta' === $variation || 'experimental' === $variation ) {
2102 2010 $block_constant = sprintf(
2103 2011 /* translators: the placeholder is a constant name */
2104 - esc_html__( 'To load the block, add the constant JETPACK_BLOCKS_VARIATION set to %1$s to your wp-config.php file', 'jetpack' ),
2105 - $variation
2012 + esc_html__( 'To load the block, add the constant %1$s as true to your wp-config.php file', 'jetpack' ),
2013 + ( 'beta' === $variation ? 'JETPACK_BETA_BLOCKS' : 'JETPACK_EXPERIMENTAL_BLOCKS' )
2106 2014 );
2107 2015 } else {
2108 2016 $block_constant = '';
2109 2017 }
@@ -2126,9 +2034,9 @@
2126 2034 $path,
2127 2035 $variation,
2128 2036 $block_list_path,
2129 2037 $block_constant,
2130 - 'https://github.com/Automattic/jetpack/blob/trunk/projects/plugins/jetpack/extensions/README.md#developing-block-editor-extensions-in-jetpack'
2038 + 'https://github.com/Automattic/jetpack/blob/master/extensions/README.md#develop-new-blocks'
2131 2039 ) . '--------------------------------------------------------------------------------------------------------------------'
2132 2040 );
2133 2041 }
2134 2042 }
@@ -2135,10 +2043,11 @@
2135 2043
2136 2044 /**
2137 2045 * Built the file replacing the placeholders in the template with the data supplied.
2138 2046 *
2139 - * @param string $template Template.
2140 - * @param array $data Data.
2047 + * @param string $template
2048 + * @param array $data
2049 + *
2141 2050 * @return string mixed
2142 2051 */
2143 2052 private static function render_block_file( $template, $data = array() ) {
2144 2053 return \WP_CLI\Utils\mustache_render( JETPACK__PLUGIN_DIR . "wp-cli-templates/$template.mustache", $data );
@@ -2144,23 +2053,21 @@
2144 2053 return \WP_CLI\Utils\mustache_render( JETPACK__PLUGIN_DIR . "wp-cli-templates/$template.mustache", $data );
2145 2054 }
2146 2055 }
2147 2056
2148 -// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file.
2149 -
2150 -/**
2057 +/*
2151 2058 * Standard "ask for permission to continue" function.
2152 2059 * If action cancelled, ask if they need help.
2153 2060 *
2154 2061 * Written outside of the class so it's not listed as an executable command w/ 'wp jetpack'
2155 2062 *
2156 - * @param bool $flagged false = normal option | true = flagged by get_jetpack_options_for_reset().
2157 - * @param string $error_msg Error message.
2063 + * @param $flagged bool false = normal option | true = flagged by get_jetpack_options_for_reset()
2064 + * @param $error_msg string (optional)
2158 2065 */
2159 2066 function jetpack_cli_are_you_sure( $flagged = false, $error_msg = false ) {
2160 2067 $cli = new Jetpack_CLI();
2161 2068
2162 - // Default cancellation message.
2069 + // Default cancellation message
2163 2070 if ( ! $error_msg ) {
2164 2071 $error_msg =
2165 2072 __( 'Action cancelled. Have a question?', 'jetpack' )
2166 2073 . ' '
@@ -2177,8 +2084,8 @@
2177 2084
2178 2085 WP_CLI::line( $prompt_message );
2179 2086 $handle = fopen( 'php://stdin', 'r' );
2180 2087 $line = fgets( $handle );
2181 - if ( 'yes' !== trim( $line ) ) {
2088 + if ( 'yes' != trim( $line ) ) {
2182 2089 WP_CLI::error( $error_msg );
2183 2090 }
2184 2091 }