If you hook into the uploader, then you’ll be making a copy of an existing file every time a user chooses it, yes? You don’t want that.
imo…
You want to remove the existing cover image option.
You want to create a new tab on their profile and allow them to choose an image.
Then store their choice as meta data.
Then rework member-header template so that it loads their chosen image or shows a default one.
Oops, sorry, just saw that you want the option in addition to choosing an existing image.
So, I would do a template overload of this file:
buddypress\bp-templates\bp-legacy\buddypress\members\single\profile\change-cover-image.php
And offer them the option of choosing an existing image or upload their own.
If they choose the latter – use the existing call:
bp_attachments_get_template_part( 'cover-images/index' );
And for the former – call in your custom screen as I suggest above and adjust cover-image-header.php to load the appropriate image if that metadata exists for the member.
Thanks @shanebp. Yes for sure we would want to avoid the scenario where we are “re-uploading” the default choosen image for each user. I guess I was sort of hoping there was a way in the uploader to just offer them to choose images from our custom library. Sort of like when you use the WordPress media uploader and can choose to pick from the library limiting it to “uploaded to this post”. Overloading the template and using our own custom image picker will work fine. By it being stored in another custom user meta data field it does add some complexity in figuring out how to decide which cover image to use. Meaning that if they upload an image and have also chosen one of our images I need to decide which image takes priority. I’m not sure how I’d do that since meta data fields don;t maintain an “updated” timestamp.
I guess one way would be to only show our “default” choices as an option is they have not uploaded or deleted their custom uploaded cover photo.
Maybe you could use this hook in buddypress\bp-core\bp-core-attachments.php
:
do_action( $object_data['component'] . '_cover_image_uploaded', (int) $bp_params['item_id'] );
And delete any existing meta re the choices you provide.
Just circling back to say this worked like a charm. I wrote a series of functions and added it to a custom plug-in to get it all to work. I’ll try at some point to separate this into a simple stand-alone plugin and try to share it in case someone else needs this feature.
I would be interested in a plugin allowing a choice of cover images. Let us know how it turns out.