| 714 | |
| 715 | /** BuddyPress Activity Action Callbacks **************************************/ |
| 716 | |
| 717 | /** |
| 718 | * Genereic function to format the dynamic BuddyPress activity action for new |
| 719 | * topics/replies. |
| 720 | * |
| 721 | * @since 2.6.0 bbPress (rXXXX) |
| 722 | * |
| 723 | * @param null|string $type The type of post. Currently `topic` or `reply`. |
| 724 | * @param string $action The current action string. |
| 725 | * @param object $activity The BuddyPress activity object. |
| 726 | * |
| 727 | * @return string The formatted activity action. |
| 728 | */ |
| 729 | function bbp_bp_format_activity_action_new_post( $type = null, $action, $activity ) { |
| 730 | |
| 731 | // Bail early if we don't have a valid type. |
| 732 | if ( ! in_array( $type, array( 'topic', 'reply' ) ) ) { |
| 733 | return $action; |
| 734 | } |
| 735 | |
| 736 | // Check if we're on the groups or bbpress component. |
| 737 | if ( 'groups' === $activity->component ) { |
| 738 | if ( 'topic' === $type ) { |
| 739 | $topic_id = bbp_get_topic_id( $activity->secondary_item_id ); |
| 740 | $forum_id = bbp_get_topic_forum_id( $topic_id ); |
| 741 | } else { |
| 742 | $topic_id = bbp_get_reply_topic_id( $activity->secondary_item_id ); |
| 743 | $forum_id = bbp_get_topic_forum_id( $topic_id ); |
| 744 | } |
| 745 | } else { |
| 746 | if ( 'topic' === $type ) { |
| 747 | $topic_id = bbp_get_topic_id( $activity->item_id ); |
| 748 | $forum_id = bbp_get_forum_id( $activity->secondary_item_id ); |
| 749 | } else { |
| 750 | $topic_id = bbp_get_topic_id( $activity->secondary_item_id ); |
| 751 | $forum_id = bbp_get_topic_forum_id( $topic_id ); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | // Setup our post type args. |
| 756 | $actions = array( |
| 757 | 'topic' => __( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), |
| 758 | 'reply' => __( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), |
| 759 | ); |
| 760 | |
| 761 | // User link for topic author. |
| 762 | $user_link = bbp_get_user_profile_link( $activity->user_id ); |
| 763 | |
| 764 | // Topic link. |
| 765 | $topic_permalink = bbp_get_topic_permalink( $topic_id ); |
| 766 | $topic_title = get_post_field( 'post_title', $topic_id, 'raw' ); |
| 767 | $topic_link = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>'; |
| 768 | |
| 769 | // Forum link. |
| 770 | $forum_permalink = bbp_get_forum_permalink( $forum_id ); |
| 771 | $forum_title = get_post_field( 'post_title', $forum_id, 'raw' ); |
| 772 | $forum_link = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>'; |
| 773 | |
| 774 | return sprintf( $actions[ $type ], $user_link, $topic_link, $forum_link ); |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Formats the dynamic BuddyPress activity action for new topics. |
| 779 | * |
| 780 | * @since 2.6.0 bbPress (rXXXX) |
| 781 | * |
| 782 | * @param string $action The current action string. |
| 783 | * @param object $activity The BuddyPress activity object. |
| 784 | * |
| 785 | * @return string The formatted activity action. |
| 786 | */ |
| 787 | function bbp_bp_format_activity_action_new_topic( $action, $activity ) { |
| 788 | |
| 789 | $action = bbp_bp_format_activity_action_new_post( 'topic', $action, $activity ); |
| 790 | |
| 791 | /** |
| 792 | * Filters the formatted activity action new topic string. |
| 793 | * |
| 794 | * @since 2.6.0 bbPress (rXXXX) |
| 795 | * |
| 796 | * @param string $action Activity action string value. |
| 797 | * @param BP_Activity_Activity $activity Activity item object. |
| 798 | */ |
| 799 | return apply_filters( 'bbp_bp_format_activity_action_new_topic', $action, $activity ); |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Formats the dynamic BuddyPress activity action for new replies. |
| 804 | * |
| 805 | * @since 2.6.0 bbPress (rXXXX) |
| 806 | * |
| 807 | * @param string $action The current action string. |
| 808 | * @param object $activity The BuddyPress activity object. |
| 809 | * |
| 810 | * @return string The formatted activity action. |
| 811 | */ |
| 812 | function bbp_bp_format_activity_action_new_reply( $action, $activity ) { |
| 813 | |
| 814 | $action = bbp_bp_format_activity_action_new_post( 'reply', $action, $activity ); |
| 815 | |
| 816 | /** |
| 817 | * Filters the formatted activity action new reply string. |
| 818 | * |
| 819 | * @since 2.6.0 bbPress (rXXXX) |
| 820 | * |
| 821 | * @param string $action Activity action string value. |
| 822 | * @param BP_Activity_Activity $activity Activity item object. |
| 823 | */ |
| 824 | return apply_filters( 'bbp_bp_format_activity_action_new_reply', $action, $activity ); |
| 825 | } |