Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

_wp_attachment_metadata.sizes is empty for REST API uploads, but populated correctly when uploading via wp-admin

未关闭
#222 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
冷清
技术栈
azure, php, wordpress
领域
api, backend, cloud

调研方向

首先,使用同一张图片重现 POST /wp/v2/media,并将其附件元数据与 wp-admin 上传路径进行比较。跟踪 REST 上传在生成变体后将 _wp_attachment_metadata 持久化到何处,并以本地文件和 Azure Blob 文件作为证据。对于 REST 上传,当 media_details 包含生成的尺寸、width 和 height 时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Environment
WordPress: 7.0.2
PHP: 8.3.29 (fpm-fcgi)
Server: Linux 6.6.139.1-1.azl3 x86_64
Web Server: nginx 1.28.0
Hosting: Azure App Service
Upload method under investigation: POST /wp/v2/media

Description
When uploading images through the REST API (POST /wp/v2/media), the image variants (thumbnail, medium, large, etc.) are successfully generated and written to both the local wp-content/uploads directory and Azure Blob Storage.
However, the attachment metadata returned by the REST API contains an empty sizes array:

"media_details": {
  "sizes": {}
}

The key point is that uploading the exact same image through the standard wp-admin Media Library uploader works as expected:
Image variants are generated.
_wp_attachment_metadata['sizes'] is correctly populated.
The REST API subsequently returns the expected media_details.sizes.

This suggests the issue is specific to the REST API upload path rather than image generation itself, as the same server, PHP configuration, image editor, and storage backend all work correctly through the admin uploader.

Steps to Reproduce

  1. Upload an image using POST /wp/v2/media.
  2. Inspect the response.
  3. Observe that media_details.sizes is an empty object ({}).
  4. Verify that the variant image files exist in both:
  • wp-content/uploads
  • Azure Blob Storage
  1. Upload the same image through the wp-admin Media Library.
  2. Observe that media_details.sizes is correctly populated.

Expected Behaviour
media_details.sizes should contain the generated image variants regardless of whether the image was uploaded through the REST API or via wp-admin.

Actual Behaviour
When uploaded via the REST API:
✅ Image variants are physically generated.
✅ Variant files exist locally and in Azure Blob Storage.
❌ _wp_attachment_metadata['sizes'] is empty.
❌ media_details.sizes in the REST response is {}.

When uploaded through wp-admin:
✅ Image variants are generated.
✅ _wp_attachment_metadata['sizes'] is populated correctly.
✅ media_details.sizes is returned as expected.

Question

Does anyone have any ideas what could be causing this behaviour?

When uploading via the REST API (POST /wp/v2/media), the image variants are physically generated and stored correctly, but _wp_attachment_metadata['sizes'] is empty. As a result, the REST response also returns an empty media_details.sizes, and even the top-level width and height values in media_details are empty.

Uploading the exact same image via wp-admin correctly populates all of this metadata.

Is there a known reason why the metadata would not be populated when uploading through the REST API, even though the variant images are successfully generated?

主要语言
HCL
星标
139
派生
84
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/wordpress-linux-appservice 的其他 Issue

查看 Azure/wordpress-linux-appservice 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。