Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'group_id'

Viewing 25 results - 101 through 125 (of 564 total)
  • Author
    Search Results
  • #270208
    Henry Wright
    Moderator

    You’re using the class method properly. This should output an array containing an array of groups and a count.

    $group_ids = BP_Groups_Member::get_group_ids( $user_id );
    var_dump( $group_ids );

    Make sure the $user_id argument you are passing to the class method is valid. It should be an integer but I don’t think type is enforced in this case so a string might also work.

    #270035

    bp_get_current_group_id() gets the ID of the current group, not the groups to which the user is a member of.

    For that you need groups_get_user_groups().

    It will return an array of group info, so you’ll have to process it further before storing it.

    Have a look here: http://hookr.io/functions/groups_get_user_groups/

    Renato Alves
    Moderator

    You can certainly use BuddyPress WP CLI for that: https://github.com/buddypress/wp-cli-buddypress

    It has a wp bp group member command.

    Something like wp bp group member remove --group-id={GROUP_ID} --user-id={MEMBER_ID}

    #269572

    In reply to: Group. Custom page

    Here’s the bare basic code to add a page to all groups:

    class my_group_page extends BP_Group_Extension {
    	function __construct() {
    		$args = array( 'slug' => 'page_slug', 'name' => 'Page Name', 'nav_item_position' => 12 );
    		parent::init( $args );
    	}
    	function display( $group_id = NULL ) {
    		// page code goes here
    	}
    }
    bp_register_group_extension( 'my_group_page' );
    #269189
    Boone Gorges
    Keymaster

    A few things to check:

    1. After submitting the first page of the group creation process, is the group actually created in the database? Check Dashboard > Groups, or the wp_bp_groups database table if you know how.

    2. Check your browser cookies to see if the bp_new_group_id and bp_completed_create_steps cookies are set. If so, please share the details, especially the Domain and Path.

    3. If you have access to PHP error logs on your server, please check them for related errors. Otherwise, consider enabling WP_DEBUG to see if anything relevant is shown after submitting the first step of the creation process.

    #269127
    AliceG
    Participant

    Thank you for your reply.
    Actually, I have a button “My group” and a none display bloc where I put this code, and a jquery shows all my groups on clic :

    <?php 
    $group_ids = groups_get_user_groups(bp_displayed_user_id());
    foreach($group_ids["groups"] as $group_id) { 
    echo('<a title="Aller sur le groupe" href="' . home_url() . '/groupes/' . groups_get_group(array( 'group_id' => $group_id )) -> slug . '">' .groups_get_group(array( 'group_id' => $group_id )) -> name . '</a>' . (end($group_ids["groups"]) == $group_id ? '' : ', ' ) ); } 
    ?>

    So this code is working on my profile page, I have all my groups. On a group page, only the group where I am shows, and everywhere else there is no list.

    So do you have an idea to show a list of “my group” everywhere?
    Thank you a lot !

    #268881
    Boone Gorges
    Keymaster

    Hi @hlubi – Generally, the sidebar is controlled by the WP theme you’re using. See sidebar.php. You’ll likely need to make your modifications in that file (probably in a child theme, if you’re not already using one).

    Exactly what modifications you make depends heavily on how you want the sidebars to differ. If you have a small number of groups, and you want the sidebar to be totally customized for each one, sidebar.php might look something like this:

    
    if ( bp_is_group() ) {
        $group_id = bp_get_current_group_id();
    
        switch ( $group_id ) {
            case 1 :
                 // group 1 sidebar
            break;
    
            case 2 :
                 // group 2 sidebar
            break;
        }
    } else {
        // existing sidebar code
    }
    

    You could even register separate sidebars for each group, so that they can be managed separately in wp-admin. (This solution obviously won’t work well if you have lots and lots of groups.)

    If you just want to have some group-specific content in the sidebar, you can use BP’s “current group” functions in sidebar.php. For example:

    
    if ( bp_is_group() ) {
        $current_group = groups_get_current_group();
        printf( 'This is the sidebar for group %s', esc_html( $current_group->name ) );
    }
    

    This way, you’d have the same *type* of data on each group’s sidebar, but the specific data would be pulled dynamically based on which group is being shown.

    #268142
    shanebp
    Moderator

    Try 0 instead of false:
    <?php if (bp_group_has_members ('group_id=1&per_page=20&exclude_admins_mods=0')) : ?>

    Re layout: you’ll have to check those functions for filter hooks and use those to adjust layout. Or make your own calls.

    #268135
    J.Parra
    Participant

    Thank you very much for your quick response, it works almost perfect.

    You can see it here: http://www.racingonlineclub.com/#agradecimientos

    First of all I can not include administrators and moderators.

    Is not this correct?

    <? php if (bp_group_has_members (‘group_id = 1 & per_page = 20 & exclude_admins_mods = false’)):?>

    And secondly I would like the name “bp_group_member_link” to appear under the avatar to better organize the grid.

    Is this possible?

    Currently the list is:

    <li style = “display: inline;”>
           <! – Example template tags you can use ->
           <? php bp_group_member_avatar ()?>
           <? php bp_group_member_link ()?>
         </ li>

    Thanks again.

    #268127
    shanebp
    Moderator

    Use bp_group_has_members and specific the id of the group.
    For example: <php if ( bp_group_has_members( 'group_id=15' ) ) : ?> etc.

    Group Members Loop

    #267892
    MSoliman
    Participant

    i’m using the buddypress groups to add a user role to members in the same group .. i hook into the groups_member_after_saveto add the role , which means when the user become a member he get the role .. and groups_member_before_remove to remove the role ,when the user leave the group the role been removed. my code is working like charm now . what i need is , to add this role when the user become admin to the group , and remove the role when he be demoted to mod or member, or be banned or removed.. this is my current code , to add the role to joined members:

    function bpmp_add_member($bp_group_admin)
    {
      $bp_group = _bpmp_get_group($bp_group_admin->group_id);
      $user = new WP_User($bp_group_admin->user_id);
      $user->add_role(_bpmp_get_role($bp_group));
    }
    
    function bpmp_remove_member($bp_group_admin)
    {
      $bp_group = _bpmp_get_group($bp_group_admin->group_id);
      $user = new WP_User($bp_group_admin->user_id);
      $user->remove_role(_bpmp_get_role($bp_group));
    }
    
    add_action('groups_member_after_save', 'bpmp_add_member', 90, 1);
    add_action('groups_member_before_remove', 'bpmp_remove_member', 10, 1);

    i just need to know what’s the right hooks to use .. i found these hooks but don’t know how to use its functions parameters with the code above

    // define the groups_promote_member callback 
    function action_groups_promote_member( $group_id, $user_id, $status ) { 
        // make action magic happen here... 
    }; 
    
    // add the action 
    add_action( 'groups_promote_member', 'action_groups_promote_member', 10, 3 );
    // define the groups_demote_member callback 
    function action_groups_demote_member( $group_id, $user_id ) { 
        // make action magic happen here... 
    }; 
    
    // add the action 
    add_action( 'groups_demote_member', 'action_groups_demote_member', 10, 2 );

    any help will be highly appreciated

    #267826
    shanebp
    Moderator

    The answer is right below the definition of the hook:

          // The following properties are required; bail if not met. 
          if ( empty( $this->user_id ) || empty( $this->group_id ) ) { 
              return false; 
          } 

    Just delete the value for one of those fields.

    #267803
    artempr
    Participant

    Hi. If it still an issue , I d recommend you to look at bp-xprofile-settings.php

    function bp_xprofile_get_settings_fields( $args = '' ) {
      //if u have ome custom user roles  you can simply filter here which groups to hide  
        if(!current_user_can("owner")){
            $query='5,6,4';
        }else{
            $query='1,3,4,5';
        }
    	// Parse the possible arguments.
    	$r = bp_parse_args( $args, array(
    		'user_id'                => bp_displayed_user_id(),
    		'profile_group_id'       => false,
    		'hide_empty_groups'      => false,
    		'hide_empty_fields'      => false,
    		'fetch_fields'           => true,
    		'fetch_field_data'       => false,
    		'fetch_visibility_level' => true,
    		'exclude_groups'         => $query,
    		'exclude_fields'         => false
    	), 'xprofile_get_settings_fields' );
    
    	return bp_has_profile( $r );
    }
    #267130
    bambidotexe
    Participant

    I found a workaround, I’am quite not completely satisfied but…

    First of all, disable members list on group:

    function change_access_group_nav_tabs() {
      if(bp_is_group()) {
        buddypress()->groups->nav->edit_nav( array( 'user_has_access' => false ), 'members', bp_current_item() );
      }
    }
    add_action( 'bp_actions', 'change_access_group_nav_tabs' );

    (btw, setting the value to true actually make the the nav items always here, but we still can’t access the group list on click)

    And then I simply add a custom BP Group Extension to make my own members list:

    class Group_Extension_List_Members extends BP_Group_Extension {
        /**
         * Here you can see more customization of the config options
         */
        function __construct() {
          $args = array(
              'slug' => 'members-list',
              'name' => 'Membres',
              'access' => array( 'anyone'),
              'show_tab' => array( 'anyone'),
              'nav_item_position' => 12,
              'screens' => array(
                  'create' => array(
                      'enabled' => false
                  ),
                  'edit' => array(
                        'enabled' => false
                  ),
              )
          );
          parent::init( $args );
        }
        function display( $group_id = NULL ) {
          //Remove user who do not belong to the group on members loop
          function filter_for_groups( $members_template_has_members, $members_template, $r ) {
            for ($i=sizeof($members_template->members)-1; $i >= 0 ; $i--) {
              $user_id = $members_template->members[$i]->id;
              if(!groups_is_user_member( $user_id, bp_get_group_id() )){
                $members_template->member_count = $members_template->member_count-1;
                array_splice($members_template->members, $i, 1);
              }
            }
            if ($members_template->member_count <= 0) {
              return '';
            } else {
              return $members_template_has_members;
            }
          };
          add_filter( 'bp_has_members', 'filter_for_groups', 10, 3 );
    
          require('/Your/theme/custom/members/loop/members-loop.php');
        }
    }
    bp_register_group_extension( 'Group_Extension_List_Members' );

    Hope it will help other in the future, And I’m still open to know the good way to proceed.

    #266841
    Brajesh Singh
    Participant

    Hi,
    Please put the following code to your bp-custom.php

    
    
    /**
     * Step 1: Store the group id in meta when there is a new comment.
     */
    function buddydev_store_group_in_activity_meta( $comment_id, $r, $activity ) {
    
    	if ( $activity->component != 'groups' ) {
    		return;
    	}
    
    	bp_activity_update_meta( $comment_id, '_group_id', $activity->item_id );
    }
    
    // hook to comment posted action
    add_action( 'bp_activity_comment_posted', 'buddydev_store_group_in_activity_meta', 10, 3 );
    add_action( 'bp_activity_comment_posted_notification_skipped', 'buddydev_store_group_in_activity_meta', 10, 3 );
    
    //Filter the action string for comment and display it.
    function buddydev_add_group_link_in_activity_comment_action( $action, $activity ) {
    
    	$group_id = bp_activity_get_meta( $activity->id, '_group_id', true );
    
    	if ( ! $group_id ) {
    		return $action;
    	}
    
    	$group = new BP_Groups_Group( $group_id );
    
    	if ( ! $group->id ) {
    		return $action;
    	}
    
    	$action = $action . sprintf( " in group <a href='%s'>%s</a>", bp_get_group_permalink( $group ), bp_get_group_name( $group ) );
    
    	return $action;
    }
    add_filter( 'bp_activity_comment_action', 'buddydev_add_group_link_in_activity_comment_action', 10, 2 );
    
    

    It records the group id in activity meta and uses that for displaying the group link.

    Please do note that it will only work for newer comments.

    Hope that helps.

    #265307
    hept27
    Participant

    Ask and ye shall receive. I figured it out, though I’m sure its not the cleanest solution:

    I created this function from the original “groups_edit_base_group_details” function

    	function bg_new_groups_edit_base_group_details( $group_id, $group_name, $group_desc, $notify_members ) {
    			global $bp;
    
    			if ( empty( $group_name ) || empty( $group_desc ) )
    				return false;
    
    			$group              = new BP_Groups_Group( $group_id );
    			$group->name        = $group_name;
    			$group->description = $group_desc;
    
    			if ( !$group->save() )
    				return false;
    
    			if ( $notify_members ) {
    				groups_notification_group_updated( $group_id, $group_id, false );
    			}
    
    			do_action( 'groups_details_updated', $group_id, $group_id, false );
    
    			return true;
    		}

    Then I put the following code in a gravity forms gform_after_submission action:

    				$group_id = 2;
    				$group_name = 'New NEw TEST';
    				$group_desc = 'testing description';
    				bg_new_groups_edit_base_group_details($group_id, $group_name, $group_desc, false); 

    This is the proof of concept the finished product will look a little different but function the same.

    #265239

    We’ve the same problem.

    But we found a solution to fix it.

    File: \htdocs\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-admin.php

    Search the function “xprofile_admin_field” and there you replace the code from Line 609 to 630 with this:

    	$field_edit_url = add_query_arg(
    		array(
    			'page'     => 'bp-profile-setup',
    			'group_id' => (int) $field->group_id,
    			'field_id' => (int) $field->id,
    			'mode'     => 'edit_field'
    		),
    		//network_admin_url( 'users.php' )
    		'users.php'
    	);
    
    	if ( $field->can_delete ) {
    		$field_delete_url = add_query_arg(
    			array(
    				'page'     => 'bp-profile-setup',
    				'field_id' => (int) $field->id,
    				'mode'     => 'delete_field'
    			),
    			//network_admin_url( 'users.php' ) . '#tabs-' . (int) $field->group_id
    			'users.php#tabs-' . (int) $field->group_id
    		);
    	}

    So it don’t create nework admin url links, just site links. This will fix it till the next update.
    I hope the BuddyPress devs will fix it in the next release 😉

    mikeboltonca
    Participant

    I’ve submitted an enhancement Trac here: https://buddypress.trac.wordpress.org/ticket/7489#ticket.

    In the meantime, I’ve implemented the following hack to allow non-members to post on a group’s activity stream:
    In /plugins/buddypress/bp-groups/bp-groups-functions.php, comment out lines 1215 and 1216.

    Original:

    if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) )
    	return false;

    Hacked:

    //if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) )
    	//return false;

    This removes the check for “Is this an admin or a group member?”, allowing anyone to post.

    #264537
    shanebp
    Moderator

    Try, after while ( bp_groups() ) : bp_the_group(); :

    $args = array( 
        'group_id' => bp_get_group_id(),
        'exclude_admins_mods' => false
    );
    
    $group_members_result = groups_get_group_members( $args );
    $group_members = array();
    
    foreach(  $group_members_result['members'] as $member ) {
    	$group_members[] = $member->ID;
    }
     
    echo implode(", ", $group_members);
    #264212

    In reply to: get events

    Henry Wright
    Moderator

    Try this:

    $args = array(
        'meta_key'       => 'group_id',
        'meta_value'     => '1',
        'meta_compare'   => '=',
        'post_type'      => 'event',
        'posts_per_page' => -1
    );
    $query = new WP_Query( $args );
    
    if ( $query->have_posts() ) {
        // Events
    } else {
        // No events
    }
    #264030
    danbp
    Participant

    Hi,

    you have to use a group_id and to ensure you’re in an appropriate loop (activity or group)

    To get a group id, you can for ex. do:

    // check for a group ID
    	if( bp_has_groups() ) {
    		// Grab current group ID
    		bp_the_group();
    		$group_id = bp_get_group_ID();
    	}	
    	
        // apply our changes only to this group ID's
    	// conditionnal action
    	if ( $group_id == 22 OR $group_id == 8 ) {  

    … and so on!

    You may also use bp_parse_args, depending where you use your custom work. In other words, you can create a complete new activity loop on a distinct page template for only one group.

    Using bp_parse_args() to filter BuddyPress template loops

    #264015
    Henry Wright
    Moderator

    I believe xprofile_insert_field() will insert or update a profile field. Here’s an example of how to use it:

    $f = xprofile_insert_field( array(
        'field_group_id' => 8,
        'type'           => 'textbox',
        'name'           => 'Foo',
        'is_required'    => false,
        'can_delete'     => false,
        'description'    => 'This is a description.'
    ) );

    On success, $f will be the ID of the new field.

    #263782
    shanebp
    Moderator

    >Am I on the right track?

    This is wrong. bp_get_group_id(get_current_user_id());
    Look up that function to see how it is used.

    Ask LearnDash how to get the group id on the LearnDash screen that you want to use.

    #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?

    #263778
    shanebp
    Moderator

    Try using bp_get_group_id().
    If you can get the group id, then use groups_get_group_admins( $group_id ) to get the group admins.
    Pull out the user ids of the group admins and use the ids to get the user data that you want.

    NOTE: you should be asking LearnDash these questions.
    By asking them here, you are asking volunteers to answer questions about a third-party premium plugin.
    Therefore, you most likely won’t get much assistance here.

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