| 855 | |
| 856 | /** |
| 857 | * Changes single activity comment entries to use the blog comment permalink. |
| 858 | * |
| 859 | * This is only done if the activity comment is associated with a blog comment. |
| 860 | * |
| 861 | * @since BuddyPress (2.1.0) |
| 862 | * |
| 863 | * @param string $retval The activity permalink |
| 864 | * @param BP_Activity_Activity $activity |
| 865 | * @return string |
| 866 | */ |
| 867 | function bp_blogs_activity_comment_single_permalink( $retval, $activity ) { |
| 868 | if ( 'activity_comment' !== $activity->type ) { |
| 869 | return $retval; |
| 870 | } |
| 871 | |
| 872 | $blog_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); |
| 873 | |
| 874 | if ( ! empty( $blog_comment_id ) ) { |
| 875 | $retval = $activity->primary_link; |
| 876 | } |
| 877 | |
| 878 | return $retval; |
| 879 | } |
| 880 | add_filter( 'bp_activity_get_permalink', 'bp_blogs_activity_comment_single_permalink', 10, 2 ); |
| 881 | |
| 882 | /** |
| 883 | * Formats single activity comment entries to use the blog comment action. |
| 884 | * |
| 885 | * This is only done if the activity comment is associated with a blog comment. |
| 886 | * |
| 887 | * @since BuddyPress (2.1.0) |
| 888 | * |
| 889 | * @param string $retval The activity action |
| 890 | * @param BP_Activity_Activity $activity |
| 891 | * @return string |
| 892 | */ |
| 893 | function bp_blogs_activity_comment_single_action( $retval, $activity ) { |
| 894 | if ( 'activity_comment' !== $activity->type ) { |
| 895 | return $retval; |
| 896 | } |
| 897 | |
| 898 | $blog_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); |
| 899 | |
| 900 | if ( ! empty( $blog_comment_id ) ) { |
| 901 | // fetch the parent blog post activity item |
| 902 | $parent_blog_post_activity = new BP_Activity_Activity( $activity->item_id ); |
| 903 | |
| 904 | // fake a 'new_blog_comment' activity object |
| 905 | $object = $activity; |
| 906 | |
| 907 | // override 'item_id' to use blog ID |
| 908 | $object->item_id = $parent_blog_post_activity->item_id; |
| 909 | |
| 910 | // override 'secondary_item_id' to use comment ID |
| 911 | $object->secondary_item_id = $blog_comment_id; |
| 912 | |
| 913 | // now format the activity action using the 'new_blog_comment' action callback |
| 914 | $retval = bp_blogs_format_activity_action_new_blog_comment( '', $object ); |
| 915 | } |
| 916 | |
| 917 | return $retval; |
| 918 | } |
| 919 | add_filter( 'bp_get_activity_action_pre_meta', 'bp_blogs_activity_comment_single_action', 10, 2 ); |
| 920 | |
| 921 | /** |
| 922 | * Filters activity stream to match activity comments joined to blog comments. |
| 923 | * |
| 924 | * This is only done when the "Comments" dropdown filter is used and if |
| 925 | * activity commenting is allowed on blog posts. |
| 926 | * |
| 927 | * @since BuddyPress (2.1.0) |
| 928 | * |
| 929 | * @param string $retval The activity action |
| 930 | * @param BP_Activity_Activity $activity |
| 931 | * @return string |
| 932 | */ |
| 933 | function bp_blogs_activity_comment_filter_stream( $retval ) { |
| 934 | // not filtering for blog comments? stop now! |
| 935 | if ( 'new_blog_comment' !== $retval['action'] ) { |
| 936 | return $retval; |
| 937 | } |
| 938 | |
| 939 | // if activity comments are disabled for blog posts, stop now! |
| 940 | if ( bp_disable_blogforum_comments() ) { |
| 941 | return $retval; |
| 942 | } |
| 943 | |
| 944 | // override the activity stream parameters to match activity comments |
| 945 | // associated with blog comments |
| 946 | $retval['display_comments'] = 'stream'; |
| 947 | $retval['action'] = 'activity_comment'; |
| 948 | $retval['meta_query'][] = array( |
| 949 | 'key' => 'bp_blogs_post_comment_id', |
| 950 | ); |
| 951 | |
| 952 | return $retval; |
| 953 | } |
| 954 | add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_activity_comment_filter_stream' ); |