Search Results for 'group_id'
-
AuthorSearch Results
-
August 24, 2015 at 3:43 pm #243538
In reply to: Add New User Activity on Button Click
coffeywebdev
ParticipantTake a look at this code, I think it may be helpful for you…
I created a function vp_add_group_activity_comments() that hooks to the ‘post_comment’ action, so when a user posts a comment an activity stream item is created and added to their group’s feed.. (on my site users can only be in one group at a time)
It’s all about what you set for the $args array….
function vp_add_group_activity_comments($comment_id){ $comment = get_comment( $comment_id ); GLOBAL $wpdb; $user_id = get_current_user_id(); $user_info = get_userdata( $user_id ); $current_user_group_id = $wpdb->get_var("SELECT group_id FROM ".$wpdb->prefix."bp_groups_members WHERE user_id = '".(int)$user_id."'"); $comment_action = "<a href='".site_url()."/members/".$user_info->user_login."'>".$user_info->first_name." ".$user_info->last_name."</a> posted a comment on <a href='".get_permalink($comment->comment_post_ID )."'>".get_the_title($comment->comment_post_ID)."</a>"; // arguments to pass to the bp_activity_add() function $args = array( 'action' => $comment_action, // The activity action - e.g. "Jon Doe posted an update" 'content' => $comment->comment_content, // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 'component' => 'groups', // The name/ID of the component e.g. groups, profile, mycomponent 'type' => 'activity_update', // The activity type e.g. activity_update, profile_updated 'primary_link' => get_permalink($comment->comment_post_ID ), // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 'user_id' => $user_id, // Optional: The user to record the activity for, can be false if this activity is not for a user. 'item_id' => $current_user_group_id, // Optional: The ID of the specific item being recorded, e.g. a blog_id 'secondary_item_id' => $comment->comment_ID, // Optional: A second ID used to further filter e.g. a comment_id 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded 'hide_sitewide' => 0, // Should this be hidden on the sitewide activity stream? 'is_spam' => 0, // Is this activity item to be marked as spam? ); $add_activity = bp_activity_add($args); // Update the group's last activity groups_update_last_activity( $current_user_group_id ); return true; } add_action('comment_post', 'vp_add_group_activity_comments' );August 24, 2015 at 3:38 pm #243537In reply to: Post comments not appearing in activity stream?
coffeywebdev
ParticipantTake a look at the code below to see how I use the post_comment action to hook my function vp_add_group_activity_comments(), which creates an activity stream item when a user posts a comment and adds it to their group’s activity stream… This is just what we are doing for our site, but if you look at the code you should be able to figure out how to do it for your site….
function vp_add_group_activity_comments($comment_id){ $comment = get_comment( $comment_id ); GLOBAL $wpdb; $user_id = get_current_user_id(); $user_info = get_userdata( $user_id ); $current_user_group_id = $wpdb->get_var("SELECT group_id FROM ".$wpdb->prefix."bp_groups_members WHERE user_id = '".(int)$user_id."'"); $comment_action = "<a href='".site_url()."/members/".$user_info->user_login."'>".$user_info->first_name." ".$user_info->last_name."</a> posted a comment on <a href='".get_permalink($comment->comment_post_ID )."'>".get_the_title($comment->comment_post_ID)."</a>"; // arguments to pass to the bp_activity_add() function $args = array( 'action' => $comment_action, // The activity action - e.g. "Jon Doe posted an update" 'content' => $comment->comment_content, // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 'component' => 'groups', // The name/ID of the component e.g. groups, profile, mycomponent 'type' => 'activity_update', // The activity type e.g. activity_update, profile_updated 'primary_link' => get_permalink($comment->comment_post_ID ), // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 'user_id' => $user_id, // Optional: The user to record the activity for, can be false if this activity is not for a user. 'item_id' => $current_user_group_id, // Optional: The ID of the specific item being recorded, e.g. a blog_id 'secondary_item_id' => $comment->comment_ID, // Optional: A second ID used to further filter e.g. a comment_id 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded 'hide_sitewide' => 0, // Should this be hidden on the sitewide activity stream? 'is_spam' => 0, // Is this activity item to be marked as spam? ); $add_activity = bp_activity_add($args); // Update the group's last activity groups_update_last_activity( $current_user_group_id ); return true; } add_action('comment_post', 'vp_add_group_activity_comments' );August 11, 2015 at 2:48 am #242993In reply to: [Resolved] please help me change css in php
Quinn Goldwin
Participantps I’ve tried all of these calls and still nothing
if ( BP_Groups_Member::get_is_admin_of( $user_id )) {
if ( ! groups_is_user_admin( $user_id, $group_id ) ) {
if ( groups_is_user_admin( $user_id, $group_id ) ) {
if ( groups_is_user_admin( get_current_user_id(), $group_id ) ) {
August 6, 2015 at 1:42 pm #242840shanebp
ModeratorTry this:
$args = array( 'group_id' => bp_get_group_id(), 'exclude_admins_mods' => false, ); $members = groups_get_group_members( $args ); foreach( $members['members'] as $member ) { echo $member->display_name . '<br/>'; } // for reference, show all the data echo '<pre>'; var_dump( $members ); echo '</pre>';August 6, 2015 at 7:08 am #242830cityfox
ParticipantThanks for the reply. I’m a newbie. I don’t understand what you mean. I put the code with php tags in the groups-loop-file but it doesn’t work correctly. The website shows this:
array(2) { ["members"]=> array(0) { } ["count"]=> string(1) "0" }In the meantime I got another idea: I put the Group Members Loop in the text editor of a wordpress page. I thought if that works I can put the code into a shortcode (with plugin My Shortcodes) and make shortcodes for each group. But the loop doesn’t get the group members. On the website there is the message “This group has no members”. Then I put the group ID into the loop like that:
bp_group_has_members('group_id=1')But still it doesn’t work. I’m lost…
August 2, 2015 at 11:10 pm #242696pandreas
ParticipantYes, but how I will use wp_update_term function?
I have written this:
function example_update_category( $group_id ) {
$group = groups_get_group( array( ‘group_id’ => $group_id ) );
$name = $group->name;
$groupid = $group->id;wp_update_term(
189, //for a specific category item
‘category’,
array(
‘name’ => $name
)
);
}
add_action( ‘groups_details_updated ‘, ‘example_update_category’, 1, 1 );But it doesn’t seem to work. What is wrong? Hook maybe?
Thank you in advance!
Andreas
July 30, 2015 at 2:53 pm #242574In reply to: Conditional PHP for Groups
Henry Wright
Moderatorif ( $group_id == '1' ) { // Do this } else { // Do this }Note: You’ll need to get
$group_idearlier on in your code.July 24, 2015 at 12:08 am #242191In reply to: BP_Group_Member_Query type alphabetical
Garrett Hyder
ParticipantHi @shanebp,
Sorry for the confusion, I’ve created a bp_group_list_managers that’s a merge of bp_group_list_admins and bp_group_list_mods to provide a single consolidated listing.
function bp_group_list_managers($group=false) { global $groups_template; if(empty($group)) { $group =& $groups_template->group; } // fetch group admins if 'populate_extras' flag is false if (empty($group->args['populate_extras']) || true) { $query = new BP_Group_Member_Query(array( 'group_id' => $group->id, 'group_role' => 'admin', 'type' => 'alphabetical', )); if (!empty($query->results)) { $group->admins = $query->results; } } // fetch group mods if 'populate_extras' flag is false if (empty($group->args['populate_extras']) || true) { $query = new BP_Group_Member_Query(array( 'group_id' => $group->id, 'group_role' => 'mod', 'type' => 'alphabetical', )); if (!empty($query->results)) { $group->mods = $query->results; } } $admins = (array)$group->admins; $mods = (array)$group->mods; usort($admins, 'bp_group_member_sort'); usort($mods, 'bp_group_member_sort'); $group->managers = array_merge($admins, $mods); if (!empty($group->managers)) { ?> <ul id="group-managers"> <?php foreach((array)$group->managers as $manager) { ?> <li> <a href="<?php echo bp_core_get_user_domain($manager->user_id, $manager->user_nicename, $manager->user_login); ?>"><?php echo bp_core_fetch_avatar(array('item_id' => $manager->user_id, 'email' => $manager->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname($manager->user_id)))) ?></a> </li> <?php } ?> </ul> <?php } else { ?> <span class="activity"><?php _e( 'No Managers', 'buddypress' ) ?></span> <?php } }As you can see I set the type here to alphabetical and was first confused why it did nothing then I realized the BP_Group_Member_Query’s were never even called as I guess populate_extras was set so not empty. This meant that the $group->admins and $group->mods came from the global $group_template->group which wasn’t ordered. I’m curious how to make that global $group_template->group admin/mod lists could be alphabetically ordered by default.
For now I just amended my method to simply force the BP_Group_Member_Query’s to be used instead which has allowed for the alphabetical ordering.
Hope that clears things up.
Thanks
July 21, 2015 at 4:33 pm #242088In reply to: Hide the whole Base profile field group
shanebp
ModeratorTry this…
Make a template overload of this file:
bp-templates\bp-legacy\buddypress\members\single\profile\profile-loop.phpIn that new file, change this:
<?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?>to this, assuming the id of your base group is 1
<?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?> <?php if( bp_get_the_profile_group_id() != 1 ) : ?>And add an
<?php endif; ?>before the<?php endwhile; ?>near the bottom of the page.Do the same for:
bp-templates\bp-legacy\buddypress\members\single\profile\edit.phpJuly 14, 2015 at 1:16 pm #241839shanebp
ModeratorTry:
function example_insert_category( $group_id ) { $group = groups_get_group( array( 'group_id' => $group_id ) ); $name = $group->name; $slug = $group->slug; wp_insert_term( $name, 'category', array( 'description' => 'This is an example category.', 'slug' => $slug ) ); } add_action('groups_group_create_complete', 'example_insert_category', 1, 1);July 11, 2015 at 7:31 pm #241742In reply to: Delete profile fields
shanebp
ModeratorYou can get the ids by going to
.../wp-admin/users.php?page=bp-profile-setup
Click or roll-over the Edit links for group or single field.
And you’ll see group_id & field_id.
btw – you can delete groups and / or single fields on that wp-admin page.July 3, 2015 at 8:23 am #241410In reply to: Display all BuddyPress group id as a dropdown
Prabin
ParticipantI did it .. thanx for reply anyway 😀
<div> <?php global $bp,$wpdb; $group_id = get_post_meta( $post->ID, 'campaign_group_id', true ); $group_results = $wpdb->get_results("SELECT id,name FROM {$wpdb->prefix}bp_groups ORDER BY ID ASC"); ?> <label for="meta-box-dropdown">ADD/EDIT</label> <select name="meta-box-dropdown"> <?php foreach($group_results as $group_result): ?> <option <?php echo ($group_id==$group_result->id)?"selected=selected":"" ?> value="<?php echo $group_result->id ?>"><?php echo $group_result->name ?></option> <?php endforeach; ?> </select> <br> </div>June 28, 2015 at 12:31 pm #241208In reply to: Edit profile groups on single page
Graeme Fulton
ParticipantAt the top of edit.php (yourtheme/buddypress/members/single/profile/edit.php), find this bit near the top:
if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) : while ( bp_profile_groups() ) : bp_the_profile_group();The important part in the snippet above is this function call:
bp_get_current_profile_group_id(). That grabs the current group ID from the URL, and sets it for the rest of the page. We want to change that bit.Just above the first code snippet I wrote, paste this query to collect all the profile groups into one variable:
$sqlStr = "SELECT *idFROMwp_bp_xprofile_groups`”;
$groups = $wpdb->get_results($sqlStr);`Now you can replace
bp_get_current_profile_group_id()with this:$groups[0]That will leave you with this:
if ( bp_has_profile( 'profile_group_id=' . $groups[0] ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>Now if you visit any of your edit profile group links, you’ll see all the groups on a single page.
Next, you will probably want to remove the pagination from the page, as it will get included multiple times (since we’re in a while loop), and it is also unnecessary now that we’re showing all groups on one page.
Remove this bit:
<ul class="button-nav"> <?php bp_profile_group_tabs(); ?> </ul>Hope that works for you.
June 27, 2015 at 10:59 pm #241192In reply to: BubbyPress + BBPress, ERROR
webappdesigner
Participantanswered my own question….
For anyone that has the same problem, bbpress -> includes -> extend -> buddypress -> groups.php
on line 151 change
public function display() {
to
public function display($group_id = NULL) {June 27, 2015 at 8:58 pm #241189In reply to: BubbyPress + BBPress, ERROR
shanebp
ModeratorThis is an issue for bbPress support.
Or you could try changing the display function in
class BBP_Forums_Group_Extensionfrom:
public function display() {
to
public function display($group_id = NULL) {June 24, 2015 at 12:40 pm #241044In reply to: Auto join group based on role
shanebp
ModeratorIf the role is set to vendor and xprofile fields are not involved, then there is a WP hook for that.
Assuming the group_id is 8, try:
function jeffery_join_vendor_group( $user_id, $role, $old_roles ) { if( $role == 'vendor' ) { groups_accept_invite( $user_id, 8 ); } } add_action( 'set_user_role', 'jeffery_join_vendor_group', 11, 3 );June 24, 2015 at 8:40 am #241036In reply to: Auto join group based on role
danbp
ParticipantHi @dcsenterprise,
in brief, the snippet tells
'user_registerto add a new user automatically to a group after the register process.If this is the scenario you want to use, you have to ensure that the Vendor role is in a xprofile field or at least, that this role is somewhere on the user profile, added by the WC plugin.
Assuming that it’s the case, you can use this:
function automatic_group_membership( $user_id ) { if( !$user_id ) return false; $join_group = xprofile_get_field_data('WCRole', $user_id); // field name (case sensitive) containing the role // conditionnal if ($join_group == 'vendor') // role name $group_id = '8'; // the id of the Vendor group to auto-join // action groups_accept_invite( $user_id, $group_id ); } add_action( 'bp_core_activated_user', 'automatic_group_membership' );How it works ?
– a field or select field on register page, with evtl. options
field name = WCRole
option0 = vendor
option1 = manager
option3 = director
etc…If several options for different groups, you simply add it as conditionnal to the function:
if... $group_id =Hope to be clear !
June 19, 2015 at 3:10 pm #240891In reply to: Admin notification
shanebp
ModeratorNot sure what you mean by approval…
Use this hook, from buddypress\bp-groups\bp-groups-actions.php :
do_action( 'groups_group_create_complete', $bp->groups->new_group_id );And write a function that sends an email.
June 19, 2015 at 2:23 pm #240887In reply to: How to show pending memberships to user
shanebp
Moderatorafaik, there is no BP function for that.
You could gather all the group ids like so:function get_all_group_membership_requests( $user_id ) { global $wpdb; $bp = buddypress(); return $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 0 AND inviter_id = 0", $user_id ) ); }Use:
$pending_group_ids = get_all_group_membership_requests( bp_loggedin_user_id() );June 16, 2015 at 1:16 pm #240768In reply to: [Resolved] Groups function is broken
pihla
ParticipantYes, this is exactly the case, it does not create the second group, because the id is 0 so the auto-increment is not working (and the first one created a row in the database, but does not show in the front end)
Yes, there is nothing wrong with the id 0 with the forum, I was just wondering why does it give duplicate entry warning with this:
WordPress database error: [Duplicate entry ‘0’ for key ‘PRIMARY’]
INSERT INTO wp_bp_groups ( creator_id, name, slug, description, status, enable_forum, date_created ) VALUES ( 22, ‘Vanhat talot’, ‘vanhat-talot’, ‘Vanhat talot’, ‘public’, 0, ‘2015-06-16 08:25:16′ )and the only 0 in this insert is the enable_forum which should not be primary, but well this might just refer to the group_id field that is not auto incremented.
I even updated the themes Buddy Press and bbPress files (Kleo-theme) and updated again Buddy Press, even though it was in version 2.3.1, did not help…
@shanebp where did you find the information about the non-BP reports where WP 4.2.2 $wpdb->insert_id returns 0? I could try to find the info from there.June 14, 2015 at 4:56 pm #240705maelga
ParticipantThanks @shanebp.
It only works if I remove the function triggered at bp_loaded, as follows:if ( class_exists( 'BP_Group_Extension' ) ) : class members_nav_tab_in_group extends BP_Group_Extension { function __construct() { if( bp_is_group_single() ) { $bp = buddypress(); $group_id = $bp->groups->current_group->id; if( $group_id == '1' ) { $args = array( 'slug' => '../../members', 'name' => 'Members Directory', 'nav_item_position' => 105, ); parent::init( $args ); } } } } bp_register_group_extension( 'members_nav_tab_in_group' ); endif;What is the rationale/advantage for adding this function add_group_tab()?
June 14, 2015 at 2:02 pm #240700shanebp
ModeratorMay not be the best way, but try:
function add_group_tab() { if ( class_exists( 'BP_Group_Extension' ) ) : class members_nav_tab_in_group extends BP_Group_Extension { function __construct() { if( bp_is_group_single() ) { $bp = buddypress(); $group_id = $bp->groups->current_group->id; if( $group_id == 1 ) { $args = array( 'slug' => '../../members', 'name' => 'Members Directory', 'nav_item_position' => 105, ); parent::init( $args ); } } } } bp_register_group_extension( 'members_nav_tab_in_group' ); endif; } add_action( 'bp_loaded', 'add_group_tab' );June 14, 2015 at 12:31 am #240691laloptk
ParticipantOk, I solved the problem, turns out I was using wrong the $bp->loggedin_user->id because only returns a value when the user is loggedin, and I wanted to add members to groups when they activate their account, so, the return in that case (members activating their account are not logged in) is 0.
The same applys to the function: get_member_nfl_team(), it tries to get the ID of the logged in user.
I made some modifications to the code and worked perfectly:
function add_members_to_nfl_group($user_id){ // I suppose when you add the parameter $user_id in the fuction and then pass it trough the action 'bp_core_activated_user', the action returns the ID of the memeber beeing activated. $nfl_team = bp_get_profile_field_data('field=2&user_id='.$user_id); // I erased the function get_member_nfl_team() and put the variable here with the new $user_id $nfl_team_slug = str_replace(" ", "-", strtolower($nfl_team)); $group_slug = "aficionados-a-los-".$nfl_team_slug; $group_id = BP_Groups_Group::group_exists($group_slug); groups_join_group( $group_id, $user_id ); // Instead of groups_accept_invite() as @henrywright suggested } add_action( 'bp_core_activated_user', 'add_members_to_nfl_group' );And thats all.
June 13, 2015 at 8:22 am #240660Henry Wright
ModeratorInstead of
groups_accept_invite(), try usinggroups_join_group().So in your code above, you’d use:
groups_join_group( $group_id, $bp_user_id )June 12, 2015 at 8:15 am #240622In reply to: [Resolved] Groups function is broken
pihla
ParticipantHi,
I get the following error:
Strict Standards: Declaration of BBP_Forums_Group_Extension::display() should be compatible with BP_Group_Extension::display($group_id = NULL) in /home/c5dh5rak/public_html/wp-content/plugins/bbpress/includes/extend/buddypress/groups.php on line 28I’m using BuddyPress 2.3.1 and WP 4.2.2 Finnish.
The site is Homesome.com
Thanks for support =)
-Pihla
-
AuthorSearch Results