@@ -33,6 +33,12 @@ class WP_CLI_QIT_Dev_Command {
3333 * @param array $assoc_args Associative arguments passed to the command.
3434 */
3535 public function qit_jetpack_connection ( array $ args , array $ assoc_args ): void {
36+ // Safety check: Only allow in local/development environments.
37+ $ environment_type = function_exists ( 'wp_get_environment_type ' ) ? wp_get_environment_type () : 'production ' ;
38+ if ( 'local ' !== $ environment_type && 'development ' !== $ environment_type ) {
39+ \WP_CLI ::error ( 'This command can only be run in local or development environments for safety. ' );
40+ }
41+
3642 if ( empty ( $ args [0 ] ) || ! is_numeric ( $ args [0 ] ) ) {
3743 \WP_CLI ::error ( 'Please provide a numeric blog ID. ' );
3844 }
@@ -71,6 +77,36 @@ public function qit_jetpack_connection( array $args, array $assoc_args ): void {
7177 \WP_CLI ::line ( 'Account data fetched from server based on Jetpack connection ' );
7278 }
7379
80+ /**
81+ * Shows Jetpack connection status for WooPayments QIT testing.
82+ *
83+ * @when after_wp_load
84+ */
85+ public function qit_jetpack_status (): void {
86+ // Safety check: Only allow in local/development environments.
87+ $ environment_type = function_exists ( 'wp_get_environment_type ' ) ? wp_get_environment_type () : 'production ' ;
88+ if ( 'local ' !== $ environment_type && 'development ' !== $ environment_type ) {
89+ \WP_CLI ::error ( 'This command can only be run in local or development environments for safety. ' );
90+ }
91+
92+ \WP_CLI ::line ( '=== QIT Jetpack Connection Status === ' );
93+
94+ if ( class_exists ( 'Jetpack_Options ' ) ) {
95+ $ blog_id = Jetpack_Options::get_option ( 'id ' );
96+ \WP_CLI ::line ( 'Blog ID: ' . ( $ blog_id ? $ blog_id : 'Not Set ' ) );
97+ }
98+
99+ if ( class_exists ( 'WC_Payments ' ) ) {
100+ $ database_cache = \WC_Payments::get_database_cache ();
101+ if ( $ database_cache ) {
102+ $ account_data = $ database_cache ->get ( Database_Cache::ACCOUNT_KEY );
103+ \WP_CLI ::line ( 'Account Data: ' . ( $ account_data ? 'Present ' : 'Not Set ' ) );
104+ }
105+ }
106+
107+ \WP_CLI ::line ( 'Dev Mode: ' . ( get_option ( 'wcpaydev_dev_mode ' ) ? 'Enabled ' : 'Disabled ' ) );
108+ }
109+
74110 /**
75111 * Configures Jetpack connection options.
76112 *
@@ -104,6 +140,23 @@ private function enable_dev_mode(): void {
104140
105141 /**
106142 * Forces WCP test mode by setting filters and gateway settings.
143+ *
144+ * DEFENSE IN DEPTH STRATEGY:
145+ * This method uses multiple independent mechanisms to ensure test mode is active.
146+ * While WP_ENVIRONMENT_TYPE=development automatically enables dev mode (see WCPay\Core\Mode),
147+ * we explicitly set test mode through multiple layers for maximum safety:
148+ *
149+ * 1. WordPress filters - Override mode detection at runtime
150+ * 2. Gateway settings - Persist test mode in database
151+ * 3. Onboarding service - Set test mode at service layer
152+ *
153+ * This redundancy protects against:
154+ * - Changes to Mode class logic
155+ * - Filter overrides by other code
156+ * - Environment variable changes
157+ * - Accidental live mode activation
158+ *
159+ * All mechanisms must fail for live mode to activate - acceptable tradeoff for test safety.
107160 */
108161 private function force_test_mode (): void {
109162 // Force test mode onboarding and test mode since we're using a test account.
@@ -157,28 +210,4 @@ private function refresh_account_data(): void {
157210 \WP_CLI ::warning ( 'Account refresh failed: ' . $ e ->getMessage () );
158211 }
159212 }
160-
161- /**
162- * Shows Jetpack connection status for WooPayments QIT testing.
163- *
164- * @when after_wp_load
165- */
166- public function qit_jetpack_status (): void {
167- \WP_CLI ::line ( '=== QIT Jetpack Connection Status === ' );
168-
169- if ( class_exists ( 'Jetpack_Options ' ) ) {
170- $ blog_id = Jetpack_Options::get_option ( 'id ' );
171- \WP_CLI ::line ( 'Blog ID: ' . ( $ blog_id ? $ blog_id : 'Not Set ' ) );
172- }
173-
174- if ( class_exists ( 'WC_Payments ' ) ) {
175- $ database_cache = \WC_Payments::get_database_cache ();
176- if ( $ database_cache ) {
177- $ account_data = $ database_cache ->get ( Database_Cache::ACCOUNT_KEY );
178- \WP_CLI ::line ( 'Account Data: ' . ( $ account_data ? 'Present ' : 'Not Set ' ) );
179- }
180- }
181-
182- \WP_CLI ::line ( 'Dev Mode: ' . ( get_option ( 'wcpaydev_dev_mode ' ) ? 'Enabled ' : 'Disabled ' ) );
183- }
184213}
0 commit comments