Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: group details updated is not posting in activity stream. Or comments on blog

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

Skip to toolbar