Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'group_id'

Viewing 25 results - 201 through 225 (of 567 total)
  • Author
    Search Results
  • #240458
    Henry Wright
    Moderator

    Hi @alvin341965,

    There’s a function that will help you do that. It’s called groups_is_user_creator(). The first step is to create a groups loop. The code on this page will do that for you. Then immediately after <?php while ( bp_groups() ) : bp_the_group(); ?> you could add something like this:

    if ( ! groups_is_user_creator( bp_loggedin_user_id(), bp_get_group_id() ) )
        continue;

    Some considerations:

    • I’ve used bp_loggedin_user_id(), but feel free to use something else like the displayed member’s ID.
    • The function uses BP_Groups_Member::check_is_creator() which performs a database query for each item in the loop. To improve performance you might want to write your own SQL targeting groups only you’ve created and then loop through the result set. There may already be a function that does that for you. I’m not aware of one but someone else on here might be
    • This doesn’t work well with pagination
    #240247

    In reply to: Group tab questions

    shanebp
    Moderator

    2. How would I add a extra tab in a group that I can link to a URL?

    You need to use the Group Extension API

    Group Extension API

    Since you only want it for one group, you need to check for that group id:

    if( bp_get_group_id() == 2 )
       bp_register_group_extension( 'Your_Group_Extension_Name' );
    #240213
    shanebp
    Moderator

    There is a BP function for getting the ids of the groups for which you’re an admin: get_is_admin_of

    You could use it like this:

    function my_group_admin_ids() {
    	
        $my_group_ids = BP_Groups_Member::get_is_admin_of( 1 ); //if your id = 1
    	
        foreach( $my_group_ids['groups'] as $group ) {
    	
    	$link = bp_get_group_permalink( $group );
    	
    	echo '<a href="' . $link .'">' . $group->name . '</a><br/>';
    	
        }
    }
    add_action( 'bp_before_directory_groups', 'my_group_admin_ids');

    If you want to create a custom tab to hold that info, you need to create a new li element in a template overload of this file:
    \bp-templates\bp-legacy\buddypress\groups\index.php

    #240200
    Henry Wright
    Moderator

    If you just need a quick and dirty approach for yourself to view, you could use the standard group loop to output a loop. See here.

    Then put the following snippet directly after the line: <?php while ( bp_groups() ) : bp_the_group(); ?>

    Snippet:

    <?php
    $args = array(
        'populate_extras' => true,
        'group_id => bp_get_group_id()
    );
    $group = groups_get_group( $args );
    
    if ( ! in_array( bp_loggedin_user_id(), $group->admins ) ) {
        continue;
    }
    ?>

    Notes:

    • I haven’t tested
    • This approach won’t be performant
    • I haven’t considered pagination

    That said, it should get the job done. The alternative is to write some SQL and use the wpdb class.

    #240138
    Henry Wright
    Moderator

    I may be wrong but passing a field_group_id could mean an existing field group gets updated. If no field_group_id is passed or the passed field_group_id doesn’t exist then a new field group gets created. And perhaps field group IDs don’t get recycled?

    That’s more of a guess than actual fact. The BP_XProfile_Group class is where the magic happens if you want to investigate.

    #240114

    In reply to: Per-group Identity?

    Tony G
    Participant

    Well, group meta allows meta data to be applied to groups. I’m thinking along the lines of data in the usermeta table which is only consumed by specific groups. This might be expressed as a name/value pair in the profile. So with reference to my original example, a GroupName profile value would include:
    school:Robert
    home:Bobby
    coolGame:Zarcon

    The BuddyPress Profile Shortcodes plugin allows for custom fields and related shortcodes to be used. This is much closer to my needs but still not quite there. I can’t create a profile field for every possible group. Ideally there would be a pulldown of groups to which the user belongs, where they can enter the name they wish the use for that group, and the group/name pairs would be displayed in a grid.

    Now I’m thinking one of the better user meta plugins could handle that. But I would also need to customize it so that there can only be one WP user with a specific value for a specific group. This is a unique key per group, as some reference to @Bobby can’t apply to more than one person, but the @Bobby in one group can be different from @Bobby in another group.

    On the client side, I would then need to modify bbPress to get the user name that’s specifically for the current group, rather than using wp_get_current_user()->display_name or whatever it has there. For example:
    get_user_meta($user_id,’groupName_’.$group_id,true)
    or better
    get_user_meta($user_id,’groupNames’,false)[$group_id]

    Actually I’d rather abstract all requests for a user name to a function which can then be replaced with custom code just once. I don’t suppose anyone has already done that, or it’s been proposed as a BP/BBP enhancement?

    I’m a noob with coding into WP, haven’t touched BP/bbP, and know little about the APIs, so please bear with me on the syntax and other specifics and focus on the concepts. Thanks.

    The more I try to flesh it out above the more it seems possible for me to do this myself. But it would be really helpful if someone has already done it. Or if someone with knowledge in this area can see a more direct line from an exiting plugin to the solution I’m describing.

    Thanks for your time!!

    #239908
    shanebp
    Moderator

    The first argument is an integer, not a string.
    groups_join_group( $group_id, $user_id = 0 )

    Since you are only handling 2 specific groups, you could hardcode the $group_id.
    groups_join_group( 3, $user_id );

    Or you could get the id like this:
    $group_id = groups_get_id( 'Teachers' );

    #238909
    Klosurdo
    Participant

    These are the errors I receive when trying to activate buddypress

    Strict Standards: Declaration of BBP_Forums_Group_Extension::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in /home1/cmpgorg/public_html/wp-content/plugins/bbpress/includes/extend/buddypress/groups.php on line 28

    Fatal error: Cannot redeclare kleo_bp_replace_placeholders() (previously declared in /home1/cmpgorg/public_html/wp-content/themes/kleo/lib/theme-functions.php:1894) in /home1/cmpgorg/public_html/wp-content/themes/kleo/lib/plugin-buddypress/config.php on line 105

    #238312

    In reply to: PHP Error

    shanebp
    Moderator

    Your question is better asked on the bbPress support forum.

    The fix is simple – open to the file and go to the line in question and change function display() to function display($group_id = NULL)

    #238254
    fab_pj
    Participant

    Thanks so much Dan, at least know I know where to look for!
    Activated debug, it seems like there is a conflict with bbpress, correct?

    Strict Standards: Declaration of BBP_Forums_Group_Extension::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in /home7/ealthblo/public_html/wp-content/plugins/bbpress/includes/extend/buddypress/groups.php on line 28

    #238195
    UrbanFix
    Participant

    @danbp
    I have attempted to use the ‘little plugin’ you mentioned but when I add the following two lines i get an error! COuld you please add them for me?

    $temp_post = get_post($post_id);
    $user_id = $temp_post->post_author;

    I have sucessfully changed the user id as you mentioned without any trouble.

    public function generate_activity_stream( $atts, $content = null, ) {
            //allow to use all those args awesome!
           $atts=shortcode_atts(array(
                'title'            => 'Latest Activity',//title of the section
                'pagination'       => 'true',//show or not
                'display_comments' => 'threaded',
                'include'          => false,     // pass an activity_id or string of IDs comma-separated
                'exclude'          => false,     // pass an activity_id or string of IDs comma-separated
                'in'               => false,     // comma-separated list or array of activity IDs among which to search
                'sort'             => 'DESC',    // sort DESC or ASC
                'page'             => 1,         // which page to load
                'per_page'         => 5,         //how many per page
                'max'              => false,     // max number to return
    
                // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
                'scope'            => false,
    
                // Filtering
                'user_id'          => $user_id,    // user_id to filter on
                'object'           => false,    // object to filter on e.g. groups, profile, status, friends
                'action'           => false,    // action to filter on e.g. activity_update, new_forum_post, profile_updated
                'primary_id'       => false,    // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
                'secondary_id'     => false,    // secondary object ID to filter on e.g. a post_id
    
                // Searching
                'search_terms'     => false,         // specify terms to search on
                'use_compat'       => bp_use_theme_compat_with_current_theme() 
            ), $atts );
           
            extract( $atts );
    	
          
            
            ob_start(); ?>

    Thanks,
    Urban-fix

    #238054
    shanebp
    Moderator

    afaik, even site admins and groups admins cannot edit activity stream items on the front-end.
    This will give group moderators the ability to delete activity stream items:

    function majecdad_group_mod_delete( $can_delete, $activity ) {
    	
       if( $activity->component == 'groups' ) {
    	
    	$group_id = $activity->item_id; 
    		
    	if( bp_current_user_can( 'bp_moderate' ) || groups_is_user_mod( bp_loggedin_user_id(), $group_id ) )
    	    $can_delete = true;
    	
       }
    
       return $can_delete;
    }
    add_filter('bp_activity_user_can_delete', 'majecdad_group_mod_delete', 21, 2 );
    shanebp
    Moderator

    Try using this hook fromfunction groups_delete_group in buddypress\bp-groups\bp-groups-functions.php

    do_action( 'groups_before_delete_group', $group_id );

    AntaresMHD
    Participant

    Yeah, about that… You’re right, obviously, I just assumed that since bp_pre_user_query existed, a group equivalent did as well, but apparently not! As you can imagine, I tried everything I could think of in order to make it work somehow.

    Anyway, I did the changes you proposed with the added custom query (like this)

    function antares_get_groups() {
    global $wpdb;
    
    $sql = "SELECT g.id
    FROM 
    	{$wpdb->prefix}user_league_prediction as p,
    	{$wpdb->prefix}bp_groups_members as m,
    	{$wpdb->prefix}bp_groups as g
    WHERE 
    	g.id = m.group_id AND m.user_id = p.user_id
    GROUP BY
    	m.group_id";
    
    $buff = array();
    
    $result = $wpdb->get_results( $sql , OBJECT );
    
    		foreach ($result as $row) {
    			$buff[]= $row->id ;
    		}
    		
    $query_str= implode (',', $buff);
    return $query_str;
    }

    And it works! The only issue now is with the pagination, because even though it’s reading the number of groups correctly and displaying them on the list, when I click on the numbers it just doesn’t do anything. I checked the web console and the parameter 2&num is being passed correctly but it doesn’t do a thing. I suspect this is another problem with ajax.

    Either way you’ve been of great help, thank you.

    Svend Rugaard
    Participant

    I have now try a diffrent approach to make a clean install and use debug mode just to make sure also all the themes change i have make the last year wasnt make this error happen it give me these errors on member page with debug on :

    Strict Standards: Declaration of BBP_Forums_Group_Extension::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in /home/www/area51.ps3geeks.dk/wp-content/plugins/bbpress/includes/extend/buddypress/groups.php on line 28
    
    Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in /home/www/area51.ps3geeks.dk/wp-includes/functions.php on line 3547
    
    Notice: bp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 1.7.) in /home/www/area51.ps3geeks.dk/wp-includes/functions.php on line 3547
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/www/area51.ps3geeks.dk/wp-content/plugins/bbpress/includes/extend/buddypress/groups.php:28) in /home/www/area51.ps3geeks.dk/wp-includes/pluggable.php on line 1178

    Some of them even show as “Solved” on google search but obviosly they aint solved.

    Svend Rugaard
    Participant

    Okay now i have try to make a complete mirror on my site it gives me this error with dedub on

    Strict Standards: Declaration of BBP_Forums_Group_Extension::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in /home/www/area51.playstationforum.dk/wp-content/plugins/bbpress/includes/extend/buddypress/groups.php on line 28
    
    Notice: bbp_setup_current_user er kaldt forkert. The current user is being initialized without using $wp->init(). Se Fejlsøgning i WordPress for at finde flere oplysninger. (Denne meddelelse blev tilføjet i version 2.3). in /home/www/area51.playstationforum.dk/wp-includes/functions.php on line 3547
    
    Notice: bp_setup_current_user er kaldt forkert. The current user is being initialized without using $wp->init(). Se Fejlsøgning i WordPress for at finde flere oplysninger. (Denne meddelelse blev tilføjet i version 1.7). in /home/www/area51.playstationforum.dk/wp-includes/functions.php on line 3547
    #237118
    danbp
    Participant

    Hi,

    did you searched in bbPress ?
    plugins\bbpress\includes\extend\buddypress

    maybe you’ll find some answers there ?

    like bbp_add_group_id_to_forum() in extend/buddypress/functions.php

    #236475
    5high
    Participant

    Hi @mrjarbenne,

    Thanks so much for helping – I’ve only just found your reply (don’t know what happened to the email notification this time). Anyway, I’ve added it into my bp-custom.php as suggested and Bingo! it works brilliantly. just tried a new test member and I’m instant joined to all 3 of my groups!

    Thanks so much for this. Just for clarity for others this is the code i used as per @modemlooper info above:

    function automatic_group_membership( $user_id ) {
       if( !$user_id ) return false;
     
       groups_accept_invite( $user_id, $group_id );
    }
    add_action( 'bp_core_activated_user', 'automatic_group_membership' );

    I have left the spacing exactly as he’d done, just in case… but maybe I could get rid of some of the extra spaces in it?

    Cheers 🙂

    aljo1985
    Participant

    Okay so I realised that it would only send the activity to stream when you have the email option checked. I also noticed that upon doing that you post 2 pieces of information into the database that are exactly the same.. Well they are not structured the same but the information holds the same data.

    This is inside bp_groups_groupmeta and bp_activity
    So I have optimized my code to remove duplicate data, well just removed it from posting into groupsmeta really, as it doesn’t need to be in there… Maybe you can optimize your code to post the action in activity only and read from there, rather than have it posted in both. The system is great, don’t get me wrong I am just making suggestions.

    So I have removed one of your functions on remove action and copied it into my own function with edits to that function. I have added 2 extra fields, drop down boxs to be exact.

    Here is my code with a lot of comments as I was trying out many different things, then decided I don’t want it to do that lol. EDIT

    <?php
    // Add custom group fields.
    // Removed the default add activity stream. file /public_html/wp-content/plugins/buddypress/bp-groups/bp-groups-activity.php for reference.
    remove_action( 'groups_details_updated', 'bp_groups_group_details_updated_add_activity' );
    // On group update.
    add_action( 'groups_details_updated', 'group_details_update', 10, 3 );
    // Updated group details.
    // Updated group details.
    function group_details_update( $group_id, $old_group, $notify_members ) {
    	global $bp, $wpdb;
    	// Custom fields.
    	$plain_fields = array(
    		'server',
    		'country'
    		//'activity'
    	);
    	foreach( $plain_fields as $field ) {
    		$key = 'group-' . $field;
    		$metakey = 'h1z1_' . $field;
    		if ( isset( $_POST[$key] ) ) {
    			$value = $_POST[$key];
    			
    			// Do they want the update notification posted on their activity stream?
    			/*if ($value == '1')
    				$post_activity = true;
    			*/
    			//Make sure they selected an item from the required dropdown boxs.
    			if ($value == 'null')
    				return bp_core_add_message( __( 'There was an error updating group details. Please try again.', 'buddypress' ), 'error' );
    			else {
    				// changed1 is empty by default, not declared. If empty, get groupmeta.
    				if (empty($changed))
    					$changed = groups_get_groupmeta( $group_id, $metakey );
    				//if groupmeta(old value) == posted value changed is empty again, so we can check the next custom field to see if that also has the same old value.
    				if ($changed == $value)
    					$changed = '';
    				else
    					groups_update_groupmeta( $group_id, $metakey, $value );
    			}
     		}
    	}
    	// Optional removed checkbox for now.. Might use later
    	/*if ($post_activity == false)
    		return false;
    	*/
    	// Taken from /public_html/wp-content/plugins/buddypress/bp-groups/bp-groups-activity.php
    	// We removed the email notification check so that it will post an activity stream regardless.
    	// Bail if Activity is not active.
    	if ( ! bp_is_active( 'activity' ) )
    		return false;
    
    	if ( ! isset( $old_group->name ) || ! isset( $old_group->description ) )
    		return false;
    
    	// If the admin has opted not to notify members, don't post an activity item either
    	// Removed, I want updated posted if it sends and email or not.
    	/*if ( empty( $notify_members ) ) {
    		return;
    	}*/
    
    	$group = groups_get_group( array(
    		'group_id' => $group_id,
    	) );
    
    	/*
    	 * Store the changed data, which will be used to generate the activity
    	 * action. Since we haven't yet created the activity item, we store the
    	 * old group data in groupmeta, keyed by the timestamp that we'll put
    	 * on the activity item.
    	 */
    	
    	if ( $group->name !== $old_group->name || $group->description !== $old_group->description )
    		$changed = 'changed';
    
    	// If there are no changes, don't post an activity item.
    	if ( empty( $changed ) )
    		return;
    
    	$time = bp_core_current_time();
    	// Don't want a long description of what has been changed inside the details. Also reduces information posted in groupmeta table.
    	//groups_update_groupmeta( $group_id, 'updated_details_' . $time, $changed );
    	
    	// And finally, update groups last activity.. Currently doesn't in standard.
    	groups_update_groupmeta( $group_id, 'last_activity', $time );
    	
    	// Since we have removed the information from meta, we will record it directly into action on activity..
    	// You do not need the same information recorded twice in the database. This needs optimizing. Hence removing update groupmeta..
    	/*
    	$user_link = bp_core_get_userlink( bp_loggedin_user_id() );
    	$group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>';
    	$action = sprintf( __( '%1$s changed the description of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), $user_link, $group_link, esc_html( $changed['description']['old'] ), esc_html( $changed['description']['new'] ) );
    	*/
    	// Record in activity streams.
    	return groups_record_activity( array(
    		'type'          => 'group_details_updated',
    		'item_id'       => $group_id,
    		'user_id'       => bp_loggedin_user_id(),
    		'recorded_time' => $time,
    	) );
    }

    If there is bugs in any code, I will find them and fix them.. That’s one of the downsides to being a perfectionist..

    I have not fixed the

    A few bugs I have found.

    From the first post yet, but will be doing after I have had my dinner 🙂
    My idea is to have a notification saying that the user has left the group when they leave/kicked/banned/ obviously if its after the 5 minutes mark lol.

    #235946
    howsepa
    Participant

    Sorry should have included full function…

    
    //Catch messages on successful login
        function login_action($user_login)
        {
    
            $userdata = get_user_by('login', $user_login);
    
            $uid = ($userdata && $userdata->ID) ? $userdata->ID : 0;
    
            $data[$this->data_labels['login']] = ( 1 == $this->login_success ) ? $this->data_labels['Successful'] : $this->data_labels['Failed'];
            if ( isset( $_REQUEST['redirect_to'] ) ) { $data[$this->data_labels['login Redirect']] = esc_attr( $_REQUEST['redirect_to'] ); }
            $data[$this->data_labels['User Agent']] = esc_attr( $_SERVER['HTTP_USER_AGENT'] );
    
            $serialized_data = serialize($data);
    
            //get user role
            $user_role = '';
            if( $uid ){
                $user = new WP_User( $uid );
                if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
                    $user_role = implode(', ', $user->roles);
                }
            }
    		$current_user = wp_get_current_user();
    		$user_email = $user->user_email;
    	
    
    		$real_client_ip_address = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? esc_attr($_SERVER['HTTP_X_FORWARDED_FOR']) : esc_attr($_SERVER['REMOTE_ADDR']);
    		
    
    		$guest_ip   = $visitor_location['IP'];
    		$guest_country = "";
    		$guest_city  = "";
    		$guest_state = "";
    		$user_info = get_userdata($uid);
            $USErname =  $user_info->first_name .  " " . $user_info->last_name;
            
    		
    
    			
    		global $bp;
    		
    		$group =  get_group_ids( bp_loggedin_user_id() );
            
    		$values = array(
                'uid'           => $uid,
                'user_login'    => $user_login,
                'user_role'     => $user_role,
    			'user_email'		=> $user_email,
                'time'          => current_time('mysql'),
                'ip'            => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? esc_attr($_SERVER['HTTP_X_FORWARDED_FOR']) : esc_attr($_SERVER['REMOTE_ADDR']),
    			'country'       => $guest_country,
    			'city'			=> $guest_city,
                'login_result'  => $this->login_success,
                'data'          => $serialized_data,
    			'name'			=> $USErname,
    			'group'			=> $group
                );
    
            $format = array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s');
    
            $this->save_data($values, $format);
        }
    
    #235944
    shanebp
    Moderator

    You don’t say which hook your class uses.

    Have you tried using get_group_ids( bp_loggedin_user_id() ) ?
    See the function in bp-groups\bp-groups-classes.php and note the structure of the returned array.

    If you’re hooking before BP is ready, you could always run some custom sql.
    Use SELECT COUNT via get_var.

    #235936
    martni
    Participant

    Ok it’s working fine like that for me.

    <?php $test=get_post_meta($post->ID, ‘test_bp_group_id’, true); ?>

    <?php if ( bp_has_activities( “&primary_id=$test” ) ): ?>

    #235886
    martni
    Participant

    Thanks @rosyteddy. Second link fit perfectly !
    Activity stream of the particluar group appears well with this:
    <?php if ( bp_has_activities( ‘&primary_id=2’ ) ): ?>

    Now I would like to automate this.
    I get primary_id on my page when I write this
    <?php echo get_post_meta($post->ID, ‘test_bp_group_id’, true); ?>
    But the following doesn’t work
    <?php if ( bp_has_activities( ‘&primary_id=get_post_meta($post->ID, ‘test_bp_group_id’, true);’ ) ): ?>
    Any idea?

    #233850
    modemlooper
    Moderator

    did these plugins not work?
    https://wordpress.org/plugins/buddypress-groupomatic/
    https://wordpress.org/plugins/buddypress-auto-group-join/

    or function

    function automatic_group_membership( $user_id ) {
       if( !$user_id ) return false;
     
       groups_accept_invite( $user_id, $group_id );
    }
    add_action( 'bp_core_activated_user', 'automatic_group_membership' );
    #233089
    Henry Wright
    Moderator

    Hi @nickguidomedia

    My first thought was to get the member count of the relevant group during each user registration.

    That can be done with groups_get_total_member_count( $group_id );.

    You’d need to check this figure is less or equal to 150 and if it isn’t, you’d need to add the user to an over-spill group, creating a new one if necessary.

    As you mentioned users are added to a group automatically during registration.

    The bp_core_signup_user hook fires at the end of the registration process so could hook all your code for the above to that. That hook gives you access to $user_id, $user_login, $user_password, $user_email and $usermeta, so you should be able to get all the info you need from those. For example:

    function my_func( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
        // Write your code here.
    }
    add_action( 'bp_core_signup_user', 'my_func', 10, 5 );

    Hope this helps.

Viewing 25 results - 201 through 225 (of 567 total)
Skip to toolbar