← All changes
|
lib/media/class-gutenberg-rest-attachments-controller.php
+17
-2
23.9.0
→
trunk
View file →
| @@ -1739,8 +1739,23 @@ | ||
| 1739 | 1739 | if ( isset( $request['_fields'] ) ) { |
| 1740 | 1740 | $response_request['_fields'] = $request['_fields']; |
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | + /* | |
| 1744 | + * Re-read the post. The 'wp_generate_attachment_metadata' filter above | |
| 1745 | + * runs long after $post was fetched, and a callback that rewrites the | |
| 1746 | + * post row - an optimizer changing post_mime_type once it has | |
| 1747 | + * converted the file, say - would otherwise be missing from this | |
| 1748 | + * response. The editor stores the response as its copy of the record | |
| 1749 | + * rather than reading the attachment again, so a stale row here is | |
| 1750 | + * what it keeps. A callback that deleted the attachment instead leaves | |
| 1751 | + * nothing to respond with, so that is reported as the error it is. | |
| 1752 | + */ | |
| 1753 | + $post = $this->get_post( $attachment_id ); | |
| 1754 | + if ( is_wp_error( $post ) ) { | |
| 1755 | + return $post; | |
| 1756 | + } | |
| 1757 | + | |
| 1743 | 1758 | return $this->prepare_item_for_response( $post, $response_request ); |
| 1744 | 1759 | } |
| 1745 | 1760 | |
| 1746 | 1761 | /** |
| @@ -1755,10 +1770,10 @@ | ||
| 1755 | 1770 | * wp_get_image_encode_quality() is proposed for WordPress core in |
| 1756 | 1771 | * https://github.com/WordPress/wordpress-develop/pull/11856; until it lands |
| 1757 | 1772 | * the function_exists() guard falls back to the inline implementation below. |
| 1758 | 1773 | * |
| 1759 | - * @param non-empty-string $mime_type The output image MIME type, e.g. 'image/jpeg'. | |
| 1760 | - * @param array{ width?: non-negative-int, height?: non-negative-int } $size Dimensions ('width', 'height') for the wp_editor_set_quality filter. | |
| 1774 | + * @param non-empty-string $mime_type The output image MIME type, e.g. 'image/jpeg'. | |
| 1775 | + * @param array{ width?: non-negative-int, height?: non-negative-int } $size Dimensions ('width', 'height') for the wp_editor_set_quality filter. | |
| 1761 | 1776 | * @return int<1, 100> Encode quality between 1 and 100. |
| 1762 | 1777 | */ |
| 1763 | 1778 | private function get_image_encode_quality( string $mime_type, array $size = array() ): int { |
| 1764 | 1779 | if ( function_exists( 'wp_get_image_encode_quality' ) ) { |