Commit bc079f083fb for woocommerce
commit bc079f083fb21efee87f1b47df7d383cf0ca298e
Author: Herman <KokkieH@users.noreply.github.com>
Date: Tue Mar 24 14:33:52 2026 +0200
Add installed_path fallback in plugin activate step (#63796)
* Add installed_path fallback in activate step to fix unknown_filename errors
- Add fallback in activate_plugin() using installed_path from move_product step
- Add equivalent fallback in activate_theme()
- Fix WP_Error access bug in move_product step where $result['destination'] was accessed on error
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add changefile(s) from automation for the following project(s): woocommerce
* Address review feedback for move_product error handling
- Sanitize error message with esc_html() since it's returned to API clients
- Fix phpcs ignore rationale to target the actual concern (static constant)
- Remove resolved PHPStan baseline entry for WP_Error offset access
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/63796-fix-WCCOM-2367-wccom-auto-install-errors b/plugins/woocommerce/changelog/63796-fix-WCCOM-2367-wccom-auto-install-errors
new file mode 100644
index 00000000000..80ac78bdf65
--- /dev/null
+++ b/plugins/woocommerce/changelog/63796-fix-WCCOM-2367-wccom-auto-install-errors
@@ -0,0 +1,4 @@
+Significance: minor
+Type: fix
+
+Adds a fallback path to the plugin file during plugin activation step. Prevents `unknown_filename` error when trying to activate a plugin during the auto-installation flow.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-activate-product.php b/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-activate-product.php
index a14adf25a50..9ead1a4eaa1 100644
--- a/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-activate-product.php
+++ b/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-activate-product.php
@@ -75,6 +75,13 @@ class WC_WCCOM_Site_Installation_Step_Activate_Product implements WC_WCCOM_Site_
$filename = is_array( $plugins ) && ! empty( $plugins ) ? key( $plugins ) : '';
}
+ // Fallback: use installed_path from the move_product step.
+ if ( empty( $filename ) && ! empty( $this->state->get_installed_path() ) ) {
+ $filename = \WC_WCCOM_Site_Installer::get_wporg_plugin_main_file(
+ basename( $this->state->get_installed_path() )
+ );
+ }
+
if ( empty( $filename ) ) {
throw new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
}
@@ -120,6 +127,11 @@ class WC_WCCOM_Site_Installation_Step_Activate_Product implements WC_WCCOM_Site_
$theme_slug = is_array( $themes ) && ! empty( $themes ) ? dirname( key( $themes ) ) : '';
}
+ // Fallback: use installed_path from the move_product step.
+ if ( empty( $theme_slug ) && ! empty( $this->state->get_installed_path() ) ) {
+ $theme_slug = basename( $this->state->get_installed_path() );
+ }
+
if ( empty( $theme_slug ) ) {
throw new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
}
diff --git a/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-move-product.php b/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-move-product.php
index 676ea77c4cd..461b2710f41 100644
--- a/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-move-product.php
+++ b/plugins/woocommerce/includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-move-product.php
@@ -6,6 +6,9 @@
* @since 7.7.0
*/
+use WC_REST_WCCOM_Site_Installer_Error_Codes as Installer_Error_Codes;
+use WC_REST_WCCOM_Site_Installer_Error as Installer_Error;
+
defined( 'ABSPATH' ) || exit;
/**
@@ -30,6 +33,8 @@ class WC_WCCOM_Site_Installation_Step_Move_Product implements WC_WCCOM_Site_Inst
/**
* Run the step installation process.
+ *
+ * @throws WC_REST_WCCOM_Site_Installer_Error If installation failed.
*/
public function run() {
$upgrader = WC_WCCOM_Site_Installer::get_wp_upgrader();
@@ -64,11 +69,12 @@ class WC_WCCOM_Site_Installation_Step_Move_Product implements WC_WCCOM_Site_Inst
return $this->state;
}
- if ( ! is_wp_error( $result ) ) {
- $this->maybe_connect_theme();
+ if ( is_wp_error( $result ) ) {
+ throw new Installer_Error( Installer_Error_Codes::INSTALLATION_FAILED, esc_html( $result->get_error_message() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Installer_Error_Codes constant is a static string, not unescaped output.
}
$this->state->set_installed_path( $result['destination'] );
+ $this->maybe_connect_theme();
return $this->state;
}
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 3d8dd1750f2..5831eb14c78 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -37215,12 +37215,6 @@ parameters:
count: 1
path: includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-get-product-info.php
- -
- message: '#^Cannot access offset ''destination'' on array\|WP_Error\.$#'
- identifier: offsetAccess.nonOffsetAccessible
- count: 1
- path: includes/wccom-site/installation/installation-steps/class-wc-wccom-site-installation-step-move-product.php
-
-
message: '#^Method WC_WCCOM_Site_Installation_Step_Move_Product\:\:run\(\) has no return type specified\.$#'
identifier: missingType.return