I’m working with the BuddyPress extended profile component and would like to add image fields to the WordPress user profile. Is there code that I can add to my theme’s functions.php so it inserts the “Image” option into the plugin?
I have searched the BuddyPress and WordPress Codex forums and haven’t come across code for intercepting the plugin’s operation without editing core files.
I figured out a way to go about adding the image type field without editing core BuddyPress files. The solution involves adding code to the theme’s functions.php that intercepts the plugin’s loading, display and saving. It also updates the WordPress upload location in order to direct the profile images to a subdirectory of the the uploads directory. The full solution is here.
Step 1.
Add a new field type:
Step 2.
Handle the rendering of the new field type in the WordPress Admin panel
Step 3.
Handle the rendering of the new field type on the WordPress front-end
Step 4.
Access the WordPress registered hook functions to remove the BuddyPress profile saving handler and insert a new one. This is necessary in order to handle the saving of the custom field before passing control back to BuddyPress.
Step 5.
Create the custom field saving function
Step 6.
Override the WordPress upload directory location to provide a custom image saving location
Step 7.
Create a javascript file that shall hold code for updating the field type selection drop-down to insert the new field type when the profile front-end is displayed. Let’s call the file xprofile-image.js and save it in the same location as the theme’s functions.php
Step 8.
Load the js file (xprofile-image.js)
That’s it! The WordPress user profile now has support for additional image fields via the BuddyPress extended profile component.
This would be really helpful if it could be turned into a plugin.
UPDATE:
I got around to creating the plugin and it’s available on the WordPress Plugins page: