Skip to:

Opened 10 years ago

Closed 10 years ago

#5335 closed defect (bug) (no action required)

Problem with Retrieving avatar's

Reported by: vusisindane's profile vusisindane Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.9.1
Component: Core Keywords:


I'm using buddypress 1.9.1 and here's the problem.

After submitting the cropped image, inside wp-core-avatars.php in
bp_core_avatar_handle_crop(), buddypress uses wp_crop_image() to resize.

The trouble is,
--> wordpress uses wp_unique_filename() inside wp_crop_image()

the function santize_file_name() changes the destination file and removes the buddypress suffix "-bpfull" and "-bpthumb" that were added in the bp_core_avatar_handle_crop() function.

So when the cropped images are set, buddypress cannot find them using the bp_core_fetch_avatar() function because it specifically looks for images with those suffixes (-bpthumb & -bpfull) respectively.

So after uploading and cropping an image, I can find it in the directioty "wp-content/uploads/avatar/#/", but bp cannot retrieve it because the file does not have the correct suffix i.e. (-bpthumb or -bpfull).

Hope this makes sense.

Change History (5)

#1 @vusisindane
10 years ago

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

Here's a temporary fix I've come up with.

function fix_crop_avatar(){
	global $bp;

	$dir =  bp_core_get_upload_dir() . "/avatars/" . bp_loggedin_user_id();
	$full_w = bp_core_avatar_full_width();
	$full_h = bp_core_avatar_full_height();

	$thumb_w = bp_core_avatar_thumb_width();
	$thumb_h = bp_core_avatar_thumb_height();


		// open the directory
		if( $av_dir = opendir($dir)) {
			$avatar_files = array();

			while(false !== ($avatar_file = readdir($av_dir))){
				if( 2 < strlen($avatar_file)){
					$avatar_files[] = $avatar_file;

			$dir = trailingslashit($dir);

			if( count($avatar_files) > 0){
				foreach($avatar_files as $key => $value){
					// rename thename of the image depending on the size
					// first collect some data
					if(strpos($value, "-bpfull") === false && strpos($value, "-bpthumb") === false){
						$imgdata = @getimagesize($dir . $value);
						$ext = ($imgdata["mime"] == "image/png") ? "png" : "jpg";
						$split_file = explode(".", $value);

						// this is a thumbnail
						if($imgdata[0] == $thumb_w){
							$newfname = $split_file[0] . "-bpthumb." . $split_file[1];						
							rename($dir . $value, $dir . $newfname);
							$newfname = $split_file[0] . "-bpfull." . $split_file[1];						
							rename($dir . $value, $dir . $newfname);
add_action( 'xprofile_avatar_uploaded', "fix_crop_avatar" );

#2 @boonebgorges
10 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks for the report and for the code. I've never heard of this problem before, and it's not clear to me why sanitize_file_name() would strip the '-bpfull' and '-bpthumb' suffixes.

In any case, please don't mark the ticket fixed until/unless it's been verified that (a) there's a real bug, and (b) it's been fixed in BuddyPress. Thanks.

#3 @boonebgorges
10 years ago

  • Keywords reporter-feedback added

Hi vusisindane - I've taken a closer look, and I can't manage to reproduce the underlying issue. Is there a chance that you've done more debugging to see why sanitize_file_name() is stripping the suffix on your setup? Do you have a plugin that is filtering 'sanitize_file_name' in some way? If you could trace the path of the issue through that function, it'd be most helpful. Thanks.

#4 @vusisindane
10 years ago

i'll do that.

I'm also not sure why this is happening. Perhaps you're right, there's a plugin somewhere that strips -bpfull. it's actually not stripping the suffix, it's returning a GUID all together.

I'll have a look in my code because I tend to borrow functions and snippets from stack-over-flow without really testing them in details.

Thanks for the acknowledgement...

#5 @DJPaul
10 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

Going to close this as we couldn't recreate and haven't heard from the original reporter (about getting some debug information from their site) in the last six months.

Note: See TracTickets for help on using tickets.