Skip to:
Content

BuddyPress.org

Ticket #6438: 6438.patch

File 6438.patch, 2.1 KB (added by imath, 11 years ago)
  • src/bp-core/classes/class-bp-attachment.php

    diff --git src/bp-core/classes/class-bp-attachment.php src/bp-core/classes/class-bp-attachment.php
    index e4e625f..3e62182 100644
    abstract class BP_Attachment { 
    196196         *
    197197         * @param  array $file               The appropriate entry the from $_FILES superglobal.
    198198         * @param  string $upload_dir_filter A specific filter to be applied to 'upload_dir' (optional).
     199         * @param  string $time              Optional. Time formatted in 'yyyy/mm'. Default null.
    199200         * @uses   wp_handle_upload()        To upload the file
    200201         * @uses   add_filter()              To temporarly overrides WordPress uploads data
    201202         * @uses   remove_filter()           To stop overriding WordPress uploads data
    abstract class BP_Attachment { 
    205206         *                                   On failure, returns an array containing the error message
    206207         *                                   (eg: array( 'error' => $message ) )
    207208         */
    208         public function upload( $file, $upload_dir_filter = '' ) {
     209        public function upload( $file, $upload_dir_filter = '', $time = null ) {
    209210                /**
    210211                 * Upload action and the file input name are required parameters
    211212                 * @see BP_Attachment:__construct()
    abstract class BP_Attachment { 
    264265                }
    265266
    266267                // Make sure the file will be uploaded in the attachment directory
    267                 add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
     268                if ( ! empty( $upload_dir_filter ) ) {
     269                        add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
     270                }
    268271
    269272                // Upload the attachment
    270                 $this->attachment = wp_handle_upload( $file[ $this->file_input ], $overrides );
     273                $this->attachment = wp_handle_upload( $file[ $this->file_input ], $overrides, $time );
    271274
    272275                // Restore WordPress Uploads data
    273                 remove_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
     276                if ( ! empty( $upload_dir_filter ) ) {
     277                        remove_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
     278                }
    274279
    275280                // Remove the pre WordPress 4.0 static filter
    276281                remove_filter( 'wp_handle_upload_prefilter', array( $this, 'validate_upload' ), 10, 1 );