Commit f9dca5f1a14 for woocommerce

commit f9dca5f1a141a45166cd77501d33f4968e95b1f1
Author: Ben Word <ben@benword.com>
Date:   Mon Jul 20 14:48:03 2026 -0600

    Fix `robots.txt` hardcoding `/wp-content/uploads/` path (#64582)

    * Fix robots.txt hardcoding /wp-content/uploads/ path

    * Add changefile(s) from automation for the following project(s): woocommerce

    * Guard against wp_parse_url() returning false in robots_txt()

    * Add changefile(s) from automation for the following project(s): woocommerce

    ---------

    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
    Co-authored-by: Brandon Kraft <public@brandonkraft.com>

diff --git a/plugins/woocommerce/changelog/64582-robots-txt-hardcoded-wp-content b/plugins/woocommerce/changelog/64582-robots-txt-hardcoded-wp-content
new file mode 100644
index 00000000000..b88a4a1f28a
--- /dev/null
+++ b/plugins/woocommerce/changelog/64582-robots-txt-hardcoded-wp-content
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix robots.txt `Disallow` rules pointing at the wrong location on installs that relocate `wp-content` or the uploads directory.
diff --git a/plugins/woocommerce/includes/class-woocommerce.php b/plugins/woocommerce/includes/class-woocommerce.php
index acaf6d55204..cb77d6c0b69 100644
--- a/plugins/woocommerce/includes/class-woocommerce.php
+++ b/plugins/woocommerce/includes/class-woocommerce.php
@@ -1281,8 +1281,9 @@ final class WooCommerce {
 	 * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
 	 */
 	public function robots_txt( $output ) {
-		$site_url = wp_parse_url( site_url() );
-		$path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
+		$upload_dir   = wp_get_upload_dir();
+		$upload_url   = wp_parse_url( $upload_dir['baseurl'] );
+		$uploads_path = ( is_array( $upload_url ) && ! empty( $upload_url['path'] ) ) ? rtrim( $upload_url['path'], '/' ) : '/wp-content/uploads';

 		$lines       = preg_split( '/\r\n|\r|\n/', $output );
 		$agent_index = array_search( 'User-agent: *', $lines, true );
@@ -1298,9 +1299,9 @@ final class WooCommerce {
 			$above[] = 'User-agent: *';
 		}

-		$above[] = "Disallow: $path/wp-content/uploads/wc-logs/";
-		$above[] = "Disallow: $path/wp-content/uploads/woocommerce_transient_files/";
-		$above[] = "Disallow: $path/wp-content/uploads/woocommerce_uploads/";
+		$above[] = "Disallow: $uploads_path/wc-logs/";
+		$above[] = "Disallow: $uploads_path/woocommerce_transient_files/";
+		$above[] = "Disallow: $uploads_path/woocommerce_uploads/";
 		$above[] = 'Disallow: /*?add-to-cart=';
 		$above[] = 'Disallow: /*?*add-to-cart=';