Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 26 through 50 (of 258 total)
  • Author
    Search Results
  • 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

    T_ed
    Participant

    I have both Buddypress and bbpress installed. bbpres is using local wordpress avatars that registered users uploaded even before bbpress was installed. I want Buddypress to do the same – use these local avatars instead of its own. I have found this code on bbpress codex and internets:

    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

    I added this code to bp-custom.php, but it`s seems like this code is not working anymore? I really need to make Buddypress to use local avatars just like bbpress do, please help.

    #276071
    justingut
    Participant

    I apologize if this is something fairly easy but I’m a bit of a beginner when it comes to this stuff. I’m looking to display my Group Mod’s member types above their names on the group page I have created but all I can get is the id to show up which of course is not user friendly when it comes to reading it. I have pasted the code I have below if anyone could please help me with this. Thank You!

    function bp_group_list_mods( $group = false ) {
    	global $groups_template;
    
    	if ( empty( $group ) ) {
    		$group =& $groups_template->group;
    	}
    
    	if ( ! empty( $group->mods ) ) : ?>
    
    		<ul id="group-mods">
    
    			<?php foreach( (array) $group->mods as $mod ) { ?>
    
    				<li id="groupmods-list"><div class="item-avatar">
    					<a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>" class="bp-tooltip" data-bp-tooltip="<?php printf( ('%s'),  bp_core_get_user_displayname( $mod->user_id ) ); ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'email' => $mod->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ) ) ) ) ?></a></div>
    				<div class="item">
    				<div class="groupmod-type"><p><?php printf( ('%s'),  bp_get_member_type( $mod->user_id) );  ?></p></div>
    				<div class="groupmod-name"><p><?php printf( ('%s'),  bp_core_get_user_displayname( $mod->user_id ) );  ?><p></div>
    
    			</div>
    				</li>
    
    			<?php } ?>
    
    		</ul>
    #274623

    In reply to: Default Profile Photo

    Venutius
    Moderator

    Just tested it, create a bp-custom.php in your plugins directory and add the following:

    define ( 'BP_AVATAR_DEFAULT', 'http://example.com/default-avatar.jpg' );
    define ( 'BP_AVATAR_DEFAULT_THUMB', 'http://example.com/default-avatar-thumb.jpg' );
    
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    jasbirs
    Participant

    <?php echo bp_core_fetch_avatar ( array( ‘item_id’ => $logged_user_id, ‘type’ => ‘full’, ‘html’ => TRUE )); ?>
    But this is working with single wordpress site

    #271679
    Jonas
    Participant

    Digging into it a bit more, it seems gravatars influences it. You can disable the gravatars like so

    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

    followed by using your original code

    define ( 'BP_AVATAR_DEFAULT', 'http://example.com/default-avatar.jpg' );
    define ( 'BP_AVATAR_DEFAULT_THUMB', 'http://example.com/default-avatar-thumb.jpg' );
    #270956
    David Cavins
    Keymaster

    Hi I’m not exactly sure what you mean, but if you’re looking to get the profile image associated with a group or user, you can use the avatar-fetching function that BP uses in its templates, bp_core_fetch_avatar():
    https://buddypress.trac.wordpress.org/browser/tags/2.9.3/src/bp-core/bp-core-avatars.php#L99

    As an example, you might use

    bp_core_fetch_avatar( array(
    			'item_id' => $user_id,
    			'type'    => 'thumb',
    			'width'   => false,
    			'height'  => false,
    			'html'    => true,
    			'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), 'user name' )
    ) );
    
    #268808

    In reply to: Goodbye Buddypress?

    David Cavins
    Keymaster

    Hi @VentureCore-

    It seems like you can make avatars work remotely. Check bp_core_fetch_avatar() for some filter opportunities. https://buddypress.trac.wordpress.org/browser/tags/2.9.2/src/bp-core/bp-core-avatars.php#L98

    I’ve not done what you’re trying to do, but it seems that the filter points bp_core_avatar_folder_url, bp_core_avatar_folder_dir could be useful, but there’s a filter on the final result at bp_core_fetch_avatar for the “html” output version and bp_core_fetch_avatar_url for just the url.

    Cover images should actually be easier to manage. Take a look in https://buddypress.trac.wordpress.org/browser/tags/2.9.2/src/bp-core/bp-core-attachments.php#L28

    Alternatively, you could filter the other plugin to ignore avatar and cover image requests. Lots of ways to solve this, I’d bet.

    tergra
    Participant

    Hi,

    I’ve tried to change the avatar in several ways, but everytime Buddypress comes on the way and overrides settings. My last try was to set up a random avatar for every user, looks slack but… It doesn’t work with Buddypress. Since you guys are BP specialists I thought you would be able to know how to fix this issue.
    Custom code I tried is this :
    https://ownyourbits.com/2017/01/31/custom-random-avatars-in-wordpress/#comment-2187

    Many thanks, you rock !

    #266477
    n0madpl
    Participant

    Hey,

    The fix for that is coming in the next release of buddy press. Or at least for the part of the problem.

    You most likely get 50% of your problem from these two in my case with 6k users these amounted to the respective query execution times (from new relic), I also run buddypress + rtmedia (which is the source of this problem) as described in this ticket:

    bp_friends_prime_mentions_results() – Used by the Activity component’s @mentions to print a JSON list of the current user’s friends.

    bp_friends_prime_mentions_results – 10,000+ ms
    bp_core_fetch_avatar – 6,000+ ms

    Here’s a fix:
    https://buddypress.trac.wordpress.org/changeset/11561

    You’ll still likely stay with this massive query even for logged out users:
    WP_User_Query::query on average right now it’s at around 7,500ms.

    Good news is that with HHVM site runs much faster due to object caching straight after enabling it.

    I’ve also played around with various hosts, flywheel & wpengine sucked. What works well is Kinsta with HHVM enabled, they can also check your database and help you move to InnoDB if you’re using another one.

    Anyway man hope this helps.

    Best,

    M.

    #266431
    coolhunt
    Participant

    This worked!

    adding
    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

    this is what my bp-custom looks like now to make it work:

    define('BP_DEFAULT_COMPONENT', 'profile' );
    
    define ( 'BP_AVATAR_THUMB_WIDTH', 125 );
    define ( 'BP_AVATAR_THUMB_HEIGHT', 125 );
    define ( 'BP_AVATAR_FULL_WIDTH', 150 );
    define ( 'BP_AVATAR_FULL_HEIGHT', 150 );
    
    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');
    
    define ( 'BP_AVATAR_DEFAULT', 'https://veloXXXXXXXhive.com/wp-content/uploads/2017/06/VeloHive-Default-User-Avatar-150px-x-150px-17Teeth-EVO.png' );
    define ( 'BP_AVATAR_DEFAULT_THUMB', 'https://veloXXXXXXhive.com/wp-content/uploads/2017/06/VeloHive-Default-User-Avatar-125px-x-125px-17Teeth-EVO-THUMBNAIL.png' );

    Someone should probably update that codex doc

    #265534
    cl0ne
    Participant

    Hello everyone.

    I’ve been pulling my hair out trying to resolve this and I know it’s probably the most simply thing but that’s what I get for not having sufficient knowledge.

    So my membership plugin creates a user and adds a profile picture to WordPress’ user directory. But I need this profile picture to sync with Buddypress. I’ve learned quite a bit in pursuit in finding a solution and I feel like I’m so close and that’s why I need the help on the last mile.

    I was able to disable Buddypress’ attempts at finding a Gravatar for any given user using add_filter('bp_core_fetch_avatar_no_grav', '__return_true');. Worked great! Now, I’m staring at the “Mystery Man” and I know I need to use bp_core_fetch_avatar to change it to the local avatar uploaded to WordPress. That’s where I’m stuck. I need a snippet of code where I can plugin in the directory for it find the user and attach the profile picture!

    Any guidance would be appreciated it!

    #263898
    Sergio Peña
    Participant

    Here’s the code for anyone who wants to do the same:

    
    add_shortcode('course_mentor','group_course_mentor');
    
    function group_course_mentor($atts, $content = null){
      if(!is_user_logged_in())
        return;
      if(!bp_is_active('groups'))
        return;
      global $wpdb,$bp;
        $batches = groups_get_user_groups(get_current_user_id());
    $return = '';
      if(!empty($batches['groups'] )){
        foreach($batches['groups'] as $batch){
          $admins = groups_get_group_admins( $batch );
          foreach($admins as $admin){
            $return .=  '<a href="'.bp_core_get_user_domain($admin->user_id).'" title="'. bp_core_get_user_displayname( $admin->user_id, true ) .'">'.bp_core_fetch_avatar ( array( 'item_id' => $admin->user_id, 'type' => 'thumb' ) ) .'</a>';
          }
        }
      }
      return  $return ;
    }
    

    Credit goes to Alex @ WPLMS for this 🙂

    #263779
    Sergio Peña
    Participant

    Thank you for your response.

    I did ask Learndash and they referred me to third party programmers.

    Since I am using buddypress groups, I thought it was appropriate to ask here as well. Apologies if I was mistaken!

    So would it be something like this:

    add_shortcode('course_mentor','nex_course_mentor');
    function nex_course_mentor($atts, $content = null){
      if(!is_user_logged_in())
        return;
      if(!bp_is_active('groups'))
        return;
    
      $nex_group_id  = bp_get_group_id(get_current_user_id());
    
      if(!empty($nex_group_id)){
        foreach($nex_group_id as $nex_group_id){
          $nex_admins = groups_get_group_admins( $nex_group_id );
          foreach($admins as $admin){
            ?>
            <a href="<?php echo bp_core_get_user_domain($admin->user_id) ?>"
            title="<?php echo bp_core_get_user_displayname( $admin->user_id, true ) ?>">
            <?php echo  bp_core_fetch_avatar ( array( 'item_id' => $admin->user_id, 'type' => 'thumb' ) ) ?></a>';
      <?php
          }
        }
      }
    }

    I’m just copy/pasting and trying to connect a bunch of different answers together. As you can tell, I’m no coder.

    Since each group may have more than one group leader/mentor I had a loop in there. Hopefully that will get the ball rolling on what I’m trying to do.

    Am I on the right track?

    #263097
    bcanr2d2
    Participant

    I am trying to use the following code to turn user avatars to greyscale.

    It has never worked, but I am not sure why. I can do it temporarily via CSS, just to show how it will look (that’s not an issue) but would prefer the actual avatars to be greyscale
    Please help

    //Convert to greyscale
    add_filter('xprofile_avatar_uploaded','rb_bw_filter', 10, 2);
    
    function rb_bw_filter($meta) {
    
    //    $path = wp_upload_dir(); // get upload directory
    //    $file = $path['basedir'].'/'.$meta['file']; // Get full size image
    $file =  bp_core_fetch_avatar(array('item_id' => $other_user, 'type' => 'full','html'=>false));
       $files[] = explode(',' ,$file); // Set up an array of image size urls
    //    foreach ($meta['sizes'] as $size) {
    //       $files[] = $path['path'].'/'.$size['file'];
    //    }
    
        foreach ($files as $file) { // iterate through each image size
    
            // Convert image to grayscale credit to http://ottopress.com/2011/customizing-wordpress-images/
    
            list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
            $image = wp_load_image($file);
            imagefilter($image, IMG_FILTER_GRAYSCALE);
            switch ($orig_type) {
                case IMAGETYPE_GIF:
                    imagegif( $image, $file );
                    break;
                case IMAGETYPE_PNG:
                    imagepng( $image, $file );
                    break;
                case IMAGETYPE_JPEG:
                    imagejpeg( $image, $file );
                    break;
            }
        }
        return $meta;
    }
    #262809
    brightwash
    Participant

    define ( ‘BP_AVATAR_DEFAULT_THUMB’, $img_url );

    This was not working for me either, in the end this combination did. Turning off gravatar (first filter), and then a default bp image filter.

    
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    add_filter( 'bp_core_default_avatar_user', 'override_default_avatar', 10, 2 );
    function override_default_avatar( $default, $params ) {
    	if ( !empty($params) ) {
    		if ( 'thumb' == $params['type'] ) {
    			return  get_stylesheet_directory_uri() . '/img/avatar-thumb.jpg'; 
    		} 
    	}
    	return  get_stylesheet_directory_uri() . '/img/avatar.jpg'; 
    }
    #261814

    In reply to: Duplicate Queires

    daniel27lt
    Participant

    So this doesn’t matter then when update_meta_cache is called twice?

    It seems to be calling 2 queries and one of them bp_core_fetch_avatar_filter

    It’s just because I’m sure (not 100%) that I’ve never seen this show up until now.

    #260847
    metalhead
    Participant

    Hello Buddypress buds!

    A lot of people have been talking over the past couple of years about “how to require a profile photo upon registration. And I know it’s a risky thing to do, but many of us are willing to take that risk.

    There are a handful of plugins that try to assist with this procedure, but some fail, and some are only partially successful. The best solution that I’ve found is Xprofile Custom Fields. With this plugin, and a lot of help from the author, I’ve managed to get profile photos to be required in the registration process. However, the issue I’m having is that the users are unable to effectively change their profile photo by using the options in the Buddypress “Profile” section/menu. The user can still click “Change Profile Photo,” and it will accept their upload, but the old photo remains in the member directory & in the user’s profile itself.

    I think there must be a miscommunication occurring due to this new way of gathering the user’s original profile photo. It seems like some code, pertaining to the Buddypress “Change Profile Photo” function needs to be tweaked, but I can not pinpoint the function, which would be the first step towards fixing this issue.

    To demonstrate how I’m requiring the profile photo upload in the registration, here is the function I’ve added to my theme’s functions.php file:

    add_filter( 'bp_core_fetch_avatar', 'my_custom_avatar', 10, 2 );
    function my_custom_avatar( $avatar, $params ) {
        if ( 'user' === $params['object'] ) {
            // Get the src of the original avatar.
            $array = array();
            preg_match( '/src="([^\"]*)"/i', $avatar, $array );
            if ( count( $array ) > 1 ) {
                $old_url_avatar = $array[1];
                // Get the new url of image.
                $uploads = wp_upload_dir();
                $img = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( 5218, $params['item_id'] ) );
                if ( ! empty( $img ) ) {
                    $new_url_avatar = $uploads['baseurl'] . $img;
    
                    // Replace the old src with the new url.
                    $avatar = str_replace( $old_url_avatar, $new_url_avatar, $avatar );
                }
            }
        }
    
        // Return the avatar.
        return $avatar;
    }

    I’d like to mention that I have asked the plugin author about this, but my message on that plugin’s support forum has been deleted twice, making me think I should give the man a break.

    Here are some specifications of my site:

    The site can be reached here.

    It’s running on WordPress v4.6.1, Buddypress v2.7.0, & using BuddyPress Xprofile Custom Fields Type v2.6

    “5218” is the field ID for the “Upload Image” field.

    Thanks and sorry if I posted in an inappropriate forum, I think I chose the right one.

    #255157
    Andrew
    Participant

    I’ve been trying to work out how to get the user IDs for the notification items so I can display notification user avatars.

    Is this the best way to do it, I’ve tested this with a few users and seems to work:

    function test_notifications_avatar() {
    	
    	$bp      = buddypress();
    	$user_id = $bp->notifications->query_loop->notification->secondary_item_id;
    	
    	if ( empty( $user_id ) )
    		$user_id = $bp->notifications->query_loop->notification->item_id;
    
    	echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type'  => 'thumb' ) );
    }
Viewing 25 results - 26 through 50 (of 258 total)
Skip to toolbar