WordPress.org

Make WordPress Core

Opened 5 weeks ago

Last modified 18 hours ago

#48477 new enhancement

Add a hook before creating image sub-sizes

Reported by: GregLone Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 5.3
Component: Upload Keywords: has-patch needs-testing 2nd-opinion
Focuses: Cc:
PR Number:

Description

Since things are moving for media thumbnails lately, it could be a good time to add a hook that fires right before thumbnails are created.
It would allow plugins to perform operations on the main file for example.

Attachments (1)

48477.diff (753 bytes) - added by GregLone 5 weeks ago.

Download all attachments as: .zip

Change History (12)

@GregLone
5 weeks ago

#1 @SergeyBiryukov
5 weeks ago

  • Milestone changed from Awaiting Review to 5.3

Moving to the milestone for visibility.

#2 @jorbin
5 weeks ago

  • Milestone changed from 5.3 to 5.3.1

I chatted with @mikeschroder and we discussed that we want to spend some time ensuring that we get the parameters and placement correct for this, so bumping to the .1 release to allow time for the exploration.

#3 @GregLone
4 weeks ago

I understand, I'm late and we're close to the release. Thanks for considering it :)

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


2 weeks ago

#5 @marybaum
2 weeks ago

Ooh I like this!

#6 follow-up: @azaozz
2 weeks ago

  • Keywords reporter-feedback added

It would allow plugins to perform operations on the main file for example.

What would be the intended use there? Currently there are (at least) three hooks fired right after a file was uploaded:

These give full access to all aspects of handling an uploaded file. Do we really need a forth hook specific for images? :)

#7 in reply to: ↑ 6 ; follow-up: @GregLone
2 weeks ago

Replying to azaozz:

Currently there are (at least) three hooks fired right after a file was uploaded:

The idea is not to have a hook that triggers after a file is uploaded but, as the hook’s name suggests, before sub-sizes are created. The difference is that it can happen even if the file wasn’t just uploaded: when a plugin regenerates thumbnails for example.
Currently I’m also thinking adding one after the sub-sizes are created and recorded in the database, maybe at the end of wp_update_attachment_metadata(), with an additional context argument (create/update), like you suggested recently if I remember well.

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


3 days ago

This ticket was mentioned in Slack in #core-media by audrasjb. View the logs.


3 days ago

#10 in reply to: ↑ 7 @azaozz
34 hours ago

  • Keywords reporter-feedback removed
  • Milestone changed from 5.3.1 to 5.4

Replying to GregLone:

Currently I’m also thinking adding one after the sub-sizes are created and recorded in the database, maybe at the end of wp_update_attachment_metadata(), with an additional context argument (create/update), like you suggested recently if I remember well.

Yeah, this can potentially be useful. At the same time I'd prefer not to "rush it" in 5.3.1. Perhaps better to confirm the use cases before adding the hooks. Then a good decisions can be made whether to pass context, etc.

Moving this to 5.4 perhaps pending a revised/updated patch.

#11 @GregLone
18 hours ago

I agree, it will give us time to think a bit more about it.

Note: See TracTickets for help on using tickets.