BBP_BuddyPress_Activity::reply_create( $reply_id, int $topic_id, int $forum_id, array $anonymous_data = array(), $reply_author_id )
Record an activity stream entry when a reply is created
Description
Parameters
- $topic_id
-
(Required)
- $forum_id
-
(Required)
- $anonymous_data
-
(Optional)
Default value: array()
- $topic_author_id
-
(Required)
Return
(Bail) early if topic is by anonywous user
Source
File: bp-forums/activity.php
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | public function reply_create( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array (), $reply_author_id = 0 ) { // Do not log activity of anonymous users if ( ! empty ( $anonymous_data ) ) return ; // Validate activity data $user_id = (int) $reply_author_id ; $reply_id = bbp_get_reply_id( $reply_id ); $topic_id = bbp_get_topic_id( $topic_id ); $forum_id = bbp_get_forum_id( $forum_id ); // Bail if user is not active if ( bbp_is_user_inactive( $user_id ) ) return ; // Bail if reply is not published if ( !bbp_is_reply_published( $reply_id ) ) return ; // Setup links for activity stream $user_link = bbp_get_user_profile_link( $user_id ); // Reply $reply_url = bbp_get_reply_url( $reply_id ); $reply_content = get_post_field( 'post_content' , $reply_id , 'raw' ); // Topic $topic_permalink = bbp_get_topic_permalink( $topic_id ); $topic_title = get_post_field( 'post_title' , $topic_id , 'raw' ); $topic_link = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>' ; // Forum $forum_permalink = bbp_get_forum_permalink( $forum_id ); $forum_title = get_post_field( 'post_title' , $forum_id , 'raw' ); $forum_link = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>' ; // Activity action & text $activity_text = sprintf( esc_html__( '%1$s replied to the discussion %2$s in the forum %3$s' , 'buddyboss' ), $user_link , $topic_link , $forum_link ); $activity_action = apply_filters( 'bbp_activity_reply_create' , $activity_text , $user_id , $reply_id , $topic_id ); $activity_content = apply_filters( 'bbp_activity_reply_create_excerpt' , $reply_content ); // Compile and record the activity stream results $activity_id = $this ->record_activity( array ( 'id' => $this ->get_activity_id( $reply_id ), 'user_id' => $user_id , 'action' => $activity_action , 'content' => $activity_content , 'primary_link' => $reply_url , 'type' => $this ->reply_create, 'item_id' => $reply_id , 'secondary_item_id' => $topic_id , 'recorded_time' => get_post_time( 'Y-m-d H:i:s' , true, $reply_id ), 'hide_sitewide' => ! bbp_is_forum_public( $forum_id , false ) ) ); // Add the activity entry ID as a meta value to the reply if ( ! empty ( $activity_id ) ) { update_post_meta( $reply_id , '_bbp_activity_id' , $activity_id ); } } |
Changelog
Version | Description |
---|---|
bbPress (r3395) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.