diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php
index f003b65..b9b6140 100644
|
|
|
class BP_Attachment_Avatar extends BP_Attachment { |
| 41 | 41 | 9 => sprintf( __( 'That photo is too big. Please upload one smaller than %s', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), |
| 42 | 42 | 10 => sprintf( _n( 'Please upload only this file type: %s.', 'Please upload only these file types: %s.', count( $allowed_types ), 'buddypress' ), self::get_avatar_types( $allowed_types ) ), |
| 43 | 43 | ), |
| | 44 | |
| | 45 | // Make sure no argument will be passed to our upload dir filters |
| | 46 | 'upload_dir_filter_arg' => 0, |
| 44 | 47 | ) ); |
| 45 | 48 | } |
| 46 | 49 | |
diff --git src/bp-core/classes/class-bp-attachment.php src/bp-core/classes/class-bp-attachment.php
index f24dabc..f233eb7 100644
|
|
|
abstract class BP_Attachment { |
| 41 | 41 | 'file_input' => '', |
| 42 | 42 | 'upload_error_strings' => array(), |
| 43 | 43 | 'required_wp_files' => array( 'file' ), |
| | 44 | 'upload_dir_filter_arg' => 1, |
| 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_arg' === $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_arg ); |
| 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_arg ); |
| 280 | 285 | } |
| 281 | 286 | |
| 282 | 287 | // Remove the pre WordPress 4.0 static filter |
diff --git tests/phpunit/testcases/core/class-bp-attachment.php tests/phpunit/testcases/core/class-bp-attachment.php
index f6e7d13..4789d3f 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 | ) ); |
| | 342 | |
| | 343 | $this->assertTrue( 1 === $attachment_class->upload_dir_filter_arg ); |
| | 344 | |
| | 345 | $avatar_attachment = new BP_Attachment_Avatar(); |
| | 346 | |
| | 347 | $this->assertTrue( 0 === $avatar_attachment->upload_dir_filter_arg ); |
| | 348 | } |
| 331 | 349 | } |