Make WordPress Core

Opened 9 years ago

Last modified 4 years ago

#41977 assigned enhancement

media_handle_upload() un required second parameter

Reported by: Tkama Owned by: antpb
Priority: normal Milestone: Future Release
Component: Media Version: 2.5
Severity: normal Keywords:
Cc: Focuses:

Description

Why second parameter of media_handle_upload( $file_id, $post_id ) is required?

It's better to define it as 0 and make it optional. In some cases it's more convenient! And we lose nothing if do so...

Attachments (1)

41977.diff (1.4 KB ) - added by costdev 4 years ago.
Make the $post_id parameter optional. Default 0.

Download all attachments as: .zip

Change History (9)

#1 @desrosj
7 years ago

  • Component GeneralMedia
  • Keywords close 2nd-opinion added
  • Version 4.8.22.5

Hi @Tkama,

I don't know that there's any real benefit to making this change. Future function calls would no longer require the parameter, but requiring the parameter also requires the developer to make a conscious decision about where the image should be attached, if at all.

Marking as a close candidate, but also for a 2nd-opinion.

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


4 years ago

#3 follow-up: @antpb
4 years ago

  • Milestone Awaiting Review6.2
  • Owner set to antpb
  • Status newassigned

Moving this to 6.2 as this change improves the ease of using the function with little to no potential issues from setting default to 0.

This change should save a developer from having to read the docs to figure out why the function is failing.

#4 @desrosj
4 years ago

  • Keywords close 2nd-opinion removed

Removing the close keyword since @antpb has volunteered to own this one.

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


4 years ago

@costdev
4 years ago

Make the $post_id parameter optional. Default 0.

#6 in reply to: ↑ 3 @azaozz
4 years ago

Replying to antpb:

This change should save a developer from having to read the docs...

Actually I tend to agree with @desrosj comment from 4 years ago:

requiring the parameter also requires the developer to make a conscious decision about where the image should be attached

WP adds context to images and other uploads by saving the post they were uploaded to. This context can be used for many things like permission settings, etc.

Imho would be nice to remind developers to add the post_ID for new uploads if possible.

Version 0, edited 4 years ago by azaozz (next)

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


4 years ago

#8 @costdev
4 years ago

  • Milestone 6.2Future Release

This ticket was discussed during the bug scrub. As this ticket still needs some work and 6.2 Beta 1 is being released today, I'll move this to Future Release.

As the next step seems to be a docs-only change, if this is ready later in the cycle, feel free to pull it back into the milestone.

Additional props: @mukesh27

Note: See TracTickets for help on using tickets.