Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 101 through 125 (of 310 total)
  • Author
    Search Results
  • #229690
    sookie29
    Participant

    Hi Guys,

    I would like to show members from the same region when logged in and here is the code I have used but now working:

    <!–?php </p–>

    bp_loggedin_user_id();

    $user_id = 14 ;

    $myfield = xprofile_get_field_data( ‘State’, 14);
    echo $myfield;

    xprofile_get_field_data(‘field=Bundesland’, 14);
    ?>

     

     

    <!–?php </p–>

    }

    $sql=”select * from `
    glft448_bp_xprofile_data where value = ‘”.$state.”‘”;
    $con1 = mysql_query(“SELECT distinct user_id FROM glft448_bp_xprofile_data WHERE value = ‘”.$state.”‘”);

    while($queRes1 = mysql_fetch_array($con1))

    {

    ?>

    <!–?php $queRes1[‘user_id’];<br ?–> // echo bp_core_get_userlink($queRes1[‘user_id’]);

    ?>
    <a href=”"<?php”>” >
    <!–?php echo bp_core_fetch_avatar ( array( ‘item_id’ =–>$queRes1[‘user_id’] , ‘type’ => ‘thumb’ ) ); ?></a>

    <!–?php </p–>

    }

    $sqlt=”select * from `glft448_bp_xprofile_data where value = ‘”.$state.”‘”;
    $con2 = mysql_query(“SELECT * FROM glft448_bp_xprofile_data WHERE user_id = ‘”.$user_id.”‘ AND field_id = ‘1’ “);

    while($queRes2 = mysql_fetch_array($con2))

    {

    ?>

    <b> <!–?php //echo $queRes2[‘value’]; ?–></b>

    I added that code to the text version of the page editor but it’s showing like that on the profile page.

    What am I missing?

    Thanks

    #203190
    danbp
    Participant

    @reinforcez,

    the link given by @drakedoc was started over 4 years. Many solutions are given in this thread, and the last one was published a year ago.

    That solution works for 1.9 and above !

    /* Skip the Gravatar check when using a default BP avatar */ 	
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

    By the way you have also to modify the global WP setting of avatars to “mystery man” or “nothing”.

    Another solution to avoid gravatars slowing down a big site (at least > 500 members), is to use a specific cache plugin like Nix Gravatar Cache. Complete list here.

    #197233
    Henry Wright
    Moderator

    Hi @tightflks

    You can use get_avatar() instead of the BuddyPress function bp_core_fetch_avatar(). See: https://codex.wordpress.org/Function_Reference/get_avatar

    #187695
    Henry Wright
    Moderator

    There might actually be more things you’d need to do. For example, the bp_get_message_thread_avatar() function uses bp_core_fetch_avatar() so you would need to filter that using bp_get_message_thread_avatar etc.

    Unless someone else knows of an easier way, it seems as though it’ll be a big task of going through everything. You’d also need to be comfortable with PHP.

    Alternatively, you could try disabling avatars by adding this to your bp-custom.php file

    define( 'BP_SHOW_AVATARS', false );

    Note: I’ve not tested that, I’m just going on what I see at the beginning of the bp_core_fetch_avatar() function. i.e:

    // If avatars are disabled for the root site, obey that request and bail
    if ( ! buddypress()->avatar->show_avatars )
       return;
    #187692
    Martin Waller
    Participant

    Okay, so searching that GitHub repo there is only one file under the bp-themes/bp-legacy/buddypress folders which mentions bp_core_fetch_avatar() (but lots within the core BuddyPress code. So I just need to replace the reference in that one file and add it to by child theme under a BuddyPress folder and it should work?

    #187685
    Martin Waller
    Participant

    Thanks @henrywright

    I’m not entirely sure that my front-end template actually references bp_core_fetch_avatar() as it is not a BuddyPress theme but rather a regular WordPress theme (Responsive Pro).

    Martin

    #187684
    Henry Wright
    Moderator

    Actually scratch that last post – it’s now displaying the avatars as the WordPress avatars in the back-end but not the front end

    In that case, I think we’ve just crossed that bridge hehe. i.e the next step will be to replace all instances of bp_core_fetch_avatar() in your front-end templates with get_avatar()

    #187679
    Henry Wright
    Moderator

    Humm.. not helpful then. In that case we might have to try doing it manually. Perhaps try disabling the filter which replaces the WP avatars with BP avatars. For example, add this to your theme’s functions.php file:

    remove_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );

    I think you can disable the Gravatar fallback as well with this:

    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

    If that doesn’t work, you may need to replace all occurrences of bp_core_fetch_avatar() with get_avatar() in your templates. But cross that bridge when you come to it.

    Ref: https://codex.wordpress.org/Function_Reference/get_avatar

    #187149
    adamt19
    Participant

    This worked for me

    
    function no_photos() { 
    	global $wpdb;
    
    	$nophotoids = array();
    	
    	$ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->prefix}users" );
    
    	foreach( $ids as $id ) { 
    
    		$avatar_check = false;
       
    		if ( preg_match('/mystery-man.jpg/', bp_core_fetch_avatar( array( 'item_id' => $id, 'no_grav' => true, 'html'=> false ) ) ) )			
    		  $avatar_check = true; 
    
    		if( ! $avatar_check ) { 
    			$nophotoids[] = $id;
    		}
    	}
    		
    	$nophotoids = implode(",", $nophotoids);
    		
    	echo 'no photo ids: ' . $nophotoids;
    	
    		
    }
    mshafshak
    Participant

    i’m trying to get user info from facebook when a user tries to login through facebook on my website ,Wordpress website, I have been struggling to retrieve users’ birthday, email, first name, last name and interests and so on what is the code to get them. I’m newly to facebook apps so I don’t know what to do and what is the procedure

    All what i can retrieve is the email, name and create username according to the url user name

    some clear code would be useful Thank you

    This is my code location in my directory:
    wp-content/themes/themeName/framework/functions/facebook_login.php

    
    <?php
    
    function fb_head(){
      if( is_user_logged_in()) return;
      ?>
    
      <div id="fb-root"></div>
    	<script>
    		// Additional JS functions here
    		window.fbAsyncInit = function() {
    			FB.init({
    				appId      : '<?php echo sq_option('fb_app_id'); ?>', // App ID
    				version    : 'v2.0',
    				status     : true, // check login status
    				cookie     : true, // enable cookies to allow the server to access the session
    				xfbml      : true,  // parse XFBML
    				oauth      : true
    			});
    
    			// Additional init code here
    
    		};
    
    		// Load the SDK asynchronously
    		(function(d){
    			 var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    			 if (d.getElementById(id)) {return;}
    			 js = d.createElement('script'); js.id = id; js.async = true;
    			 js.src = "//connect.facebook.net/en_US/sdk.js";
    			 ref.parentNode.insertBefore(js, ref);
    		 }(document));
    	</script>
        <?php
    }
    add_action( 'kleo_after_body', 'fb_head' );
    
    function fb_footer(){
    ?>
    	<script type="text/javascript">
    	var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    	jQuery('.facebook_connect').click(function(){
    			var context = jQuery(this).closest("form");
    			if (jQuery(".tos_register", context).length > 0)
    			{
    				if (! jQuery(".tos_register", context).is(":checked"))
    				{
    					alert('<?php echo apply_filters('kleo_fb_tos_alert',__("You must agree with the terms and conditions.",'kleo_framework'));?>');
    					return false;
    				}
    			}		
    			
    		FB.login(function(FB_response){
    			if( FB_response.status === 'connected' ){
    				fb_intialize(FB_response);
    			}
    		},
    		{scope: 'public_profile,email'});
    	});
    
    	function fb_intialize(FB_response){
    		FB.api( '/me', 'GET', 
    						{'fields':'id,email,verified,name'},
    						function(FB_userdata){
    							jQuery.ajax({
    									type: 'POST',
    									url: ajaxurl,
    									data: {"action": "fb_intialize", "FB_userdata": FB_userdata, "FB_response": FB_response},
    									success: function(user){
    										if( user.error ){
    											alert( user.error );
    										}
    										else if( user.loggedin ){
    											if( user.type === 'login' )
    											{
    												window.location.reload();
    											}
    											else if( user.type === 'register' )
    											{
    												window.location = user.url;
    											}
    										}
    									}
    							});
    						}
    		);
    	};
    	</script>
    <?php
    }
    add_action( 'wp_footer', 'fb_footer' );
    
    if (!function_exists('fb_button')):
    function fb_button()
    {
    ?>
        <a href="#" class="facebook_connect radius button facebook"><i class="icon-facebook-sign"></i> &nbsp;<?php _e("LOG IN WITH Facebook", 'kleo_framework');?></a>
    <?php
    }
    endif;
    
    if (!function_exists('fb_register_button')):
    function fb_register_button()
    {
    ?>
        <a href="#" class="facebook_connect radius small button facebook"><i class="icon-facebook-sign"></i> &nbsp;<?php _e("Register using Facebook", 'kleo_framework');?></a>
    <?php
    }
    endif;
    
    if (!function_exists('fb_register_button_front')):
    function fb_register_button_front()
    {
    ?>
        <a href="#" class="facebook_connect radius button facebook"><i class="icon-facebook"></i></a>
    <?php
    }
    endif;
    
    add_action('fb_popup_button', 'fb_button' );
    
    if (sq_option('facebook_register', 0) == 1) {
        add_action('fb_popup_register_button', 'fb_register_button' );
        add_action('fb_popup_register_button_front', 'fb_register_button_front' );
    }
            
    function wp_ajax_fb_intialize(){
        @error_reporting( 0 ); // Don't break the JSON result
        header( 'Content-type: application/json' );
    
        if( !isset( $_REQUEST['FB_response'] ) || !isset( $_REQUEST['FB_userdata'] ))
        die( json_encode( array( 'error' => __('Authenication required.', 'kleo_framework') )));
    
        $FB_response = $_REQUEST['FB_response'];
        $FB_userdata = $_REQUEST['FB_userdata'];
        $FB_userid = $FB_userdata['id'];
    
        if( !$FB_userid )
        die( json_encode( array( 'error' => __('Please connect your facebook account.', 'kleo_framework') )));
    
        global $wpdb;
        //check if we already have matched our facebook account
        $user_ID = $wpdb->get_var( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '_fbid' AND meta_value = '$FB_userid'" );
        
    	
        //if facebook is not connected
        if( !$user_ID ){
    			$user_email = $FB_userdata['email'];
    			$user_ID = $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_email = '".$wpdb->escape($user_email)."'" );
    
    			$redirect = '';
    
    			//if we have a registered user with this Facebook email
    			if(!$user_ID )
    			{
    				if ( !get_option( 'users_can_register' )) {
    					die( json_encode( array( 'error' => __('Registration is not open at this time. Please come back later.', 'kleo_framework') )));
    				}
    				if (sq_option('facebook_register', 0) == 0) {
    					die( json_encode( array( 'error' => __('Registration using Facebook is not currently allowed. Please use our Register page', 'kleo_framework') )));
    				}
    				
    				extract( $FB_userdata );
    
    				$display_name = $name;
    
    				if( empty( $verified ) || !$verified )
    				die( json_encode( array( 'error' => __('Your facebook account is not verified. You have to verify your account before proceed login or registering on this site.', 'kleo_framework') )));
    
    				$user_email = $email;
    				if ( empty( $user_email ))
    				die( json_encode( array( 'error' => __('Please re-connect your facebook account as we couldn\'t find your email address.', 'kleo_framework') )));
    
    				if( empty( $name ))
    				die( json_encode( array( 'error' => 'empty_name', __('We didn\'t find your name. Please complete your facebook account before proceeding.', 'kleo_framework') )));
    
    				$user_login = sanitize_title_with_dashes( sanitize_user( $display_name, true ));
    
    				if ( username_exists( $user_login )) {
    					$user_login = $user_login. time();
    				}
    
    				$user_pass = wp_generate_password( 12, false );
    				$userdata = compact( 'user_login', 'user_email', 'user_pass', 'display_name' );
    				$userdata =  apply_filters('kleo_fb_register_data', $userdata);
    
    				$user_ID = wp_insert_user( $userdata );
    				if ( is_wp_error( $user_ID ))
    				die( json_encode( array( 'error' => $user_ID->get_error_message())));
    
    				//send email with password
    				wp_new_user_notification( $user_ID, wp_unslash( $user_pass ) );
    
    				//add Facebook image
    				update_user_meta($user_ID, 'kleo_fb_picture', 'https://graph.facebook.com/' . $id . '/picture');
    						
    				do_action('fb_register_action',$user_ID);
                
    				update_user_meta( $user_ID, '_fbid', (int) $id );
    				$logintype = 'register';
    				$redirect = apply_filters('kleo_fb_register_redirect',bp_core_get_user_domain( $user_ID ).'profile/edit/group/1/?fb=registered');
    			}
    			else
    			{
    				update_user_meta( $user_ID, '_fbid', (int) $FB_userdata['id'] );
    				//add Facebook image
    				update_user_meta($user_ID, 'kleo_fb_picture', 'https://graph.facebook.com/' . (int) $FB_userdata['id'] . '/picture');
    				$logintype = 'login';
    			}
    		}
        else
        {
    			$logintype = 'login';
        }
    
        wp_set_auth_cookie( $user_ID, false, false );
        die( json_encode( array( 'loggedin' => true, 'type' => $logintype, 'url' => $redirect )));
    }
    add_action( 'wp_ajax_nopriv_fb_intialize', 'wp_ajax_fb_intialize' );  
            
    //If registered via Facebook -> show message
    add_action( 'template_notices', 'kleo_fb_register_message' );
    if (!function_exists('kleo_fb_register_message')):
        function kleo_fb_register_message()
        {
            if (isset($_GET['fb']) && $_GET['fb'] == 'registered')
            {
                echo '<div class="clearfix"></div><br><div class="alert-box success" id="message" data-alert>';
                echo __('Thank you for registering. Please make sure to complete your profile fields below.', 'kleo_framework');
                echo '</div>';
            }
        }
    endif;
    
    //display Facebook avatar
    if(sq_option('facebook_avatar', 1) == 1) {
    	//show Facebook avatar in WP
    	add_filter('get_avatar', 'kleo_fb_show_avatar', 5, 5);
    	//show Facebook avatar in Buddypress
    	add_filter('bp_core_fetch_avatar', 'kleo_fb_bp_show_avatar', 3, 5);
    	//show Facebook avatar in Buddypress - url version
    	add_filter('bp_core_fetch_avatar_url','kleo_fb_bp_show_avatar_url', 3, 2);
    }
    function kleo_fb_show_avatar($avatar = '', $id_or_email, $size = 96, $default = '', $alt = false) {
      $id = 0;
      if (is_numeric($id_or_email)) {
        $id = $id_or_email;
      } else if (is_string($id_or_email)) {
        $u = get_user_by('email', $id_or_email);
        $id = $u->id;
      } else if (is_object($id_or_email)) {
        $id = $id_or_email->user_id;
      }
      if ($id == 0) return $avatar;
    	
    	//if we have an avatar uploaded and is not Gravatar return it
    	if(strpos($avatar, home_url()) !== FALSE && strpos($avatar, 'gravatar') === FALSE) return $avatar;
    	
    	//if we don't have a Facebook photo
      $pic = get_user_meta($id, 'kleo_fb_picture', true);
      if (!$pic || $pic == '') return $avatar;
    	
      $avatar = preg_replace('/src=("|\').*?("|\')/i', 'src=\'' . $pic . apply_filters('fb_show_avatar_params', '?width=580&height=580') . '\'', $avatar);
      return $avatar;
    }
    
    function kleo_fb_bp_show_avatar($avatar = '', $params, $id) {
        if(!is_numeric($id) || strpos($avatar, 'gravatar') === false) return $avatar;
    		
    		//if we have an avatar uploaded and is not Gravatar return it
    		if(strpos($avatar, home_url()) !== FALSE && strpos($avatar, 'gravatar') === FALSE) return $avatar;
    		
        $pic = get_user_meta($id, 'kleo_fb_picture', true);
        if (!$pic || $pic == '') return $avatar;
        $avatar = preg_replace('/src=("|\').*?("|\')/i', 'src=\'' . $pic. apply_filters('fb_show_avatar_params', '?width=580&height=580') . '\'', $avatar);
        return $avatar;
    }
    
    function kleo_fb_bp_show_avatar_url($gravatar, $params) {
    	
    	//if we have an avatar uploaded and is not Gravatar return it
    	if(strpos($gravatar, home_url()) !== FALSE && strpos($gravatar, 'gravatar') === FALSE) return $gravatar;
    	
      $pic = get_user_meta($params['item_id'], 'kleo_fb_picture', true);
      if (!$pic || $pic == '') return $gravatar;
    	return $pic. apply_filters('fb_show_avatar_params', '?width=580&height=580');
    }
    
    ?>
    
    #184752
    shanebp
    Moderator

    untested:

    
    function no_photos() { 
    	global $wpdb;
    
    	$emails = array();
    	
    	$ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->prefix}users" );
    
    	foreach( $ids as $id ) { 
    
    		$avatar_check = false;
       
    		if ( bp_core_fetch_avatar( array( 'item_id' => $id, 'no_grav' => true, 'html'=> false ) ) != bp_core_avatar_default() )
    			$avatar_check = true; 
    
    		if( ! $avatar_check ) { 
    			$email = $wpdb->get_var( "SELECT user_email FROM {$wpdb->prefix}users WHERE ID = $id" );
    			$emails[] = $email;
    		}
    	}
    		
    	$emails = implode(",", $emails);
    		
    	return $emails;
    		
    }
    rodhewitt
    Participant

    Hello im looking for same solution , im looking for days, all solutions uses too many CPU resources because avatars are not stored in database

    I found this code add to functions.php but its not working for me

    ________________________________________________________________________________________________

    //Hide members without avatars
    add_action( ‘bp_core_delete_existing_avatar’, ‘log_avatar_deleted’ );
    add_action( ‘xprofile_avatar_uploaded’, ‘log_avatar_uploaded’ );

    //on new avatar upload, record it to user meta
    function log_avatar_uploaded(){
    update_user_meta(bp_loggedin_user_id(), ‘has_avatar’, 1);
    }

    //on delete avatar, delete it from user meta
    function log_avatar_deleted($args){
    if($args[‘object’]!=’user’)
    return;
    //we are sure it was user avatar delete
    //remove the log from user meta
    delete_user_meta(bp_loggedin_user_id(), ‘has_avatar’);
    }

    function modify_loop_and_pag($qs, $object=false) {
    global $wpdb;
    $include = ”;

    if( $object != ‘members’ )//hide for members only
    return $qs;

    $subscribers = $wpdb->get_results(“SELECT user_id FROM {$wpdb->usermeta } WHERE meta_key=’has_avatar'” , ARRAY_N );
    foreach($subscribers as $subscriber){
    $include = $include . “,” . $subscriber[0];
    }

    $args = wp_parse_args( $qs );

    //check if we are listing friends?, do not apply in this case

    if( !empty( $args[‘include’] ) ) {
    $args[‘include’] = $args[‘include’] . ‘,’ . $include;
    }
    else {
    $args[‘include’] = $include;
    }

    $qs = build_query($args);

    return $qs;

    }
    add_action( ‘bp_ajax_querystring’ , ‘modify_loop_and_pag’, 25, 2 );

    function current_user_has_avatar($id) {
    global $bp;
    if ( bp_core_fetch_avatar( array( ‘item_id’ => $id, ‘no_grav’ => true,’html’=> false ) ) != bp_core_avatar_default( ‘local’ ) ) {
    return true;
    }
    return false;
    }

    // ATTENTION
    // This code should be deleted after first site load with the code
    //
    function init_avatar_meta(){
    global $wpdb;
    $ids=$wpdb->get_col(“SELECT ID FROM $wpdb->users”);//we don’t need to check for meta value anyway
    foreach( $ids as $id ){
    if( current_user_has_avatar($id) ){
    update_user_meta( $id, ‘has_avatar’, 1 );
    } else {
    delete_user_meta( $id, ‘has_avatar’ );
    }
    }
    }
    add_action(‘init’, ‘init_avatar_meta’);

    latinosamorir
    Participant

    Hello.

    So I’m trying to do a member loop that shows only members with avatars.

    Here is my code:

    template member loop file has this line:

    bp_has_members( gd_custom_ids( 'What are your interests?', $interests ) . '&per_page=6&type=random')

    functions.php

    
    /********* SEARCH MEMBERS BASED ON PROFILE FIELDS *********/
    function gd_custom_ids( $field_name, $field_value = '' ) {
      
      if ( empty( $field_name ) )
        return '';
      
      global $wpdb;
      
      $field_id = xprofile_get_field_id_from_name( $field_name ); 
     
      if ( !empty( $field_id ) ) 
        $query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id;
      else
       return '';
      
      if ( $field_value != '' ) 
        $query .= " AND value LIKE '%" . $field_value . "%'";
          /* 
          LIKE is slow. If you're sure the value has not been serialized, you can do this:
          $query .= " AND value = '" . $field_value . "'";
          */
      
      $custom_ids = $wpdb->get_col( $query );
      $i = 0;
      $user_ids_loop = array();
      foreach ($custom_ids as $custom_id){
    	if(gd_check_avatar($custom_id)){
    	  	$user_ids_loop[$i] = $custom_id;
      		$i++;
      	}
      }  
      
      if ( !empty( $user_ids_loop ) ) {
        // convert the array to a csv string
        $custom_ids_str = 'include=' . implode(",", $custom_ids);
        return $custom_ids_str;
      }
      else
       return '';
       
    }
    
    /********* CHECK IF MEMBER HAVE AVATARS *********/
    function gd_check_avatar($user_id){
    
    	// Check for avatar.
    		$fbavatar = false;
    		$user_info = get_userdata($user_id);
    	
    		$username=$user_info->user_login;
    	
    		//  Check what information is missing? Avatar? Profile info?
    		$username = strtolower($username);
    		
    		$userfbavatar = get_user_meta($user_ID, 'facebook_uid', true);
    		
    		if (!empty( $userfbavatar ) )
    		{
    			$fbavatar= true;
    			//echo "DEBUG: user has a FB photo<br/>"; 
    		}
    		
    		if (bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() )
    		{
    			$has_photo = true; 
    			//echo "DEBUG: user has a photo<br/>"; 
    		}
    		
    		if (  $has_photo || $fbavatar)
    		{
    			$avatarchk = true;
    		}
    		
    		if(!$avatarchk){ $avatarchk=false;}
    		
    		return $avatarchk;
    }

    I have ~6,000 members on my site.

    I get this error:

    [30-May-2014 06:59:51 UTC] PHP Fatal error:  Allowed memory size of 41943040 bytes exhausted (tried to allocate 64 bytes) in /Users/giova/Sites/lam.dev/wp-content/mu-plugins/wpengine-common/patterns.php on line 331
    [30-May-2014 06:59:51 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

    I assume that the for loop in function gd_check_avatar() is not helping.

    What would be the best way to do this to reduce resources and still get only members with avatars?

    Or at least, sort the members so that the first members have an avatar.

    Thanks!

    Giovanni

    #183465
    shanebp
    Moderator

    $defaults aren’t being passed by the filter.

    Try:

    add_filter('bp_member_avatar', 'mm_hide_name_in_alt_text', 1);
    function mm_hide_name_in_alt_text( $var ) {
      var_dump( $var ); 
      return $var;
    }

    Then you should be able to tell what is being passed to the filter and adjust it accordingly.
    You could also use the filters in bp_core_fetch_avatar()

    adamt19
    Participant

    Still trying to wrap my head around taking advantage of these built in filters..

    I need to change the alt-text here so that the member’s Full name is not shown. We’re using the “Usernames Only” plugin but it does not cover a few usages of our users’ names, such as in alt-text on /members avatars, as well as in pictures.php.

    So first… avatars. The function in question:

    function bp_member_avatar( $args = '' ) {
    	echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
    }
    	function bp_get_member_avatar( $args = '' ) {
    		global $members_template;
    
    		$fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name;
    
    		$defaults = array(
    			'type'   => 'thumb',
    			'width'  => false,
    			'height' => false,
    			'class'  => 'avatar',
    			'id'     => false,
    			'alt'    => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname )
    		);
    
    		$r = wp_parse_args( $args, $defaults );
    		extract( $r, EXTR_SKIP );
    
    		return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
    	}

    and what I tried:
    /* Hide FUll Name from member avatar */

    add_filter('bp_member_avatar', 'mm_hide_name_in_alt_text');
    
    function mm_hide_name_in_alt_text() {
      $defaults = array(
        'type'   => 'thumb',
        'width'  => false,
        'height' => false,
        'class'  => 'avatar',
        'id'     => false,
        'alt'    => 'Profile Picture' );
        
        return $defaults;
    }

    Looking to understand why this isn’t working?

    #182446
    Sythenz
    Participant

    Hey there guys,

    I’ve been following Buddypress’ progress over the last few months and with the new theme development strategies in BP 1.8+ I’m finding it very difficult to develop my own theme.

    All the documentation on the BP Codex seems to either be outdated, or extremely vague and gives no guidance onto how to develop your own theme.

    The current way I’ve been developing is starting out with Eddie Machado’s bones and adding php files based on the Template Hierarchy, then calling Buddypress functions within the documents. As an example:

    
    <?php $ud = get_userdata( bp_displayed_user_id() ); ?>
    <div id="wrapper-main" class = "cf">
    <div id="profilesidebar">
    <?php bp_core_fetch_avatar( array( 'item_id' => $ud->ID,'type'=>'full','width'=>450,'height'=>450 ) ); ?>
    <?php echo $ud->user_login; ?>
    </div>

    Is this the correct way to go about developing a theme? and if not, where am I going wrong?
    – Sythen.

    #181935
    dasde
    Participant

    Hi,
    I’m using BuddyPress on my website (gowc.fr) for several month, I was using a “hack” in functions.php to use my WP avatar in BuddyPress and it was working like a charm until the last version of BuddyPress. I have updated the plugin yesterday and now all my members have the default avatar instead of their custom avatar.

    The code I was using in functions.php :

    
    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');
    
    add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 );//late load
    function revert_to_default_wp_avatar( $img, $params, $item_id ){
    	//we are concerned only with users
    	if( $params['object']!='user' )
    		return $img;
    
    	//check if user has uploaded an avatar
    	//if not then revert back to wordpress core get_avatar method
    	//remove the filter first, or else it will go in infinite loop
    	remove_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 );
    
    	if( !emi_user_has_avatar( $item_id ) ){
    		$width = $params['width'];
    		// Set image width
    		if ( false !== $width ) {
    			$img_width = $width;
    		} elseif ( 'thumb' == $width ) {
    			$img_width = bp_core_avatar_thumb_width();
    		} else {
    			$img_width = bp_core_avatar_full_width();
    		}
    		$img = get_avatar( $item_id, $img_width );
    	}
    
    	//add the filter back again
    	add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 );
    	return $img;
    }
    
    /**
    * Check if the given user has an uploaded avatar
    * @return boolean
    */
    function emi_user_has_avatar( $user_id=false ) {
    	if( !$user_id ){
    		$user_id = bp_loggedin_user_id();
    	}
    	
    	if ( bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() )
    		return true;
    	return false;
    }
    

    Please help me to solve this annoying issue.

    Thanks

    #179965
    wp_kouhai
    Participant

    I have found and corrected the issue.

    function buddypress_redirect_if_no_avatar($redirect_url,$request_url,$user) {
    
      $avatar = bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'no_grav' => true, 'html'=>false) );
    
      $pos = strpos($avatar, 'mystery-man');
      if ($pos === false) { return "/";}
      else {
        $redirect_url = bp_core_get_user_domain($user->ID)."/profile/change-avatar/";
        return $redirect_url;
      }
    
    }
    
    add_filter("login_redirect","buddypress_redirect_if_no_avatar",100,3);
    #179949
    #179514

    In reply to: 3rd Sized Avatar

    Henry Wright
    Moderator

    So, with the code I suggested in place. You can output the 3 sized avatars on your site like this:

    Thumb size:

    $type = 'thumb';
    $width = 200;
    $height = 200;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'type' => $type, 'title' => $user_fullname ) );

    Full size:

    $type = 'full';
    $width = 500;
    $height = 500;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'type' => $type, 'title' => $user_fullname ) );

    Tiny thumb size:

    $width = 20;
    $height = 20;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'title' => $user_fullname ) );

    Note: It isn’t recommended to change core files in this way because you’ll lose the changes you made on each upgrade. But it’s what you asked for so… 🙂

    #179509

    In reply to: 3rd Sized Avatar

    darqpony
    Participant

    Yes! that! Since I know so little about php coding, I didn’t know WHAT to do instead of the choice it gave me or where to look.

    1. I understand about the upgrade will overwrite thing. If I put this bit of code in my bpcustom.php file, will it override the original “$avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb;” or do I have to somehow negate that first in the bpcustom file?

    2. I have this in the bp_core_fetch_avatar:

    function bp_core_fetch_avatar( $args = '' ) {
    
    	// If avatars are disabled for the root site, obey that request and bail
    	if ( ! buddypress()->avatar->show_avatars )
    		return;
    
    	global $current_blog;
    
    	$bp = buddypress();
    
    	// Set a few default variables
    	$def_object = 'user';
    	$def_type   = 'thumb';
    	$def_class  = 'avatar';
    
    	// Set the default variables array
    	$params = wp_parse_args( $args, array(
    		'item_id'    => false,
    		'object'     => $def_object, // user/group/blog/custom type (if you use filters)
    		'type'       => $def_type,   // tinythumb, thumb or full
    		'avatar_dir' => false,       // Specify a custom avatar directory for your object
    		'width'      => false,       // Custom width (int)
    		'height'     => false,       // Custom height (int)
    		'class'      => $def_class,  // Custom <img> class (string)
    		'css_id'     => false,       // Custom <img> ID (string)
    		'alt'        => '',    	     // Custom <img> alt (string)
    		'email'      => false,       // Pass the user email (for gravatar) to prevent querying the DB for it
    		'no_grav'    => false,       // If there is no avatar found, return false instead of a grav?
    		'html'       => true,        // Wrap the return img URL in <img />
    		'title'      => ''           // Custom <img> title (string)
    	) );
    	extract( $params, EXTR_SKIP );
    

    Where do I ‘pass’ thumb or full to it? Or is it already there in this original since I haven’t changed anything yet?

    3. If I change the bp_core_fetch_avatar, do I have to somehow change the first 1.’s solution?

    4. Should I post this on the other site you found my question on? LOL (Hey, I gave it two days before trying a different site! But got the same guy answering… go figure… LOL)

    … and yes, it did use the tinythumb type and it did make the thumb sized avatar fuzzy. I have an avatar for that size. I want it to use it! LOL I want to use ALL my avatars!

    #179497

    In reply to: 3rd Sized Avatar

    Henry Wright
    Moderator

    You’d change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb; to:

    if ($type == 'full' ) {
        $avatar_size = '-bpfull';
    } elseif ($type == 'thumb' ) {
        $avatar_size = '-bpthumb';
    } else {
        $avatar_size = '-bptinythumb';
    }

    But that approach wouldn’t be recommended because when you upgrade buddypress your changes will be lost.

    The tiny thumb will be the default avatar size. If you wanted to use the thumb or full versions then you’d need to pass thumb or full to bp_core_fetch_avatar

    #179475

    In reply to: 3rd Sized Avatar

    darqpony
    Participant

    Yes, I already have the different various sizes of avatar. I have the Tinythumb, Thumb, and Full sizes. And I can change them to whatever width and height I’d like them to be. I could make miiiiyyyons of them if I so chose. Thumb1, Thumb2, Thumb3, etc. . . . Not the issue. I’m stuck in the calling of them to my themes widget. I can call only two of those sizes. If I change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’; to add ‘-bptinythumb’, it defaults back to the default of full and bpfull or bpthumb. I can’t get it to USE bptinythumb in the theme. Or in actuality, to USE more than two, hence I need it to SEE the third size avatar.

    🙂

    And thanks so much for taking a look at this guys.

    PS: And I’m gonna check to see what bp_core_fetch_avatar does… maybe rewriting it will get me what I want. Maybe you guys know already how I should rewrite it? *Hint hint* LOL

    #179470

    In reply to: 3rd Sized Avatar

    Henry Wright
    Moderator

    Hi @darqpony

    1. Thumbs

    define ( 'BP_AVATAR_THUMB_WIDTH', 20 );
    define ( 'BP_AVATAR_THUMB_HEIGHT', 20 );

    2. Full

    define ( 'BP_AVATAR_FULL_WIDTH', 150 );
    define ( 'BP_AVATAR_FULL_HEIGHT', 150 );

    3. Original

    define ( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 300 );

    4. File size

    define ( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $max_in_kb );

    Now, you can use bp_core_fetch_avatar to output either the thumb or the full size avatar. This doesn’t cover the original. You could write your own version of bp_core_fetch_avatar which will output the original as well. That’s if the original is saved. You’ll have to check that it is. I’m sure it will be but have never needed to use it so you might want to make sure.

    #179201
    modemlooper
    Moderator

    add this to your bp-custom.php file

    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

Viewing 25 results - 101 through 125 (of 310 total)
Skip to toolbar