One of the most exciting features added in BuddyPress 2.3 is the new BP Attachments API. It provides a BP core-supported method of managing user-submitted files and opens up a world of possibilities for plugin developers.
The API powers the new avatar uploads UI, but it can also be used to extend BuddyPress to add media sharing capabilities. If you want to see a good example of this in the wild, check out BuddyDrive version 1.3.0. The plugin was created by BP core developer Mathieu Viet, who led the effort to get the BP Attachments API into the latest release.
BuddyDrive allows members to share a file or a list of files with the community and includes various settings for restricting access. It’s essentially like a Dropbox clone for BuddyPress, designed to enhance collaboration between members. The plugin was a prime candidate for adapting the BP Attachments API to power community file sharing in a simpler, more elegant way.
You can see it active in the new “BuddyDrive Editor” included in version 1.3, demonstrated in the video below:
[vimeo 129065626 w=1025 h=551]
Viet posted an example function in the plugin’s wiki to show how the BuddyDrive Editor can be placed anywhere. The feature is a good example of how easy it is for developers to leverage the API to manage user-generated media from the frontend.
BuddyDrive 1.3 is currently in beta and on track to be released soon. If you’d like to help test the beta or inspect the code to see how it works, you can download a zip file from Viet’s preview post. The unreleased version 1.3 is also available on GitHub.
If you want to learn more about using the new BP Attachments API, check out Viet’s comprehensive BP codex article. It walks you through extending the
BP_Attachment class to validate and store files in a subdirectory of wp-content/uploads. The documentation also includes a sample plugin to demonstrate how you might add attachments to private messages.
Source: WP Tavern