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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / cli / class-wc-cli-com-command.php
woocommerce / includes / cli Last commit date
class-wc-cli-com-command.php 3 years ago class-wc-cli-com-extension-command.php 3 years ago class-wc-cli-rest-command.php 3 years ago class-wc-cli-runner.php 3 years ago class-wc-cli-tool-command.php 6 years ago class-wc-cli-tracker-command.php 4 years ago class-wc-cli-update-command.php 3 years ago
class-wc-cli-com-command.php
200 lines
1 <?php
2 /**
3 * WC_CLI_COM_Command class file.
4 *
5 * @package WooCommerce\CLI
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Allows to interact with extensions from WCCOM marketplace via CLI.
14 *
15 * @version 6.8
16 * @package WooCommerce
17 */
18 class WC_CLI_COM_Command {
19 const APPLICATION_PASSWORD_SECTION_URL = 'https://woocommerce.com/my-account/#application-passwords';
20
21 /**
22 * Registers a commands for managing WooCommerce.com extensions.
23 */
24 public static function register_commands() {
25 WP_CLI::add_command( 'wc com extension list', array( 'WC_CLI_COM_Command', 'list_extensions' ) );
26 WP_CLI::add_command( 'wc com disconnect', array( 'WC_CLI_COM_Command', 'disconnect' ) );
27 WP_CLI::add_command( 'wc com connect', array( 'WC_CLI_COM_Command', 'connect' ) );
28 }
29
30 /**
31 * List extensions owned by the connected site
32 *
33 * [--format]
34 * : If set, the command will use the specified format. Possible values are table, json, csv and yaml. By default the table format will be used.
35 *
36 * [--fields]
37 * : If set, the command will show only the specified fields instead of showing all the fields in the output.
38 *
39 * ## EXAMPLES
40 *
41 * # List extensions owned by the connected site in table format with all the fields
42 * $ wp wc com extension list
43 *
44 * # List the product slug of the extension owned by the connected site in csv format
45 * $ wp wc com extension list --format=csv --fields=product_slug
46 *
47 * @param array $args WP-CLI positional arguments.
48 * @param array $assoc_args WP-CLI associative arguments.
49 */
50 public static function list_extensions( array $args, array $assoc_args ) {
51 $data = WC_Helper::get_subscriptions();
52
53 $data = array_values( $data );
54
55 $formatter = new \WP_CLI\Formatter(
56 $assoc_args,
57 array(
58 'product_slug',
59 'product_name',
60 'auto_renew',
61 'expires_on',
62 'expired',
63 'sites_max',
64 'sites_active',
65 'maxed',
66 )
67 );
68
69 $data = array_map(
70 function( $item ) {
71 $product_slug = '';
72 $product_url_parts = explode( '/', $item['product_url'] );
73 if ( count( $product_url_parts ) > 2 ) {
74 $product_slug = $product_url_parts[ count( $product_url_parts ) - 2 ];
75 }
76 return array(
77 'product_slug' => $product_slug,
78 'product_name' => htmlspecialchars_decode( $item['product_name'] ),
79 'auto_renew' => $item['autorenew'] ? 'On' : 'Off',
80 'expires_on' => gmdate( 'Y-m-d', $item['expires'] ),
81 'expired' => $item['expired'] ? 'Yes' : 'No',
82 'sites_max' => $item['sites_max'],
83 'sites_active' => $item['sites_active'],
84 'maxed' => $item['maxed'] ? 'Yes' : 'No',
85 );
86 },
87 $data
88 );
89
90 $formatter->display_items( $data );
91 }
92
93 /**
94 * ## OPTIONS
95 *
96 * [--yes]
97 * : Do not prompt for confirmation.
98 *
99 * ## EXAMPLES
100 *
101 * # Disconnect from site.
102 * $ wp wc com disconnect
103 *
104 * # Disconnect without prompt for confirmation.
105 * $ wp wc com disconnect --yes
106 *
107 * @param array $args Positional arguments to include when calling the command.
108 * @param array $assoc_args Associative arguments to include when calling the command.
109
110 * @return void
111 * @throws \WP_CLI\ExitException If WP_CLI::$capture_exit is true.
112 */
113 public static function disconnect( array $args, array $assoc_args ) {
114 if ( ! WC_Helper::is_site_connected() ) {
115 WP_CLI::error( __( 'Your store is not connected to WooCommerce.com. Run `wp wc com connect` command.', 'woocommerce' ) );
116 }
117
118 WP_CLI::confirm( __( 'Are you sure you want to disconnect your store from WooCommerce.com?', 'woocommerce' ), $assoc_args );
119 WC_Helper::disconnect();
120 WP_CLI::success( __( 'You have successfully disconnected your store from WooCommerce.com', 'woocommerce' ) );
121 }
122
123 /**
124 * Connects to WooCommerce.com with application-password.
125 *
126 * [--password]
127 * : If set, password won't be prompt.
128 *
129 * [--force]
130 * : If set, site will be disconnected and a new connection will be forced.
131 *
132 * ## EXAMPLES
133 *
134 * # Connect to WCCOM using password.
135 * $ wp wc com connect
136 *
137 * # force connecting to WCCOM even if site is already connected.
138 * $ wp wc com connect --force
139 *
140 * # Pass password to comman.
141 * $ wp wc com connect --password=PASSWORD
142 *
143 * @param array $args Positional arguments to include when calling the command.
144 * @param array $assoc_args Associative arguments to include when calling the command.
145 *
146 * @return void
147 * @throws \WP_CLI\ExitException If WP_CLI::$capture_exit is true.
148 */
149 public static function connect( array $args, array $assoc_args ) {
150 $password = \WP_CLI\Utils\get_flag_value( $assoc_args, 'password' );
151 $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
152
153 if ( WC_Helper::is_site_connected() ) {
154 if ( $force ) {
155 WC_Helper::disconnect();
156 } else {
157 WP_CLI::error( __( 'Your store is already connected.', 'woocommerce' ) );
158
159 return;
160 }
161 }
162
163 if ( empty( $password ) ) {
164 // translators: %s is the URL for the application-password section in WooCommerce.com.
165 WP_CLI::log( sprintf( __( 'If you don\'t have an application password (not your account password), generate a password from %s', 'woocommerce' ), esc_url( self::APPLICATION_PASSWORD_SECTION_URL ) ) );
166 $password = self::ask( __( 'Connection password:', 'woocommerce' ) );
167 }
168 $password = sanitize_text_field( $password );
169 if ( empty( $password ) ) {
170 // translators: %s is the URL for the application-password section in WooCommerce.com.
171 WP_CLI::error( sprintf( __( 'Invalid password. Generate a new one from %s.', 'woocommerce' ), esc_url( self::APPLICATION_PASSWORD_SECTION_URL ) ) );
172 }
173
174 $auth = WC_Helper::connect_with_password( $password );
175 if ( is_wp_error( $auth ) ) {
176 WP_CLI::error( $auth->get_error_message() );
177 }
178
179 if ( WC_Helper::is_site_connected() ) {
180 WP_CLI::success( __( 'Store connected successfully.', 'woocommerce' ) );
181 }
182 }
183
184 /**
185 * We are asking a question and returning an answer as a string.
186 *
187 * @param string $question The question being prompt.
188 *
189 * @return string
190 */
191 protected static function ask( $question ) {
192 // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite
193 // Adding space to question and showing it.
194 fwrite( STDOUT, $question . ' ' );
195
196 return trim( fgets( STDIN ) );
197 // phpcs:enable
198 }
199 }
200