[buddypress-trac] [BuddyPress Trac] #7265: uploads dir should filtered for cover images

buddypress-trac noreply at wordpress.org
Thu Sep 22 01:17:38 UTC 2016


#7265: uploads dir should filtered for cover images
--------------------------+-----------------------------
 Reporter:  m_uysl        |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Core          |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |
--------------------------+-----------------------------
Changes (by boonebgorges):

 * keywords:   => needs-patch
 * milestone:  Awaiting Review => Future Release


Comment:

 Thanks for the ticket, @m_uysl.

 I worked through the problem a bit and it's not straightforward to solve.
 The root issue is, as noted in the description, that the `upload_dir`
 isn't being filtered in a consistent way. When you filter via
 `bp_attachments_cover_image_upload_dir`, the filter is effective during
 `wp_handle_upload()` but not in other places in the API (such as
 `bp_attachments_uploads_dir_get()`).

 There are a handful of places where it's possible that we could run
 `upload_dir` through `upload_dir_filter()`. For example, in
 `bp_attachments_cover_image_ajax_upload()`, we can do the following:

 {{{
         // Get BuddyPress Attachments Uploads Dir datas.
         $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
 +       $bp_attachments_uploads_dir =
 $cover_image_attachment->upload_dir_filter( $bp_attachments_uploads_dir );
 }}}

 This fixes half of the comparisons during the AJAX handler. The other half
 is harder to solve. Later in `bp_attachments_cover_image_generate_file()`,
 we do the following check:

 {{{
 if ( false === $dimensions || $args['file'] !== $args['cover_image_dir'] .
 '/' . wp_basename( $args['file'] ) ) {
     return false;
 }
 }}}

 This check fails without doing some manipulation to the
 `BP_Attachment_Cover_Image` object. That object caches some properties
 (like `base_dir`) in a way that isn't sensitive to the
 `bp_attachments_cover_image_upload_dir` filter.

 This is not a very good explanation (I didn't really get to the bottom of
 things) but it gestures in the direction of a solution, which is to ensure
 the `bp_attachments_cover_image_upload_dir` filter is applied to all ways
 that the cover image object generates its upload paths.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7265#comment:1>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list