Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#39759 closed enhancement (fixed)

Make $thumbnail_id filterable in embed-content.php

Reported by: ov3rfly's profile Ov3rfly Owned by: ketuchetan's profile ketuchetan
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.4
Component: Embeds Keywords: has-patch good-first-bug needs-testing
Focuses: Cc:

Description

Some images from photo agencies have special terms where/how to publish them. Use outside of the website might be prohibited.

To be able to filter/replace these images (by looking at their title, description, excerpt or similar) a filter in embed-content.php would be helpful.

Currently a theme needs to provide a modified copy of embed-content.php to catch these cases. Other details (size, shape) can be filtered already, but not the image itself.

Suggested endhancement:

		if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
			$thumbnail_id = get_the_ID();
		}
		
		// add this:
		$thumbnail_id = apply_filters( 'embed_thumbnail_id', $thumbnail_id );

		if ( $thumbnail_id ) {

Thanks for considering.

Attachments (6)

39759.patch (479 bytes) - added by Dency 7 years ago.
Added filter for the thumbnail_id
39759.2.patch (547 bytes) - added by jontyravi 7 years ago.
Added doc part for the filter
39759.3.patch (661 bytes) - added by ketuchetan 7 years ago.
Added proper doc and indentation.
updated-39759.patch (548 bytes) - added by Dency 7 years ago.
updated code filter for the thumbnail_id
39759.4.patch (636 bytes) - added by ketuchetan 7 years ago.
39759.5.patch (639 bytes) - added by ketuchetan 7 years ago.
Made the correction in doc

Download all attachments as: .zip

Change History (22)

#1 @swissspidy
7 years ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to Future Release

@Dency
7 years ago

Added filter for the thumbnail_id

#2 @Dency
7 years ago

  • Keywords has-patch added; needs-patch good-first-bug removed

Hi @swissspidy,

I have added the filter for the $thumbnail_id

Thanks,

@jontyravi
7 years ago

Added doc part for the filter

#3 @swissspidy
7 years ago

  • Keywords good-first-bug added
  • Version changed from 4.7.2 to 4.4

@jontyravi @Dency The filter needs to be documented according to our PHP Documentation Standards. Note to use tabs for indentation, not spaces.

@ketuchetan
7 years ago

Added proper doc and indentation.

@Dency
7 years ago

updated code filter for the thumbnail_id

@ketuchetan
7 years ago

#4 @ketuchetan
7 years ago

  • Keywords good-first-bug removed

Hi @swissspidy

I have updated the patch with the proper documentation.

Thanks,

#5 @swissspidy
7 years ago

  • Keywords good-first-bug added
  • Owner set to ketuchetan
  • Status changed from new to assigned

Please note that the good-first-bug keyword is usually not removed. Instead we assign tickets to an individual contributor working on a solution to mark this good-first-bug as claimed.

#6 @swissspidy
7 years ago

  • Milestone changed from Future Release to 4.8

Moving to the milestone for consideration.

Patch needs a few corrections:

  • @since should be 4.8.0, not 4.4. We can't time travel :)
  • filter description needs a trailing dot

@ketuchetan
7 years ago

Made the correction in doc

#7 @ketuchetan
7 years ago

Hi,

I have made the necessary changes as per above comments.

Thanks,

#8 @jbpaul17
7 years ago

  • Keywords needs-testing added

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

#11 @jbpaul17
7 years ago

  • Milestone changed from 4.8 to 4.8.1

Punting to 4.8.1 per today's bug scrub.

#12 @mariusvetrici
7 years ago

I applied the patch to the latest WordPress build, but the "embed-content.php" file doesn't get called if I embed a post in an iframe. So I'm not able to test how this works.

Repro:

  1. in the root of the WordPress, create a simple HTML file with an IFRAME which includes an existing post. Let's say test.html
  2. load http://src.wordpress-develop.dev/test.html -> it displays ok in browser, but the embed-content.php file doesn't get called.

Expected behavior: embed-content.php should get called when the IFRAME is loaded in a browser.

#13 @swissspidy
7 years ago

@mariusvetrici That's not exactly how it works. embed-content.php is used for oEmbed, i.e. when you paste the URL to a post on a single line, or when you manually include the embed code for a post. (check the REST API or get_post_embed_html()). The embed code is an iframe, but the URL for a post looks like example.com/my-post/embed/ instead of example.com/my-post/.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

#15 @SergeyBiryukov
7 years ago

  • Milestone changed from 4.8.1 to 4.9

#16 @SergeyBiryukov
7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 41565:

Embeds: Introduce embed_thumbnail_id filter for thumbnail image ID in the embed template.

Props ketuchetan, Dency, jontyravi, Ov3rfly.
Fixes #39759.

Note: See TracTickets for help on using tickets.