Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#6336 closed enhancement (fixed)

Improve bp_core_check_avatar_type() and introduce a function to get the allowed avatar types

Reported by: imath Owned by: imath
Milestone: 2.3 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Cc:

Description

During WC London, DJPaul recommended:

  • to improve the i18n of #6278 for the error message when a file is not a supported image file type.
  • bp_core_check_avatar_type (and related functions) should be committed separately and have its own ticket.

I've attached a unit test 'current_check_avatar_type.patch' which is only testing the current bp_core_check_avatar_type(). This unit test requires 2 files i'm not attaching

  • tests/phpunit/assets/files/buddypress_logo.pdf
  • tests/phpunit/assets/files/disc.png

You'll see that the current function is failing the last assertion.

In 01.patch, i'm suggesting 2 new functions :

  • bp_core_get_allowed_avatar_types() which include a filter to restrict image types
  • bp_core_get_allowed_avatar_mimes() to get the corresponding mime types

I think bp_core_check_avatar_type() should use wp_check_filetype_and_ext() to be absolutely sure an image was uploaded.

Attachments (5)

6336.01.patch (4.5 KB) - added by imath 5 years ago.
6336.02.patch (4.7 KB) - added by imath 5 years ago.
6336.02.patch is improving 01.patch
current_check_avatar_type.patch (1.3 KB) - added by imath 5 years ago.
6336.03.patch (6.2 KB) - added by imath 5 years ago.
Adds a unit test for bp_core_get_allowed_avatar_mimes()
6336.04.patch (6.2 KB) - added by imath 5 years ago.
Use mystery-man.jpg and humans.txt instead of adding files in tests assets

Download all attachments as: .zip

Change History (8)

@imath
5 years ago

@imath
5 years ago

6336.02.patch is improving 01.patch

@imath
5 years ago

Adds a unit test for bp_core_get_allowed_avatar_mimes()

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


5 years ago

@imath
5 years ago

Use mystery-man.jpg and humans.txt instead of adding files in tests assets

#2 @imath
5 years ago

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

In 9760:

Improve bp_core_get_allowed_avatar_types(). Make sure to get the file type if the upload was not done using html5

The way we used to check the image file type is not working if the browser is Internet Explorer < 10. In this particular case, the Plupload runtime is falling back to flash and the file type is application/octet-stream. We are now using wp_check_filetype_and_ext() to fix this issue.

You can use the filter bp_core_get_allowed_avatar_types if you wish to *restrict* the avatar image types. Our supported types are: jpg, jpeg, png and gif.

Props DJPaul.

Fixes #6336
See #6290
See #6278

#3 @DJPaul
3 years ago

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