-
-
Save ryanhellyer/c31bf993d55e1d7450a8 to your computer and use it in GitHub Desktop.
BuddyPress add acitivity to groups - bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class RR_BuddyPress { | |
public function __construct() { | |
add_post_type_support( 'events', 'buddypress-activity' ); | |
add_action( 'bp_activity_before_save', array( $this, 'add_activity' ) ); | |
} | |
/** | |
* Add activity. | |
* | |
* @param object $activity | |
*/ | |
public function add_activity( $activity ) { | |
// Bail out if not saving an event | |
if ( 'new_events' != $activity->type ) { | |
return; | |
} | |
$post_id = $activity->secondary_item_id; | |
$current_user = wp_get_current_user(); | |
$post = get_post( $post_id ); | |
$excerpt = $post->post_excerpt; | |
if ( '' == $excerpt ) { | |
$excerpt = $post->post_content; | |
} | |
// Save the activity | |
$args = array( | |
// 'id' => '', | |
'action' => '<a href="' . esc_url( get_author_posts_url( $current_user->ID, $current_user->user_nicename ) ) . '">' . $current_user->display_name . '</a>' . __( ' did something', 'XXX' ), | |
'content' => $excerpt, | |
'component' => 'groups', | |
'type' => 'activity_update', | |
'item_id' => 2, // The group ID | |
'secondary_item_id' => $post_id, // Post ID | |
); | |
bp_activity_add( $args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't seem to need the bp_activity_set_post_type_tracking_args() when using it with a custom post-type, so I've been able to remove that too.