Custom Default BuddyPress User Profile cover photo based on WordPress Roles
One of our members asked me recently about this. They wanted to know if it was feasible to set different default BuddyPress profile cover imageĀ based on WordPress user roles. If you are looking for the same, you can do it easily with the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /** * Set different default background images based on user roles * * @param array $settings * * @return array */ function buddydev_set_custom_default_profile_cover( $settings = array() ) { $displayed_user_id = bp_displayed_user_id(); if ( user_can( $displayed_user_id, 'list_users' ) ) { //admin $settings['default_cover'] = 'http://example.com/cover-admin.jpg'; } elseif ( user_can( $displayed_user_id, 'moderate_comments' ) ) {//editor $settings['default_cover'] = 'http://example.com/cover-editor.jpg'; } elseif ( user_can( $displayed_user_id, 'edit_published_posts' ) ) { //author $settings['default_cover'] = 'http://example.com/cover-author.jpg'; } elseif ( user_can( $displayed_user_id, 'edit_posts' ) ) { //contributor $settings['default_cover'] = 'http://example.com/cover-contributor.jpg'; } else { //subscriber $settings['default_cover'] = 'http://example.com/cover.jpg'; } return $settings; } add_filter( 'bp_before_xprofile_cover_image_settings_parse_args', 'buddydev_set_custom_default_profile_cover', 40 ); |
You put the above code in your bp-custom.php or the functions.php in your theme.
I have used capability here for determining user roles, You may look at the WordPress roles in more details here.
Just wanted to say Thanks for directing me to the right direction to set up a default cover image for those who haven't uploaded cover images.
Thank you Pradeep š
Hi there, I am looking for the same but not for the profile photo but rather the cover photo i.e. the large, wide photo in the profile section.
Do you know how to set default images based on profiles for the cover photo?
Thanks!!
Hi Rafaela,
The above code is for the cover photo. It is exactly what you are looking for.
Regards
Brajesh