Commit 0ceb21c1c5 for wordpress.org

commit 0ceb21c1c5a90f5dcbe81c9a15e8761b5d2bcdfd
Author: adamsilverstein <adamsilverstein@git.wordpress.org>
Date:   Wed Sep 9 16:19:46 2026 +0000

    Media: Prepare the attachment finalize response from the current post data.

    `finalize_item()` prepares its response from the `$post` fetched before the `wp_generate_attachment_metadata` filter runs, so anything a callback writes to the post row is missing from the response. The editor now stores that response as the attachment record instead of refetching, so re-read the post after the metadata is written and return the `WP_Error` if a callback deleted the attachment. See https://github.com/WordPress/gutenberg/issues/81844 and https://github.com/WordPress/gutenberg/pull/81947.

    Props gregbenz, andrewserong.
    Fixes #66056.


    Built from https://develop.svn.wordpress.org/trunk@63564


    git-svn-id: http://core.svn.wordpress.org/trunk@62740 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index b95b061b33..9807ac9cf1 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
@@ -3453,6 +3453,21 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
 			$response_request['_fields'] = $request['_fields'];
 		}

+		/*
+		 * Re-read the post. The 'wp_generate_attachment_metadata' filter above
+		 * runs long after $post was fetched, and a callback that rewrites the
+		 * post row - an optimizer changing post_mime_type once it has
+		 * converted the file, say - would otherwise be missing from this
+		 * response. The editor stores the response as its copy of the record
+		 * rather than reading the attachment again, so a stale row here is
+		 * what it keeps. A callback that deleted the attachment instead leaves
+		 * nothing to respond with, so that is reported as the error it is.
+		 */
+		$post = $this->get_post( $attachment_id );
+		if ( is_wp_error( $post ) ) {
+			return $post;
+		}
+
 		return $this->prepare_item_for_response( $post, $response_request );
 	}
 }
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 6f2c317165..907ab260a9 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-63563';
+$wp_version = '7.2-alpha-63564';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.