Search Results for 'bp_core_fetch_avatar'
-
AuthorSearch Results
-
November 9, 2024 at 5:12 pm #335577
thinlizzie
ParticipantI forgot the comma above, should be a comma after ‘full’ , like so …
return bp_core_fetch_avatar( array( 'type' => 'full', 'item_id' => $user->ID, 'width' => 80, 'height' => 80, ) ); }November 9, 2024 at 1:32 pm #335575thinlizzie
ParticipantAlso re. Avatar size, first try adding ‘type = full’ into the array, should allow you to specify larger sizes, as below …
return bp_core_fetch_avatar( array( 'type' => 'full' 'item_id' => $user->ID, 'width' => 80, 'height' => 80, ) ); }November 9, 2024 at 1:02 pm #335574thinlizzie
ParticipantRe. avatar size, not sure, you can try putting a span around your shortcode, give it a class and with CSS try to force the avatar size.
Or you can add a class into the fetch_avatar array and try that way.
See: https://www.buddyboss.com/resources/reference/functions/bp_core_fetch_avatar/
November 9, 2024 at 1:50 am #335567thinlizzie
ParticipantTry this for your avatar display.
Your shortcode syntax would look like …
[showavatar username=”johnsmith”]
You can change width & height to your preference.
function show_avatar ($atts) { $user = get_user_by( 'login' , $atts['username'] ); return bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'width' => 50, 'height' => 50, ) ); } add_shortcode( 'showavatar' , 'show_avatar' );July 30, 2024 at 6:00 pm #334788In reply to: Blurry Avatar and Cover Images
Why Not Advertising, LLC
ParticipantThis is what I came up with and I think it worked to fix the Avatar quality, however, it won’t impact the Profile images for Groups and Group cover photos. Can you point me in the correct direction for the Constants that work with those two?
Here’s my code:
// Set the BP_AVATAR_ORIGINAL_MAX_WIDTH to a higher value if ( ! defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) ) { define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 1024 ); // Set to match your largest expected upload size } // Adjust the quality of the avatar resizing process function custom_bp_avatar_quality( $args ) { $args['quality'] = 100; // Set to the highest quality return $args; } add_filter( 'bp_core_avatar_resize_args', 'custom_bp_avatar_quality' ); add_filter( 'bp_core_avatar_thumb_resize_args', 'custom_bp_avatar_quality' ); add_filter( 'bp_core_group_avatar_resize_args', 'custom_bp_avatar_quality' ); add_filter( 'bp_core_group_avatar_thumb_resize_args', 'custom_bp_avatar_quality' ); // Adjust JPEG quality for all images in WordPress add_filter( 'jpeg_quality', function() { return 100; // Set to the highest quality }); // Ensure high-resolution images are used in the HTML output function custom_bp_use_full_size_avatar( $html, $params ) { if ( isset( $params['object'] ) && in_array( $params['object'], array( 'user', 'group' ) ) ) { // Get the full-size avatar URL $full_avatar_url = bp_core_fetch_avatar( array( 'item_id' => $params['item_id'], 'object' => $params['object'], 'type' => 'full', 'html' => false, )); // Construct the new img tag with the full-size avatar URL $html = sprintf( '<img src="%s" class="%s" alt="%s" width="%d" height="%d"/>', esc_url( $full_avatar_url ), esc_attr( $params['class'] ), esc_attr( $params['alt'] ), (int) $params['width'], (int) $params['height'] ); } return $html; } add_filter( 'bp_core_fetch_avatar', 'custom_bp_use_full_size_avatar', 10, 2 ); // Add custom CSS to scale down the avatars function custom_bp_add_avatar_css() { $custom_css = " .avatar, .group-avatar img { width: 150px; height: 150px; object-fit: cover; /* Ensures the image covers the element's entire area */ } "; wp_add_inline_style( 'bp-parent-css', $custom_css ); // Adjust 'bp-parent-css' to match your theme's main stylesheet handle if necessary } add_action( 'wp_enqueue_scripts', 'custom_bp_add_avatar_css' );May 5, 2024 at 12:49 pm #333950shiylo
ParticipantSalut ! Effectivement, BuddyPress ne supprime pas automatiquement les avatars des utilisateurs lorsque leurs comptes sont supprimés. Cependant, tu peux gérer ce problème en ajoutant un peu de code personnalisé à ton thème ou dans un plugin spécifique. Voici comment tu pourrais procéder pour supprimer les avatars lors de la suppression des comptes d’utilisateurs :
1- Crée un hook dans ton fichier functions.php ou dans un plugin spécifique :
Utilise l’action bp_remove_user ou wpmu_delete_user, delete_user selon la configuration de ton réseau si tu es en multisite ou pas.
2- Ajoute le code suivant pour supprimer l’avatar lorsqu’un utilisateur est supprimé :function remove_user_avatar_on_delete($user_id) { // Vérifie si l'utilisateur a un avatar $avatar_path = bp_core_fetch_avatar(array( 'item_id' => $user_id, 'html' => false, 'type' => 'full', 'no_grav' => true )); if ($avatar_path) { // Supprime le fichier avatar @unlink($avatar_path); } } // Hook pour la suppression de l'utilisateur add_action('delete_user', 'remove_user_avatar_on_delete'); add_action('wpmu_delete_user', 'remove_user_avatar_on_delete'); add_action('bp_remove_user', 'remove_user_avatar_on_delete');Note : Ce code utilise @unlink pour supprimer le fichier, qui supprime silencieusement le fichier sans afficher d’erreur si le fichier n’existe pas ou ne peut être supprimé. Assure-toi que le chemin de l’avatar est correctement récupéré.
3- Teste le code : Avant de mettre ce code en production, teste-le dans un environnement de développement pour t’assurer qu’il fonctionne comme attendu sans effets secondaires.
Cela devrait aider à gérer le problème des fichiers d’avatar résiduels. Si tu as besoin de plus d’informations sur la fonction ou sur d’autres façons de gérer les fichiers avec WordPress et BuddyPress, n’hésite pas à demander !December 6, 2023 at 3:19 pm #332122In reply to: Buddypress profile pic to wordpress avatar
fusionbudd
ParticipantTwo ways to use your BP profile pic as your WordPress avatar:
1. Plugins:
Install and activate a plugin like “BuddyPress Default Avatar” or “BuddyPress Avatar Sync.”
These plugins automatically sync your BP profile photo with your WordPress avatar, making it a simple and hands-off solution.2. Custom code:
If you prefer a more technical approach, you can add code to your theme’s functions.php file.
This code snippet will enable syncing of the two avatars:PHP
function bp_avatar_sync($user_id) {
// Get BP profile picture URL
$bp_avatar_url = bp_core_fetch_avatar(array(‘item_id’ => $user_id, ‘type’ => ‘full’));// Update WordPress avatar URL
update_user_meta($user_id, ‘user_avatar’, $bp_avatar_url);
}
add_action(‘bp_core_avatar_uploaded’, ‘bp_avatar_sync’);Remember, both methods achieve the same result. Choose the method that best suits your technical skills and preferences.
July 6, 2023 at 5:10 am #330322In reply to: Buddypress profile pic to wordpress avatar
kindabisu
ParticipantTo use your BP (BuddyPress) profile picture as the WordPress avatar, you can follow these steps:
Install and activate the “BuddyPress” plugin: Ensure that you have the BuddyPress plugin installed and activated on your WordPress site. This plugin adds social networking functionality, including user profiles, to your WordPress site.
Upload a profile picture in BuddyPress: Go to your BuddyPress profile and upload the desired profile picture. BuddyPress allows users to customize their profile information, including the profile picture. Typically, you can find the profile settings in the user dashboard or by navigating to your profile page on the front-end of your website.
Enable BuddyPress avatar syncing: By default, BuddyPress doesn’t automatically sync the profile picture with the WordPress avatar. You can enable this functionality by adding custom code to your theme’s functions.php file or by using a plugin specifically designed for this purpose.
Option 1: Custom code:
Open your theme’s functions.php file (Appearance > Theme Editor > functions.php) and add the following code snippet:php
Copy code
function bp_sync_profile_picture_with_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
if ( function_exists( ‘bp_core_fetch_avatar’ ) ) {
$avatar = bp_core_fetch_avatar( array(
‘item_id’ => $id_or_email->user_id,
‘type’ => ‘full’,
‘html’ => false
) );
}
return $avatar;
}
add_filter( ‘get_avatar’, ‘bp_sync_profile_picture_with_avatar’, 10, 5 );
Option 2: Use a plugin:
Install and activate a plugin like “BuddyPress Default Avatar” or “BuddyPress Avatar Sync.” These plugins simplify the process by automatically syncing the BuddyPress profile picture with the WordPress avatar.Verify the avatar sync: Log out of your WordPress account and visit your website as a guest or open an incognito/private browsing window. Leave a comment or view your author bio to see if the BuddyPress profile picture is now being used as the WordPress avatar.
By following these steps, your BuddyPress profile picture should now be synced with your WordPress avatar.
February 26, 2023 at 9:50 am #328533Topic: Default Buddypress avatar type
in forum How-to & TroubleshootingHerveSLT
ParticipantHello,
I would like to change the default Buddypress avatar type.
In bp-core-avatars.php, “bp_core_fetch_avatar” function is set to “thumb”.How to set to “Full” in my theme ?
Thanks for your help !
July 8, 2021 at 8:10 pm #319844In reply to: Adding the users’ avatar photo URL to usermeta
shanebp
ModeratorIt is unclear if this is a BuddyPress issue.
BP does not store avatar info in the database.
It calls avatars from the uploads > avatars directory and organizes them based on the WP user ID.If not found, the default image is used.
May 27, 2021 at 11:39 pm #319017In reply to: meta user field to load avatar URL
shanebp
ModeratorThere are several filter hooks you could try.
Look towards the bottom offunction bp_core_fetch_avatarin this file:
wp-content\plugins\buddypress\bp-core\bp-core-avatars.phpFor example, I would try this one first:
function gabriel_random_avatar( $default_grav, $params ) { // $default_grav is an url // replace it with the full url to one of your preferred avatars return $default_grav; } add_filter('bp_core_avatar_default', 'gabriel_random_avatar', 99, 2 );May 26, 2021 at 3:20 pm #318997In reply to: meta user field to load avatar URL
shanebp
ModeratorAre you saying that you want to use BP avatars on WP author pages?
If so, find the call to the avatar on the authors template.
And replace it with something like this:<img class="" src="<?php $authorUserID = get_the_author_meta('ID'); // get the user id of the post author echo bp_core_fetch_avatar ( array( 'item_id' => $authorUserID, // output user id of post author 'type' => 'full', 'html' => FALSE // FALSE = return url, TRUE (default) = return url wrapped with html and css classes ) );August 6, 2020 at 12:35 am #313242Topic: Getting wrong avatar on likes
in forum How-to & Troubleshootingtbako
ParticipantHi guys, how are you?
I have a website that shows the correct avatar (from Social Login) in comments but in likes it gets the user uploaded profile, even if the social login is forcing the new one (it get’s it directly from the upload folder).
The wrong code is:
$avatar = bp_core_fetch_avatar( array( 'html' => false, 'type' => 'thumb', 'item_id' => $user_id ) ); // Get User Image Code. $output .= "<a data-yztooltip='" . $fullname . "' style='background-image: url( " . $avatar . ");' href='" . bp_core_get_user_domain ( $user_id ) . "'></a>";It returns:
/wp-content/uploads/avatars/38/5f1df11236f8e-bpthumb.jpg (the old photo before social login)The code that shows the correct one:
<?php bp_activity_avatar( ‘type=thumb&user_id=’ . bp_get_activity_comment_user_id() ); ?>It returns:
//graph.facebook.com/2434567832184997/picture?type=largeTried changing but it shows the author profile pic on the liked space.
Can anyone help me?
Thanks!
March 5, 2020 at 7:30 am #310368In reply to: how get profile image information from database?
Carlen
ParticipantYou can use for logged in user:
bp_displayed_user_avatar( ‘type=full’ );if calling within a group:
bp_group_member_avatar();or in general (this is pulled for admin of a group, but can be set up in other ways):
bp_core_fetch_avatar( array( ‘item_id’ => $admin->user_id, ’email’ => $admin->user_email, ‘type’ => ‘full’ ) )January 12, 2020 at 5:00 am #309727vuture
ParticipantHello,
I want to create an email-token to display a member avatar in a bp-custom-mail.
I tried to implement snippets from this tutorial, but maybe I don’t understand everything correctly.
1) I created a single-bp-email.php with custom html content which works fine.
There I can add the output whereever I want the avatar to be displayed <?php bp_email_avatar(); ?>, right?2) To my bp-custom.php I added this function:
function bp_email_avatar() { $token = '{{recipient.avatar}}'; printf( '<img src="%s">', $token ); }Have a look at my bp-custom.php:
https://1drv.ms/u/s!AikSNhBAk4teugLf_yT-8610eUDC$formatted_tokens['recipient.avatar'] = bp_core_fetch_avatar( array( 'object' => 'user', 'item_id' => $formatted_tokens['initiator.id'], 'html' => false, ) );=> The last snippet results in a php-error.
Could you help me to make this work?
Thanks in advance,
ChrisJanuary 3, 2020 at 10:50 pm #309653Mathieu Viet
ModeratorHi @mohamedbakry83,
In this case you’ll need to copy the email template into a
/buddypress/assets/email/single-bp-email.phpfile of your active theme and edit it from theme to include a new template tag.something like:
<?php mohamedbakry83_output_avatar(); ?>Then in a bp-custom.php file, you’ll need to include new function for this template tag:
function mohamedbakry83_output_avatar() { $token = '{{recipient.avatar}}'; printf( '<img src="%s">', $token ); }In this file, you’ll need to use & adapt the filter @shanebp pasted in his first reply making sure to check
$formatted_tokens['friend-requests.url']&$formatted_tokens['initiator.id']are set and then set the recipient.avatar token like this :$formatted_tokens['recipient.avatar'] = bp_core_fetch_avatar( array( 'object' => 'user', 'item_id' => $formatted_tokens['initiator.id'], 'html' => false, ) );This is for the friendship request email. But you should be able to do it for any email type with this example.
October 24, 2019 at 8:20 pm #308645In reply to: Fetch user’s avatar
jbrandsma
ParticipantWelp, I couldn’t wait so I just spent hours trying to figure this out – with SUCCESS. If anyone stumbles upon this, here is the code I placed in my theme’s function.php file.
function jb_get_bp_user_avatar($avatar, $id_or_email, $size, $default, $alt)
{
if (is_numeric($id_or_email)) {
$id = (int) $id_or_email;
$user = get_user_by(‘id’, $id);
} elseif (is_object($id_or_email)) {
if (!empty($id_or_email->user_id)) {
$id = (int) $id_or_email->user_id;
$user = get_user_by(‘id’, $id);
}
} else {
$user = get_user_by(’email’, $id_or_email);
}
if ($user && is_object($user)) {
$avatar = bp_core_fetch_avatar(array(‘item_id’ => $user->ID));
}
return $avatar;
}
add_filter(‘get_avatar’, ‘jb_get_bp_user_avatar’, 10000, 5);September 8, 2019 at 6:18 pm #307725In reply to: Get rid of gravatar option
Ben Roberts
ParticipantTry add_filter(‘bp_core_fetch_avatar_no_grav’, ‘__return_true’);
There was a bug ticket that used this ages ago – https://buddypress.trac.wordpress.org/ticket/7056
Can’t guarantee it still works.
July 30, 2019 at 11:39 pm #307226In reply to: customize avatar file name
a608237
ParticipantSo this is a very hacky way i’m doing it. I noticed using xprofile_set_field_data to set the data for an extended profile field only works temporarily. However, overwriting an existing default profile field (i.e. Facebook, Snapchat) seems to stay permanently.
xprofile_set_field_data('Snapchat', $current_user->ID, $avatar_path);So as admin, I went in and changed the name of the default profile field to my desired one (i.e. Snapchat -> path) and applied
add_filter( 'xprofile_updated_profile', 'update_xprof' ); function update_xprof() { $path=bp_core_fetch_avatar(); xprofile_set_field_data('path', $current_user->ID, $path); }This way works more or less. However, I noticed that the function only kicks in when the user literally clicks ‘Edit’ and changes the data in her/his profile from the front end.
This function does not kick in whenever the user changes his/her avatar. I tried to use
xprofile_avatar_uploadedin place ofxprofile_updated_profile, but with it, the function doesn’t seem to work at all. Can someone comment on why?July 30, 2019 at 10:22 pm #307225In reply to: customize avatar file name
a608237
ParticipantI’ve decided to create a hidden xprofile field to store this data, but using xprofile_set_field_data only seems to work temporarily, after several minutes, the entire row containing the data disappears from wp_bp_xprofile_data. How can I make this permanent?
add_action( 'bp_setup_nav', 'write_path' ); function write_path() { global $bp; global $current_user; $avatar_path = bp_core_fetch_avatar('html=false'); xprofile_set_field_data('path', $current_user->ID, $avatar_path); }April 12, 2019 at 7:53 pm #304726In reply to: Lightbox profile image
Venutius
ModeratorHi Debby, I found time to test this, if you install WP Featherlight and then make the following change:
<?php $fullsize_avatar_url = bp_core_fetch_avatar( array( 'type' => 'full', 'html' => false, 'no_grav' => true, 'item_id' => bp_get_member_user_id() ) ); ?> <li <?php bp_member_class(); ?>> <div class="item-avatar"> <a href="#" data-featherlight="<?php echo $fullsize_avatar_url; ?>"><?php bp_member_avatar(); ?></a> </div>You will have your avatars in lightboxes. However these will probably be small. The default is only 150 pixels.
You can change this with the following setting placed in either your child themes functions.php or a bp-custom.php placed in the plugins directory.
define ( 'BP_AVATAR_FULL_WIDTH', 150 ); define ( 'BP_AVATAR_FULL_HEIGHT', 150 );change the 150 to your preferred pixel size for the image.
April 12, 2019 at 3:58 pm #304716In reply to: Lightbox profile image
Venutius
ModeratorWhat you will need however is details of how to construct the url for the full size avatar image:
<?php $fullsize_avatar_url = bp_core_fetch_avatar( array( 'type' => 'full', 'html' => false, 'item_id' => bp_get_member_user_id() ) ); ?>So you’d add this as the image that will load into the lightbox.
December 10, 2018 at 9:18 pm #282695Venutius
ModeratorI always use bp_core_fetch_avatar, it’s better documented and avoids the filter, which could be the issue.
$args = array( 'item_id' => bp_loggedin_user_id()' 'type' => 'full', 'html' => false ); $mg_avatar = bp_core_fetch_avatar( $args );Try that
November 23, 2018 at 2:44 pm #282120Venutius
ModeratorYou’d just set the default avatar for buddypress:
The default avatar is the one that appear when a user has not yet uploaded his own avatar. If you’re not a fan of the mystery man, here are the constants that you can use to define your own:
define ( 'BP_AVATAR_DEFAULT', $img_url ); define ( 'BP_AVATAR_DEFAULT_THUMB', $img_url );Change the the constant to include the URL for the location of your new default avatars and add this to your bp-custom.php file.
define ( 'BP_AVATAR_DEFAULT', 'http://example.com/default-avatar.jpg' ); define ( 'BP_AVATAR_DEFAULT_THUMB', 'http://example.com/default-avatar-thumb.jpg' );To use a default avatar without Gravatar you should also add:
add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );October 17, 2018 at 1:24 am #279042In reply to: problem with avatar in multisite
keshabee
ParticipantHi @prashantvatsh
Thanks for pointing me to the right direction, I noticed the break in the image was caused by this code I made use of;Please can you assist me in a way to debug and fix this code a little
Reasons being:
The code helps to disable the gravatar use in buddy-press avatar and cover-image while also removing that gravatar text wordings when editing the avatar and cover image/*Disable gravatar*/ add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); /*Disable gravatar extra function*/ function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) { $default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg'; if( $image && strpos( $image, "gravatar.com" ) ){ return '<img src="' . $default . '" alt="avatar" class="avatar" ' . $html_width . $html_height . ' />'; } else { return $image; } } add_filter('bp_core_fetch_avatar', 'bp_remove_gravatar', 1, 9 ); function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) { $default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg'; return "<img alt='{$alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; } add_filter('get_avatar', 'remove_gravatar', 1, 5); function bp_remove_signup_gravatar ($image) { $default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg'; if( $image && strpos( $image, "gravatar.com" ) ){ return '<img src="' . $default . '" alt="avatar" class="avatar" width="150" height="150" />'; } else { return $image; } } add_filter('bp_get_signup_avatar', 'bp_remove_signup_gravatar', 1, 1 );Thanks in advance
-
AuthorSearch Results