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