Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#39185 closed defect (bug) (wontfix)

REST API Media end-point, "description" field changes with WP 4.7

Reported by: patchworkboy's profile patchworkboy Owned by: joehoyle's profile joehoyle
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords:
Focuses: rest-api Cc:

Description

Previously in the JSON response from querying wp-json/wp/v2/media, the description field contained the textual description as entered in the relevant field within WP-Admin Media Library.

"description":"Site Banner"

Now it returns a render.

"description":{"rendered":"<p class=\"attachment\"><a href='http:\/\/www.accordmat.org.uk\/wp\/wp-content\/uploads\/2016\/12\/site-banner.jpg'><img width=\"300\" height=\"138\" src=\"http:\/\/www.accordmat.org.uk\/wp\/wp-content\/uploads\/2016\/12\/site-banner-300x138.jpg\" class=\"attachment-medium size-medium\" alt=\"Accord MAT Site Banner\" srcset=\"http:\/\/www.accordmat.org.uk\/wp\/wp-content\/uploads\/2016\/12\/site-banner-300x138.jpg 300w, http:\/\/www.accordmat.org.uk\/wp\/wp-content\/uploads\/2016\/12\/site-banner-768x354.jpg 768w, http:\/\/www.accordmat.org.uk\/wp\/wp-content\/uploads\/2016\/12\/site-banner-1024x472.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Site Banner<\/p>\n”}

Whilst I understand that this is to keep consistency with other endpoints, I would EXPECT the content of a media description (such as my example above) render to contain:

"description":{"rendered":"<p>Site Banner<\/p>\n"}

Including the media itself as an attachment doesn't really comply with the idea of a piece of media's description.

Change History (6)

#1 @patchworkboy
8 years ago

PS: As an aside, description for the REST API on the plugins database needs amending to avoid unnecessary end-user confusion - it specifically states:

"All tickets for the project are being tracked on GitHub. You can also take a look at the recent updates for the project."

However, on GitHub I was informed that this isn't the case and that they're being tracked here.

#2 @jnylen0
8 years ago

This is a bit of a weird one. The media description is stored internally as the post_content, and WP uses the content rendering filters to render the attachment image on the original page, which is why it shows up there in the API.

See #38679 for the original change - these fields were pretty broken before it.

I would've liked to make the description of media items appear as you suggested, and add a content: { rendered: ... } field that contains the image display HTML, but we didn't have time. I also don't love the idea of calling it content because that means something else for other post types.

We might be able to get something like this done in 4.7.2, but we would need consensus on an approach and a patch with unit tests.

#3 @jnylen0
8 years ago

Also, this is pretty easy to work around. This will get you just the description in JavaScript:

description.rendered.replace( /^<p class="attachment[^\n]+\n/, '' )

#4 @joehoyle
8 years ago

  • Milestone changed from Awaiting Review to 4.8
  • Owner set to joehoyle
  • Status changed from new to assigned

Hmm @jnylen0 shouldn't we just be removing that filter for the REST API requests? Seems like we shouldn't be including this.

#5 @jnylen0
8 years ago

We decided it was OK as-is. See https://wordpress.slack.com/archives/C02RQC26G/p1478579809001097

If we want to make a further change there are a couple of things to consider:

  • This should be done sooner rather than later due to BC concerns (and I am already concerned it may be too late).
  • This piece of information (the rendered "content" meaning the actual image) should be exposed somewhere.

#6 @joehoyle
8 years ago

  • Milestone 4.8 deleted
  • Resolution set to wontfix
  • Status changed from assigned to closed

@jnylen0 ahh cool, missed that. Ok, I'll go with that too. If we need to expose the image elsewhere anyway then I think this is ok.

Closing as #wontfix.

Note: See TracTickets for help on using tickets.