Skip to:
Content

BuddyPress.org

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#6438 closed defect (bug) (fixed)

BP Attachment API, warning when no base_dir set

Reported by: imath's profile imath Owned by: imath's profile imath
Milestone: 2.3 Priority: high
Severity: normal Version:
Component: Core Keywords: has-patch
Cc:

Description

I've been testing the new BP_Attachment class with a specific case. Well actually it's a case i have to deal with for one of my plugin.

Let's say, you want to use the BP_Attachment class but want to use the WordPress default upload dir. To do so, i haven't specified the base_dir argument of my extending class, but then i get a warning because the `$upload_dir_filter' is empty in this case and the plugin API doesn't find the missing filter.

Then, there's a third parameter we should include to BP_Attachment->upload() method: $time. I can see cases (my plugin for instance) where we need to attach the file to a post type and make sure the file is saved in a WordPress generated subdirectory of the year and month of the post type's date. Just like it's the case when using directly wp_handle_upload().

I suggest to have the patch in before 2.3 release. I'm also adding a unit test.

Attachments (2)

6438.patch (2.1 KB) - added by imath 9 years ago.
6438-unittest.patch (2.8 KB) - added by imath 9 years ago.

Download all attachments as: .zip

Change History (6)

@imath
9 years ago

@imath
9 years ago

#1 @boonebgorges
9 years ago

Looks good to me.

#2 @imath
9 years ago

Thanks a lot for your feedback boonebgorges, i will commit this in a few minutes :)

#3 @imath
9 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 9874:

In BP_Attachment->upload(), only filter the WordPress upload_dir if the callback function is set.

This callback function can be passed as the second argument of BP_Attachment->upload(), or dynamically created if the specific $base_dir parameter was provided by the extending class.

About this second case, if the extending class forgets to set the $base_dir parameter or do it on purpose in order to use the WordPress default upload directory, we will not filter the WordPress upload_dir to avoid a warning.

This commit also adds a third argument to BP_Attachment->upload(), in case there is a need to pass a specific time (yyyy/mm) to set the WordPress default upload sub directory.

Fixes #6438

#4 @DJPaul
8 years ago

  • Component changed from API to Core
Note: See TracTickets for help on using tickets.