Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 1 through 25 (of 303 total)
  • Author
    Search Results
  • #332122
    fusionbudd
    Participant

    Two 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.

    #330322
    kindabisu
    Participant

    To 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.

    #328533
    HerveSLT
    Participant

    Hello,

    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 !

    #319844
    shanebp
    Moderator

    It 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.

    See bp_core_fetch_avatar

    If not found, the default image is used.

    #319017
    shanebp
    Moderator

    There are several filter hooks you could try.
    Look towards the bottom of function bp_core_fetch_avatar in this file:
    wp-content\plugins\buddypress\bp-core\bp-core-avatars.php

    For 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 );
    #318997
    shanebp
    Moderator

    Are 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
        ) 
    );
    #313344
    grosfaignan
    Participant

    hello

    i writed this code part for wordpress :

    
    <?php $av_id=bp_get_group_id();?>
    <div class="img_group" style="background: no-repeat url('<?php echo(bp_core_fetch_avatar('item_id='.$av_id.'&object=group&no_grav=true&html=false'));?>');" ></div>

    in my google chrome code inspector i have this html output :

    
    <div class="img_group" style="background: no-repeat url("http://localhost/001-blueprint/wp-content/uploads/group-avatars/2/5f3252e75e000-bpthumb.png");"></div>

    and i have this css line in my chrome inspector too, i have image miniature on flyhover so image seems to be charged.

    
    element.style {
        background: no-repeat url(http://localhost/001-blueprint/wp-content/uploads/group-avatars/2/5f3252e75e000-bpthumb.png);
    }

    problem, i don’t have anything on my website …

    #313242
    tbako
    Participant

    Hi 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=large

    Tried changing but it shows the author profile pic on the liked space.

    Can anyone help me?

    Thanks!

    #310368
    Carlen
    Participant

    You 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’ ) )

    vuture
    Participant

    Hello,

    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,
    Chris

    #309653
    Mathieu Viet
    Moderator

    Hi @mohamedbakry83,

    In this case you’ll need to copy the email template into a /buddypress/assets/email/single-bp-email.php file 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.

    #308645

    In reply to: Fetch user’s avatar

    jbrandsma
    Participant

    Welp, 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);

    #307725
    Ben Roberts
    Participant

    Try 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.

    DurdenBlog
    Participant

    Hi all,

    I really need help. I can not find the bug by myself. I am creating a custom widget to be able to display on the homepage of my site the groups a user is a member of (whether the group is hidden or not).

    I managed to retrieve the groups and their avatar and then display them in the widget. Everything works well but as soon as I want to place it in front of others, there are display bugs. The other widgets fit in my widget!

    Here is the code I wrote in my functions.php :

    // Display groups a user is member of + linked
    function user_group_memberships( $user_id = null, $show_hidden = false ) {
    
    	$group_ids = groups_get_user_groups($user_id);
    	$i = 1;
    	$visible_group_ids = array();
    	
    	foreach($group_ids["groups"] as $group_id) { 
    		if (!$show_hidden) {
    			if(groups_get_group(array( 'group_id' => $group_id )) -> status !== 'hidden') {
    			$visible_group_ids[] = $group_id;
    			}
    		} else {
    		$visible_group_ids[] = $group_id;
    		}
    	}
    	
    	if (empty($visible_group_ids)) {
    		echo 'None';
    	} else {
    		echo '<ul id="" class="" aria-live="polite" aria-relevant="all" aria-atomic="true">';
    		foreach($visible_group_ids as $visible_group_id) {
    	
    			$avatar = bp_core_fetch_avatar( array(
    				'item_id' => $visible_group_id,
    				'object' => 'group',
    				'type' => $type,
    				'avatar_dir' => 'group-avatars',
    				'alt' => $alt,
    				'css_id' => $id,
    				'class' => 'avatar',
    				'width' => $width,
    				'height' => $height
    				));
    				?>
    				<li class="odd public is-member group-has-avatar">
    					<div class="item-avatar">
    						<a href="' <?php echo home_url() . '/groups/' . groups_get_group(array( 'group_id' => $visible_group_id )) -> slug ?>'"><?php echo $avatar ?></a>
    					</div>
    					<div class="item">
    						<div class="item-title">
    							<a href="' <?php echo home_url() . '/groups/' . groups_get_group(array( 'group_id' => $visible_group_id )) -> slug ?>'"><?php echo groups_get_group(array( 'group_id' => $visible_group_id )) -> name ?></a><?php echo (end($visible_group_ids) == $visible_group_id ? '' : ' ' )?>
    						</div>
    					</div>
    				</li>			
    			<?php if ($i++ == 3) break;
    		}
    		echo '</ul>';
    	}
    }

    And here the code I use in my Widget :
    return user_group_memberships(get_current_user_id(), true);

    #307226
    a608237
    Participant

    So 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_uploaded in place of xprofile_updated_profile, but with it, the function doesn’t seem to work at all. Can someone comment on why?

    #307225
    a608237
    Participant

    I’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); 
    }
    #304726

    In reply to: Lightbox profile image

    Venutius
    Moderator

    Hi 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.

    #304716

    In reply to: Lightbox profile image

    Venutius
    Moderator

    What 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.

    Mike Witt
    Participant

    Hi,

    On our site we have a default image that is used instead of the the user’s normal gravatar, until they set their profile photo. In my functions.php I’ve disabled the standard gravatar upload with

    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

    and substituted our image with:

    function bp_set_avatar_constants() {
       define(
        'BP_AVATAR_DEFAULT',
        site_url('/wp-content/uploads/default.png')
        );
       define(
        'BP_AVATAR_DEFAULT_THUMB',
        site_url('/wp-content/uploads/default.png')
        );
    }
    add_action('bp_init', 'bp_set_avatar_constants', 2);

    Now the only issue I have is that when you go to upload your photo there is the message “Your profile photo will be used on your profile and throughout the site. If there is a Gravatar associated with your account email we will use that, or you can upload an image from your computer.”

    It would be nice if I could change this to eliminate the part about the Gravatar. I believe this is in: members/single/profile/change-avatar.php

    Do I have any option other than to edit that file directly? Just looking for some guidance here about what is the right thing to do. FWIW, I’m pretty much of a novice with WP in general and certainly with BuddyPress.

    #282695
    Venutius
    Moderator

    I 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

    #282120
    Venutius
    Moderator

    You’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' );

    #282091
    gossamerzzz
    Participant

    Hello! Please help me correct errors in the code ..

    
    Warning: Declaration of BP_Group_Categories::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 339
    
    Warning: Declaration of BP_Group_Categories::edit_screen() should be compatible with BP_Group_Extension::edit_screen($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 339
    
    Warning: Declaration of BP_Group_Categories::edit_screen_save() should be compatible with BP_Group_Extension::edit_screen_save($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 339
    
    Warning: Declaration of BP_Group_Categories::create_screen() should be compatible with BP_Group_Extension::create_screen($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 339
    
    Warning: Declaration of BP_Group_Categories::create_screen_save() should be compatible with BP_Group_Extension::create_screen_save($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 339
    
    Warning: Declaration of BP_Group_Categories_UserGroups::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 390
    
    Warning: Declaration of BP_Group_Categories_UserGroups::edit_screen() should be compatible with BP_Group_Extension::edit_screen($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 390
    
    Warning: Declaration of BP_Group_Categories_UserGroups::edit_screen_save() should be compatible with BP_Group_Extension::edit_screen_save($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 390
    
    Warning: Declaration of BP_Group_Categories_UserGroups::create_screen() should be compatible with BP_Group_Extension::create_screen($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 390
    
    Warning: Declaration of BP_Group_Categories_UserGroups::create_screen_save() should be compatible with BP_Group_Extension::create_screen_save($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 390
    
    Warning: Declaration of BP_Group_Categories_Create::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 508
    
    Warning: Declaration of BP_Group_Categories_Create::edit_screen() should be compatible with BP_Group_Extension::edit_screen($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 508
    
    Warning: Declaration of BP_Group_Categories_Create::edit_screen_save() should be compatible with BP_Group_Extension::edit_screen_save($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 508
    
    Warning: Declaration of BP_Group_Categories_Create::create_screen() should be compatible with BP_Group_Extension::create_screen($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 508
    
    Warning: Declaration of BP_Group_Categories_Create::create_screen_save() should be compatible with BP_Group_Extension::create_screen_save($group_id = NULL) in XXX\wp-content\plugins\bp-group-categoriestypes\includes\bp-grouptypes-classes.php on line 508

    bp-grouptypes-classes.php ====

    <?php
    class BP_Category_Group {
    	var $group_id;
    	var $parent_group_id;
    	
    	/**
    	 * BP_Category_Group()
    	 *
    	 * This is the constructor, it is auto run when the class is instantiated.
    	 * It will either create a new empty object if no ID is set, or fill the object
    	 * with a row from the table if an ID is provided.
    	 */
    	function BP_Category_Group( $group_id = null ) {
    		global $wpdb, $bp;
    		
    		if ( $group_id ) {
    			$this->group_id = $group_id;
    			
    			$this->populate( $this->group_id );
    		}
    	}
    	
    	/**
    	 * populate()
    	 *
    	 * This method will populate the object with a row from the database, based on the
    	 * ID passed to the constructor.
    	 */
    	function populate() {
    		global $wpdb, $bp, $creds;
    		$this->parent_group_id=groups_get_groupmeta($this->group_id, 'parent_cat');
    		
    	}
    	
    	function is_cat_group(){
    		global $bp;
    		if(groups_get_groupmeta($bp->groups->current_group->id, 'group_type')=='category')
    			return true;
    		return false;
    	}
    	
    	function has_sub_categories(){
    		global $wpdb,$bp;
    		$sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_groupmeta} WHERE meta_key = 'parent_cat' AND meta_value = %d", $bp->groups->current_group->id );
    		if( $wpdb->get_row( $sql ))
    			return true;
    		return false;
    	}
    	
    	function has_sub_groups(){
    		global $wpdb,$bp;
    		$sql = $wpdb->prepare( "SELECT gmcat.groupid FROM {$bp->groups->table_name_groupmeta} gmcat, {$bp->groups->table_name_groupmeta} gmtype WHERE gmcat.meta_key = 'parent_cat' AND gmcat.meta_value = %d AND gmtype.meta_key = 'group_type' AND gmtype.meta_value = 'user_group'", $bp->groups->current_group->id );
    		if( $wpdb->get_var( $sql ))
    			return true;
    		return false;
    	}
    	
    	function get_all_cats(){
    		global $wpdb, $bp;
    		$sql = $wpdb->prepare( "SELECT DISTINCT gmcat.group_id FROM {$bp->groups->table_name_groupmeta} gmcat, {$bp->groups->table_name_groupmeta} gmtype WHERE gmcat.meta_key = 'parent_cat' AND gmtype.meta_key = 'group_type' AND gmtype.meta_value = 'category'" );
    		return $wpdb->get_col( $sql );
    	}
    	
    	/**
    	 * get_sub_cats()
    	 *
    	 * Accepts three parameters group type, page number, and limit.
    	 * Returns sub category group ids based off of parameters. 
    	 */	
    	function get_sub_cats($group_type = null, $page = null, $limit = null){
    		global $wpdb, $bp;
    		if( $page && $limit ){
    			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 
    		}
    		$sql = $wpdb->prepare( "SELECT DISTINCT gmcat.group_id, gmcat.meta_key, gmcat.meta_value as parent_cat, gmtype.meta_key, gmtype.meta_value as group_type FROM {$bp->groups->table_name_groupmeta} g, {$bp->groups->table_name_groupmeta} gmcat, {$bp->groups->table_name_groupmeta} gmtype WHERE  gmcat.meta_key = 'parent_cat' AND gmcat.meta_value = {$this->group_id} AND gmtype.meta_key = 'group_type' AND gmtype.meta_value = '{$group_type}'  {$pag_sql}" );
    		$paged_groups = $wpdb->get_col( $sql );	
    		
    		$sql = $wpdb->prepare( "SELECT DISTINCT gmcat.group_id, gmcat.meta_key, gmcat.meta_value as parent_cat, gmtype.meta_key, gmtype.meta_value as group_type FROM {$bp->groups->table_name_groupmeta} g, {$bp->groups->table_name_groupmeta} gmcat, {$bp->groups->table_name_groupmeta} gmtype WHERE  gmcat.meta_key = 'parent_cat' AND gmcat.meta_value = {$this->group_id} AND gmtype.meta_key = 'group_type' AND gmtype.meta_value = '{$group_type}' AND gmcat.group_id = gmtype.group_id" );
    		$total_groups = $wpdb->get_col( $sql );
    		$count=0;
    		//todo get rid of foreach use COUNT DISTINCT instead
    		foreach($total_groups as $group_id)
    			$count++;
    		$total_groups=$count;
    		return array( 'groups' => $paged_groups, 'total' => $total_groups );
    	}
    
    /*  Dont need these anymore	save incase needed in later version
    	function is_sub_cat($id){
    		global $wpdb, $bp;
    		$sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_groupmeta} WHERE meta_key = 'parent_cat' AND meta_value = %d AND group_id = %d", $this->group_id , $id );
    		if($wpdb->get_row( $sql ))
    			return true;
    		return false;
    	}
    	
    	function is_user_group($id){
    		global $wpdb, $bp;
    		$sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_groupmeta} WHERE meta_key = 'parent_cat' AND meta_value = %d AND group_id = %d", $this->group_id , $id );
    		if($wpdb->get_row( $sql ))
    			return true;
    		return false;
    	}
    */	
    // TODO combine display_categories() and display_userGroups() into one function and add in a group type parameter
    	function display_categories(){
    		global $bp;
    		$urlstr = $_SERVER["REQUEST_URI"];
    		$current=strpos($urlstr,'?page=');
    		if(!$current){
    			$current=1;
    		}
    		else
    			$current=substr($urlstr,(int)($current)+6);
    		$limit = 5;
    		$subcats=$this->get_sub_cats('category', $current, $limit);		
    		$total_subcats = $subcats['total'];
    		$paged_subcats = $subcats['groups'];
    		$paged_subcats_num = 0;
    		foreach($paged_subcats as $groupid)
    			 $paged_subcats_num++;
    		$pagination = array(
    	  'base' => site_url() . '/' . $bp->groups->slug . '/' . bp_get_group_slug() . '/sub-categories%_%', //%_% is replaced by the format below
    	  'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
    	  'total' => round(($total_subcats / $limit)+0.4),
    	  'current' => $current,
    	  'show_all' => false,
    	  'prev_next' => true,
    	  'prev_text' => __('&larr;'),
    	  'next_text' => __('&rarr;'),
    	  'end_size' => 5,
    	  'mid_size' => 2,
    	  'type' => 'plain',
    	  'add_args' => false, // array of query args to add
    	  'add_fragment' => ''
    		);
    		?>
    		<h4>Sub Categories</h4>
    		<?php
    		if($current>1){
    			$first_group=(($current-1)*$limit)+1;
    			$sec_group = ($first_group)+$paged_subcats_num-1;
    		} else{
    			$first_group=1;
    			$sec_group = $paged_subcats_num;
    		}
    		?>
    		<div class="pag-count" id="group-dir-count">Viewing group <?php echo $first_group ?> to <?php echo $sec_group ?> (of <?php echo $total_subcats ?> groups)</div>
    		<?php
    	  	echo paginate_links( $pagination );
    	  	?>
    	  	<ul id="groups-list" class="item-list">
    	  	<?php
    		foreach($paged_subcats as $groupid){
    			$group = new BP_Groups_Group($groupid);
    			 if ( !$avatar = bp_core_fetch_avatar( array( 'item_id' => $group->id, 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'alt' => __( 'Group avatar', 'buddypress' ), 'id' => $group->id, 'class' => 'avatar' ) ) )
                 	$avatar = '<img src="' . attribute_escape( $group->avatar_thumb ) . '" class="avatar" alt="' . attribute_escape( $group->name ) . '" />';
     
    			?>
    			<li>
    					<div class="item-avatar">
    						<a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/' . $group->slug . '/'  ?>"><?php echo $avatar;//bp_get_group_avatar( 'id='.$group->id ) ?></a>
    					</div>
    		
    					<div class="item">
    						<div class="item-title"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/' . $group->slug . '/' ?>"><?php echo $group->name ?></a></div>
    						<div class="item-meta"><span class="activity"><?php printf( __( 'active %s ago', 'buddypress' ), bp_get_group_last_active($group) ) ?></span></div>
    		
    						<div class="item-desc"><?php echo bp_create_excerpt( bp_get_group_description($group), 20) ?></div>
    		
    						<?php do_action( 'bp_directory_groups_item' ) ?>
    					</div>
    					
    					<div class="action">
    						<?php bp_group_join_button($group) ?>
    
    					<div class="meta">
    						<?php bp_get_group_type($group) ?>
    					</div>
    
    						<?php do_action( 'bp_directory_groups_actions' ) ?>
    					</div>
    		
    					<div class="clear"></div>
    			</li>
    			
    			<?php	
    		}
    		?>
    		</ul>
    		<?php
    		echo paginate_links( $pagination );	
    	}
    	
    	function display_userGroups(){
    		global  $bp;
    		$urlstr = $_SERVER["REQUEST_URI"];
    		$current=strpos($urlstr,'?page=');
    		if(!$current){
    			$current=1;
    		}
    		else
    			$current=substr($urlstr,(int)($current)+6);
    		$limit = 20;
    		$subcats=$this->get_sub_cats('user_group', $current, $limit);
    		$total_subcats = $subcats['total'];
    		$paged_subcats = $subcats['groups'];
    		$paged_subcats_num = 0;
    		foreach($paged_subcats as $groupid)
    			 $paged_subcats_num++;
    		$pagination = array(
    	  'base' => site_url() . '/' . $bp->groups->slug . '/' . bp_get_group_slug() . '/groups%_%', //%_% is replaced by format (below)
    	  'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
    	  'total' => round(($total_subcats / $limit)+0.4),
    	  'current' => $current,
    	  'show_all' => false,
    	  'prev_next' => true,
    	  'prev_text' => __('&larr;'),
    	  'next_text' => __('&rarr;'),
    	  'end_size' => 5,
    	  'mid_size' => 5,
    	  'type' => 'plain',
    	  'add_args' => false, // array of query args to add
    	  'add_fragment' => ''
    		);
    		?>
    					<h4>Groups</h4>
    		<?php
    		if(!((int)$total_subcats>0)):
    		?>
    			<div id="message"><p>Sorry there are no groups filed under this category.  You can create one if you like.</p></div>
    		<?php
    		else:
    		if($current>1){
    			$first_group=(($current-1)*$limit)+1;
    			$sec_group = ($first_group)+$paged_subcats_num-1;
    		} else{
    			$first_group=1;
    			$sec_group = $paged_subcats_num;
    		}
    		?>
    		<div class="pag-count" id="group-dir-count">Viewing group <?php echo $first_group ?> to <?php echo $sec_group ?> (of <?php echo $total_subcats ?> groups)</div>
    		<?php
    		endif;
    		echo paginate_links($pagination);
    		?>
    			<ul id="groups-list" class="item-list">
    		<?php
    		foreach($paged_subcats as $groupid){
    			$group = new BP_Groups_Group($groupid);
    			if ( !$avatar = bp_core_fetch_avatar( array( 'item_id' => $group->id, 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'alt' => __( 'Group avatar', 'buddypress' ), 'id' => $group->id, 'class' => 'avatar' ) ) )
                 	$avatar = '<img src="' . attribute_escape( $group->avatar_thumb ) . '" class="avatar" alt="' . attribute_escape( $group->name ) . '" />';
     
    			?>
    			<li>
    					<div class="item-avatar">
    						<a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/' . $group->slug . '/'  ?>"><?php echo $avatar;//bp_group_avatar( 'type=thumb&width=50&height=50&class=avatar&id='.$group->id ) ?></a>
    					</div>
    		
    					<div class="item">
    						<div class="item-title"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/' . $group->slug . '/' ?>"><?php echo $group->name ?></a></div>
    						<div class="item-meta"><span class="activity"><?php printf( __( 'active %s ago', 'buddypress' ), bp_get_group_last_active($group) ) ?></span></div>
    		
    						<div class="item-desc"><?php bp_create_excerpt( $group->description, 20 ) ?></div>
    		
    						<?php do_action( 'bp_directory_groups_item' ) ?>
    					</div>
    		
    					<div class="action">
    						<?php bp_group_join_button($group) ?>
    		
    						<div class="meta">
    							<?php echo bp_get_group_type($group) ?> / <?php echo $group->total_member_count; ?>
    						</div>
    		
    						<?php do_action( 'bp_directory_groups_actions' ) ?>
    					</div>
    		
    					<div class="clear"></div>
    			</li>
    			
    			<?php	
    		}
    		?>
    		</ul>
    		<?php
    		echo paginate_links( $pagination );
    	}
    	
    }
    // TODO combine all these group extensions into one if possible and move these out of here
    class BP_Group_Categories extends BP_Group_Extension {	
    
    	function BP_Group_Categories() {
    		global $bp;
    		$this->name = 'Sub Categories';
    		$this->slug = 'sub-categories';
    		$this->visibilty='public';
    		$this->enable_edit_item=false;
    		$this->enable_create_step = false;
    		$this->nav_item_position = 41;
    		$this->enable_nav_item = $this->enable_nav_item(); // make sure this is a categories group and it has sub categories
    		bp_core_remove_subnav_item( $bp->groups->slug, 'send-invites' );
    		bp_core_remove_subnav_item( $bp->groups->slug, 'members');
    	}
    
    	function create_screen() {
    
    	}
    
    	function create_screen_save() {
    
    	}
    
    	function edit_screen() {
    
    	}
    
    	function edit_screen_save() {
    	}
    
    	function display() {
    		/* Use this function to display the actual content of your group extension when the nav item is selected */
    		global $bp,$wp_query;
    		$displaygroup= new BP_Category_Group($bp->groups->current_group->id);
    		$displaygroup->display_categories();
    	}
    	
    	function enable_nav_item() {
    	if ( ( BP_Category_Group::has_sub_categories() ) )
    		return true;
    	else
    		return false;
    	}
    
    	function widget_display() { 
    		
    	}
    }
    if(BP_Category_Group::is_cat_group())
    bp_register_group_extension( 'BP_Group_Categories' );
    
    class BP_Group_Categories_UserGroups extends BP_Group_Extension {	
    
    	function BP_Group_Categories_UserGroups() {
    		global $bp;
    		$this->name = 'Groups';
    		$this->slug = 'groups';
    		$this->visibilty='public';
    		$this->enable_edit_item=false;
    		$this->enable_create_step = false;
    		$this->nav_item_position = 51;
    		$this->enable_nav_item = true; // make sure this is a categories group and it has sub categories
    		bp_core_remove_subnav_item( $bp->groups->slug, 'send-invites' );
    		bp_core_remove_subnav_item( $bp->groups->slug, 'members');
    	}
    
    	function create_screen() {
    
    	}
    
    	function create_screen_save() {
    
    	}
    
    	function edit_screen() {
    
    	}
    
    	function edit_screen_save() {
    	}
    
    	function display() {
    		// Use this function to display the actual content of your group extension when the nav item is selected 
    		global $bp;
    		$displaygroup= new BP_Category_Group($bp->groups->current_group->id);
    		$displaygroup->display_userGroups();
    	}
    
    	function widget_display() { ?>
    		<div class="info-group">
    			<h4><?php echo attribute_escape( $this->name ) ?></h4>
    			<p>
    				You could display a small snippet of information from your group extension here. It will show on the group
    				home screen.
    			</p>
    		</div>
    		<?php
    	}
    }
    if(BP_Category_Group::is_cat_group())
    bp_register_group_extension( 'BP_Group_Categories_UserGroups' );
    
    	function display_breadcrumb(){
    		global $bp;
    		?>
    		<div style="float:left;"id="bp-group-cat-breadcrumb">
    		<div style="float:left;margin:0;padding:0;">
    					<a title="Go To Home." href="<?php echo $bp->root_domain . '/'; ?>">Home</a>
    		</div>
    		<div style="float:left;margin:0;padding:0;">
    					&rarr; <a title="Go To Groups." href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/'; ?>">Groups</a>
    		</div>
    		<?php
    		$breadcrumb="";
    		$group_id=$bp->groups->current_group->id;
    			while($group_id!=-1&&$group_id!=0):
    				$group= new BP_Groups_Group($group_id);
    				$breadcrumb=substr_replace($breadcrumb,'<div style="float:left;margin:0;padding:0;">&rarr; <a title="Go To Group '.$group->name.'." href="'.bp_get_group_permalink($group).'">'.$group->name.'</a></div>',0,0);
    				$group_id=groups_get_groupmeta($group_id, 'parent_cat');
    			endwhile;
    			echo $breadcrumb;
    		?></div>
    		<?php
    	}
    	add_action('bp_after_group_header' , 'display_breadcrumb');
    	function display_create(){
    		global $bp;
    		?>
    				<label for="target_uri"><?php _e( 'How to categorize this group?', 'bp-group-types' ) ?></label>
    				<select name="bp-groupcats-parent-group">
     				<option selected="selected"value="0">No Category</option>
    				 			<?php $catgroups = BP_Category_Group::get_all_cats();
    				 			foreach($catgroups as $catid):
    				 				$catgroup = new BP_Groups_Group($catid);
    				 				$parent = (int)groups_get_groupmeta($bp->groups->current_group->id,'parent_cat');
    				 				?>	
    				    			<option <?php if($parent==$catid) echo'selected="selected"' ?>value="<?php echo $catid; ?>"><?php echo $catgroup->name; ?></option>
    							<?php endforeach; ?>
    				</select>
    		<?php if(is_site_admin()):
    			if(groups_get_groupmeta($bp->groups->current_group->id, 'group_type')=='category')
    				$current_type=groups_get_groupmeta($bp->groups->current_group->id, 'group_type');
    			else
    				$current_type='user_group';
    		?>
    		<label for="target_uri"><?php _e( 'What type of group?', 'bp-group-types' ) ?></label>
    			<input type="radio" name="bp-group-type" value="user_group" <?php if($current_type=='user_group') echo 'CHECKED'  ?> /> User Group<br />
    			<input type="radio" name="bp-group-type" value="category" <?php if($current_type=='category') echo 'CHECKED' ?> /> Category
    		<?php
    		endif;
    	}
    
    	function display_create_save(){
    		global $bp;
    		if(isset($_POST['bp-groupcats-parent-group']))
    			groups_update_groupmeta($bp->groups->current_group->id, 'parent_cat',$_POST['bp-groupcats-parent-group']);
    		else
    		groups_update_groupmeta($bp->groups->current_group->id,'parent_cat', 0);
    		if(isset($_POST['bp-group-type']))
    		groups_update_groupmeta($bp->groups->current_group->id,'group_type',$_POST['bp-group-type']);
    		else
    		groups_update_groupmeta($bp->groups->current_group->id,'group_type','user_group');
    	}
    
    class BP_Group_Categories_Create extends BP_Group_Extension {	
    
    	function BP_Group_Categories_Create() {
    		global $bp;
    		$this->name = 'Category';
    		$this->slug = 'category';
    		$this->visibilty='public';
    		$this->enable_edit_item=true;
    		$this->create_step_position = 2;
    		$this->enable_nav_item = false;
    	}
    
    	function create_screen() {
    		global $bp;
    		if ( !bp_is_group_creation_step( $this->slug ) )
    			return false;
    		
    		display_create();
    		wp_nonce_field( 'groups_create_save_' . $this->slug );
    	}
    
    	function create_screen_save() {
    		global $bp;
    		check_admin_referer( 'groups_create_save_' . $this->slug );
    		display_create_save();
    	}
    
    	function edit_screen() {
    		global $bp;
    		display_create();
    		?>
    		<br /><br />
    		<input type="submit" name="save" value="Save Category Settings" />
    		<?php
    		wp_nonce_field( 'groups_edit_save_' . $this->slug );
    	}
    
    	function edit_screen_save() {
    		global $bp;
    		if(!isset($_POST['save']))
    			return false;
    		check_admin_referer( 'groups_edit_save_' . $this->slug );
    		display_create_save();
    	}
    
    	function display() {
    
    	}
    
    	function widget_display() {
    
    	}
    }
    bp_register_group_extension( 'BP_Group_Categories_Create' );
    
    ?>
    keshabee
    Participant
    /*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;
        }
    
    }

    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
    But the issue is am making use of a Buddypress Multiblog so this tend to cause issue with my avatar not being displayed in biography on post .

    Thanks in advance.

    #279042
    keshabee
    Participant

    Hi @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

    #276394
    Prashant Singh
    Participant

    Hi,
    There is a filter code already written to modify this:

    return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array(
    			'item_id' => $item_id,
    			'object'  => $object,
    			'type'    => $type,
    			'alt'     => $alt,
    			'class'   => $class,
    			'width'   => $width,
    			'height'  => $height,
    			'email'   => $email
    		) ) );

    You can use this filter to write your own code to modify the class parameter.

    Thanks

Viewing 25 results - 1 through 25 (of 303 total)
Skip to toolbar