Make WordPress Core

Opened 15 years ago

Closed 10 years ago

#12493 closed enhancement (maybelater)

Filter $bits in wp_upload_bits()

Reported by: viper007bond's profile Viper007Bond Owned by: josephscott's profile josephscott
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Upload Keywords: has-patch mobile needs-docs
Focuses: Cc:

Description

It'd be nice if there was a filter on $bits in wp_upload_bits() to allow plugins to modify uploads coming in from XML-RPC. Resizing, watermarking, etc. are all example uses for this filter.

Since it's a simple filter, perhaps it could be slipped into 3.0.

Attachments (2)

12493.patch (460 bytes) - added by Viper007Bond 15 years ago.
12493.2.patch (471 bytes) - added by Viper007Bond 15 years ago.
Pass the filename so it can be used to determine file type

Download all attachments as: .zip

Change History (15)

@Viper007Bond
15 years ago

#1 @Viper007Bond
15 years ago

To clarify, yes this can be done after the file is saved to the filesystem, but then the thumbnails must be regenerated and the meta data updated. A big hassle.

#2 follow-up: @josephscott
15 years ago

If we are going to do this have you looked at adding a corresponding filter for uploads done via AtomPub?

#3 in reply to: ↑ 2 @Viper007Bond
15 years ago

Replying to josephscott:

If we are going to do this have you looked at adding a corresponding filter for uploads done via AtomPub?

AtomPub uses wp_upload_bits() too, doesn't it?

@Viper007Bond
15 years ago

Pass the filename so it can be used to determine file type

#4 @Viper007Bond
15 years ago

I have thoroughly tested this tonight via XML-RPC and it works awesome. I don't have an AtomPub client though, but I don't see why it wouldn't work as it's the same kinda thing.

#5 @daniloercoli
12 years ago

  • Keywords mobile added

#6 @daniloercoli
12 years ago

  • Cc ercoli@… added

#7 follow-up: @markoheijnen
10 years ago

  • Component changed from XML-RPC to Upload

Moving this outside of XML-RPC since it's also used inside the function wp_generate_attachment_metadata() since [27863].

For the reason this ticket was created I would say close it since I'm unsure we want to filter the original. Image sizes could be done with a custom WP_Image_Editor. That said, adding the filter is easy to do.

#8 in reply to: ↑ 7 ; follow-up: @Viper007Bond
10 years ago

Replying to markoheijnen:

For the reason this ticket was created I would say close it since I'm unsure we want to filter the original.

Actually that's exactly what I wanted to do when it came to watermarking, otherwise the original image could be downloaded from the site. However that makes a tiny watermark on the thumbnails so really the thumbnails should be watermarked on their own by this imaginary plugin and then the original file overwritten with a watermarked version afterwards.

It gets complicated fast but can you ever have too many filters? :)

At the very least allowing resizing massive images, or using crushing techniques, seems like a useful case for this.

#9 @markoheijnen
10 years ago

  • Milestone changed from Future Release to 4.1

Curious how crushing bits looks like but the filter could be a great way to limit the size of the original.

Let's see if we can get this included in 4.1 :)

#10 in reply to: ↑ 8 @nacin
10 years ago

Replying to Viper007Bond:
Yep. Anything that makes it more difficult to be backwards compatible with future changes is usually a good example of a bad filter.

This one seems fairly harmless, but it looks like demand for it is particularly low. Also, actually messing with the bits is kind of low level, no? I'd kind of prefer an action similar to wp_handle_upload (which is actually a filter) that lets you know where the file is upon completion. Unfortunately wp_handle_upload() is not a shining example of hooks as it uses that weird overrides stuff from probably the 1960s.

#11 @markoheijnen
10 years ago

Didn't thought about an action but I do like that idea. Less change to break stuff when filtering and also if you want to use WP_Image_Editor, it only can receive a file anyway.

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


10 years ago

#13 @DrewAPicture
10 years ago

  • Keywords needs-docs added
  • Milestone 4.1 deleted
  • Resolution set to maybelater
  • Status changed from new to closed

Doesn't seem to be a great deal of interest in this filter (or action). Would also need hook docs. Closing as maybelater.

Note: See TracTickets for help on using tickets.