Skip to content

Instantly share code, notes, and snippets.

@sbrajesh
Created September 9, 2019 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbrajesh/da7add582f168cfe016dd85454f864f2 to your computer and use it in GitHub Desktop.
Save sbrajesh/da7add582f168cfe016dd85454f864f2 to your computer and use it in GitHub Desktop.
/**
* Attach media with comments on a mediapress activity.
*
* @param int $comment_id comment id.
* @param array $r args.
* @param BP_Activity_Activity $activity activity object.
*/
function mpp_custom_comment_posted( $comment_id, $r, $activity ) {
$comment = new BP_Activity_Activity( $comment_id );
$parent_id = $comment->item_id;
$parent = new BP_Activity_Activity( $parent_id );
if ( 'mpp_media_upload' !== $parent->type ) {
return;
}
$attached_ids = mpp_activity_get_attached_media_ids( $comment->item_id );
if ( ! $attached_ids || count( $attached_ids ) > 1 ) {
return;
}
$media_id = current( $attached_ids );
mpp_activity_update_media_id( $comment_id, $media_id );
}
add_action( 'bp_activity_comment_posted', 'mpp_custom_comment_posted', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment