diff --git src/bp-core/classes/class-bp-attachment.php src/bp-core/classes/class-bp-attachment.php
index f24dabc..c91b09d 100644
|
|
|
abstract class BP_Attachment { |
| 34 | 34 | * @var array |
| 35 | 35 | */ |
| 36 | 36 | protected $default_args = array( |
| 37 | | 'original_max_filesize' => 0, |
| 38 | | 'allowed_mime_types' => array(), |
| 39 | | 'base_dir' => '', |
| 40 | | 'action' => '', |
| 41 | | 'file_input' => '', |
| 42 | | 'upload_error_strings' => array(), |
| 43 | | 'required_wp_files' => array( 'file' ), |
| | 37 | 'original_max_filesize' => 0, |
| | 38 | 'allowed_mime_types' => array(), |
| | 39 | 'base_dir' => '', |
| | 40 | 'action' => '', |
| | 41 | 'file_input' => '', |
| | 42 | 'upload_error_strings' => array(), |
| | 43 | 'required_wp_files' => array( 'file' ), |
| | 44 | 'upload_dir_filter_args' => 0, |
| 44 | 45 | ); |
| 45 | 46 | |
| 46 | 47 | /** |
| … |
… |
abstract class BP_Attachment { |
| 91 | 92 | } elseif ( 'base_dir' === $key ) { |
| 92 | 93 | $this->{$key} = sanitize_title( $param ); |
| 93 | 94 | |
| | 95 | // Sanitize the upload dir filter arg to pass |
| | 96 | } elseif ( 'upload_dir_filter_args' === $key ) { |
| | 97 | $this->{$key} = (int) $param; |
| | 98 | |
| 94 | 99 | // Action & File input are already set and sanitized |
| 95 | 100 | } elseif ( 'action' !== $key && 'file_input' !== $key ) { |
| 96 | 101 | $this->{$key} = $param; |
| … |
… |
abstract class BP_Attachment { |
| 268 | 273 | |
| 269 | 274 | // Make sure the file will be uploaded in the attachment directory |
| 270 | 275 | if ( ! empty( $upload_dir_filter ) ) { |
| 271 | | add_filter( 'upload_dir', $upload_dir_filter, 10, 0 ); |
| | 276 | add_filter( 'upload_dir', $upload_dir_filter, 10, $this->upload_dir_filter_args ); |
| 272 | 277 | } |
| 273 | 278 | |
| 274 | 279 | // Upload the attachment |
| … |
… |
abstract class BP_Attachment { |
| 276 | 281 | |
| 277 | 282 | // Restore WordPress Uploads data |
| 278 | 283 | if ( ! empty( $upload_dir_filter ) ) { |
| 279 | | remove_filter( 'upload_dir', $upload_dir_filter, 10, 0 ); |
| | 284 | remove_filter( 'upload_dir', $upload_dir_filter, 10, $this->upload_dir_filter_args ); |
| 280 | 285 | } |
| 281 | 286 | |
| 282 | 287 | // Remove the pre WordPress 4.0 static filter |
| … |
… |
abstract class BP_Attachment { |
| 344 | 349 | /** |
| 345 | 350 | * Default filter to save the attachments. |
| 346 | 351 | * |
| 347 | | * @since BuddyPress (2.3.0) |
| | 352 | * @since 2.3.0 |
| | 353 | * @since 2.4.0 Added `$upload_dir_data` parameter |
| 348 | 354 | * |
| 349 | 355 | * @uses apply_filters() call 'bp_attachment_upload_dir' to eventually override the upload location |
| 350 | 356 | * regarding to context |
| 351 | 357 | * |
| | 358 | * @param array $upload_dir_data The original upload directory data. |
| 352 | 359 | * @return array The upload directory data. |
| 353 | 360 | */ |
| 354 | | public function upload_dir_filter() { |
| | 361 | public function upload_dir_filter( $upload_dir_data = array() ) { |
| 355 | 362 | |
| 356 | 363 | /** |
| 357 | 364 | * Filters the component's upload directory. |
| … |
… |
abstract class BP_Attachment { |
| 367 | 374 | 'basedir' => $this->upload_path, |
| 368 | 375 | 'baseurl' => $this->url, |
| 369 | 376 | 'error' => false |
| 370 | | ) ); |
| | 377 | ), $upload_dir_data ); |
| 371 | 378 | } |
| 372 | 379 | |
| 373 | 380 | /** |
diff --git tests/phpunit/testcases/core/class-bp-attachment.php tests/phpunit/testcases/core/class-bp-attachment.php
index f6e7d13..5914a9f 100644
|
|
|
class BP_Tests_BP_Attachment_TestCases extends BP_UnitTestCase { |
| 328 | 328 | // clean up! |
| 329 | 329 | $this->clean_files(); |
| 330 | 330 | } |
| | 331 | |
| | 332 | /** |
| | 333 | * @group upload |
| | 334 | * @group avatar |
| | 335 | */ |
| | 336 | public function test_bp_attachment_upload_dir_filter_arg() { |
| | 337 | $attachment_class = new BPTest_Attachment_Extension( array( |
| | 338 | 'action' => 'attachment_action', |
| | 339 | 'file_input' => 'attachment_file_input', |
| | 340 | 'base_dir' => 'attachment_base_dir', |
| | 341 | 'upload_dir_filter_args' => 1, |
| | 342 | ) ); |
| | 343 | |
| | 344 | $this->assertTrue( 1 === $attachment_class->upload_dir_filter_args ); |
| | 345 | |
| | 346 | $avatar_attachment = new BP_Attachment_Avatar(); |
| | 347 | |
| | 348 | $this->assertTrue( 0 === $avatar_attachment->upload_dir_filter_args ); |
| | 349 | } |
| 331 | 350 | } |