#6948 closed enhancement (fixed)
Add more filters to short-circuit avatar/cover image operations.
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (10)
#2
@
9 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
@
9 years ago
I understand, but returning false to the filter, this is what the user will get :
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
- The cover image
- the feedback
- the link to delete it
This is the result of the above code with 02.patch
#5
@
9 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 ?
@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.