Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#6948 closed enhancement (fixed)

Add more filters to short-circuit avatar/cover image operations.

Reported by: DJPaul Owned by: djpaul
Milestone: 2.5.1 Priority: normal
Severity: normal Version:
Component: Media Keywords:
Cc:

Description

Most of our avatar/cover image upload functions have actions or a set of filters that can be used to short-circuit the entire function, but some don't.

These are required to support certain cloud CDNs or image hosting services, depending on how that integration is implemented.

Attachments (2)

6948.01.patch (4.9 KB) - added by DJPaul 5 years ago.
6948.02.patch (5.5 KB) - added by imath 5 years ago.

Download all attachments as: .zip

Change History (10)

@DJPaul
5 years ago

#1 @imath
5 years ago

@DJPaul Thanks a lot for your patch.

I guess most of the filters are nice to "short-circuit" the upload process. I have a little concern about bp_attachments_pre_cover_image_ajax_upload because the UI is expecting a json encoded reply. So i'd suggest .02.patch so that the UI can dynamically load the uploaded cover image / inform the user in case of an issue.

@imath
5 years ago

#2 @DJPaul
5 years ago

The custom filter function would use bp_attachments_json_response which would end execution; the return was just to stop anything else in that function to happen (not that it would, because wp_die ends up being called.

#3 @imath
5 years ago

I understand, but returning false to the filter, this is what the user will get :

https://cldup.com/cu9TSZ7DwL.png

Using what i suggest you can do the stuff you need and then return something like :

function write_on_any_cloud_service( $result, $bp_params, $needs_reset, $object_data ) {
	return array(
		'result'        => true,
		'name'          => 'random_cover_name.jpg',
		'url'           => 'https://cldup.com/DB-6lSS9Or.jpg',
		'feedback_code' => 1,
	);
}
add_filter( 'bp_attachments_pre_cover_image_ajax_upload', 'write_on_any_cloud_service', 10, 4 );

Then you would get something more interesting for the user

  1. The cover image
  2. the feedback
  3. the link to delete it

This is the result of the above code with 02.patch

https://cldup.com/qgtUi2AhpW.png

#4 @DJPaul
5 years ago

Right, a simple solution would be just to have the if block just return.

#5 @imath
5 years ago

You mean in 02.patch, instead of having

if ( isset( $pre_filter['result'] ) ) {
	bp_attachments_json_response( $pre_filter['result'], $is_html4, $pre_filter );
}

Using this:

if ( isset( $pre_filter['result'] ) ) {
	return;
}

If so we come back to your patch :) And the UI will display an error message.

Maybe i misunderstood your goal. If you want to completely disable cover image uploads, filters are already existing:

// For members :
add_filter( 'bp_is_profile_cover_image_active', '__return_false' );
 
// For groups :
add_filter( 'bp_is_groups_cover_image_active', '__return_false' );

I think it's best to use these, because the error message in the UI is not great for the user. If the goal is to short-circuit the upload, then .02.patch should help make this happen, am i wrong ?

#6 @djpaul
5 years ago

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

In 10641:

Add filters and actions to support short-circuiting of standard avatar/cover image uploads/crops.

Fixes #6948

Props DJPaul, imath

#7 @djpaul
5 years ago

In 10642:

Add filters and actions to support short-circuiting of standard avatar/cover image uploads/crops.

Fixes #6948 (2.5 branch)

Props DJPaul, imath

#8 @DJPaul
4 years ago

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