Changeset 6370
- Timestamp:
- 03/07/2017 09:54:24 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/extend/buddypress/functions.php
r6320 r6370 745 745 return (bool) $bbp->current_user->is_group_creator; 746 746 } 747 748 /* BuddyPress Activity Action Callbacks ***************************************/ 749 750 /** 751 * Return an array of allowed activity actions 752 * 753 * @since 2.6.0 bbPress (r6370) 754 * 755 * @return array 756 */ 757 function bbp_get_activity_actions() { 758 return apply_filters( 'bbp_get_activity_actions', array( 759 'topic' => __( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), 760 'reply' => __( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ) 761 ) ); 762 } 763 764 /** 765 * Generic function to format the dynamic BuddyPress activity action for new 766 * topics/replies. 767 * 768 * @since 2.6.0 bbPress (r6370) 769 * 770 * @param string $type The type of post. Expects `topic` or `reply`. 771 * @param string $action The current action string. 772 * @param BP_Activity_Activity $activity The BuddyPress activity object. 773 * 774 * @return string The formatted activity action. 775 */ 776 function bbp_format_activity_action_new_post( $type = '', $action = '', $activity = false ) { 777 778 // Get actions 779 $actions = bbp_get_activity_actions(); 780 781 // Bail early if we don't have a valid type 782 if ( ! in_array( $type, array_keys( $actions ), true ) ) { 783 return $action; 784 } 785 786 /** 787 * Overrides the formatted activity action new activity string. 788 * 789 * @since 2.6.0 bbPress (r6370) 790 * 791 * @param string $activity_action Activity action string value 792 * @param string $type The type of post. Expects `topic` or `reply`. 793 * @param string $action The current action string. 794 * @param BP_Activity_Activity $activity The BuddyPress activity object. 795 */ 796 if ( $pre = apply_filters( 'bbp_pre_format_activity_action_new_post', false, $type, $action, $activity ) ) { 797 return $pre; 798 } 799 800 // Groups component 801 if ( 'groups' === $activity->component ) { 802 if ( 'topic' === $type ) { 803 $topic_id = bbp_get_topic_id( $activity->secondary_item_id ); 804 $forum_id = bbp_get_topic_forum_id( $topic_id ); 805 } else { 806 $topic_id = bbp_get_reply_topic_id( $activity->secondary_item_id ); 807 $forum_id = bbp_get_topic_forum_id( $topic_id ); 808 } 809 810 // General component (bbpress/forums/other) 811 } else { 812 if ( 'topic' === $type ) { 813 $topic_id = bbp_get_topic_id( $activity->item_id ); 814 $forum_id = bbp_get_forum_id( $activity->secondary_item_id ); 815 } else { 816 $topic_id = bbp_get_topic_id( $activity->secondary_item_id ); 817 $forum_id = bbp_get_topic_forum_id( $topic_id ); 818 } 819 } 820 821 // User link for topic author 822 $user_link = bbp_get_user_profile_link( $activity->user_id ); 823 824 // Topic link 825 $topic_permalink = bbp_get_topic_permalink( $topic_id ); 826 $topic_title = get_post_field( 'post_title', $topic_id, 'raw' ); 827 $topic_link = '<a href="' . esc_url( $topic_permalink ) . '">' . esc_html( $topic_title ) . '</a>'; 828 829 // Forum link 830 $forum_permalink = bbp_get_forum_permalink( $forum_id ); 831 $forum_title = get_post_field( 'post_title', $forum_id, 'raw' ); 832 $forum_link = '<a href="' . esc_url( $forum_permalink ) . '">' . esc_html( $forum_title ) . '</a>'; 833 834 // Format 835 $activity_action = sprintf( $actions[ $type ], $user_link, $topic_link, $forum_link ); 836 837 /** 838 * Filters the formatted activity action new activity string. 839 * 840 * @since 2.6.0 bbPress (r6370) 841 * 842 * @param string $activity_action Activity action string value 843 * @param string $type The type of post. Expects `topic` or `reply`. 844 * @param string $action The current action string. 845 * @param BP_Activity_Activity $activity The BuddyPress activity object. 846 */ 847 return apply_filters( 'bbp_format_activity_action_new_post', $activity_action, $type, $action, $activity ); 848 } 849 850 /** 851 * Formats the dynamic BuddyPress activity action for new topics. 852 * 853 * @since 2.6.0 bbPress (r6370) 854 * 855 * @param string $action The current action string 856 * @param object $activity The BuddyPress activity object 857 * 858 * @return string The formatted activity action. 859 */ 860 function bbp_format_activity_action_new_topic( $action, $activity ) { 861 $action = bbp_format_activity_action_new_post( 'topic', $action, $activity ); 862 863 /** 864 * Filters the formatted activity action new topic string. 865 * 866 * @since 2.6.0 bbPress (r6370) 867 * 868 * @param string $action Activity action string value 869 * @param BP_Activity_Activity $activity Activity item object 870 */ 871 return apply_filters( 'bbp_format_activity_action_new_topic', $action, $activity ); 872 } 873 874 /** 875 * Formats the dynamic BuddyPress activity action for new replies. 876 * 877 * @since 2.6.0 bbPress (r6370) 878 * 879 * @param string $action The current action string 880 * @param object $activity The BuddyPress activity object 881 * 882 * @return string The formatted activity action 883 */ 884 function bbp_format_activity_action_new_reply( $action, $activity ) { 885 $action = bbp_format_activity_action_new_post( 'reply', $action, $activity ); 886 887 /** 888 * Filters the formatted activity action new reply string. 889 * 890 * @since 2.6.0 bbPress (r6370) 891 * 892 * @param string $action Activity action string value 893 * @param BP_Activity_Activity $activity Activity item object 894 */ 895 return apply_filters( 'bbp_format_activity_action_new_reply', $action, $activity ); 896 }
Note: See TracChangeset
for help on using the changeset viewer.