diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php
index c29e56b..0395679 100644
|
|
add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_ |
766 | 766 | * @return array $args |
767 | 767 | */ |
768 | 768 | function bp_blogs_new_blog_comment_query_backpat( $args ) { |
| 769 | global $wpdb; |
| 770 | $bp = buddypress(); |
| 771 | |
769 | 772 | // Bail if this is not a 'new_blog_comment' query |
770 | 773 | if ( 'new_blog_comment' !== $args['action'] ) { |
771 | 774 | return $args; |
772 | 775 | } |
773 | 776 | |
774 | | // display_comments=stream is required to show new-style |
775 | | // 'activity_comment' items inline |
776 | | $args['display_comments'] = 'stream'; |
| 777 | // if activity comments are disabled for blog posts, stop now! |
| 778 | if ( bp_disable_blogforum_comments() ) { |
| 779 | return $args; |
| 780 | } |
777 | 781 | |
778 | | // For the remaining clauses, we filter the SQL query directly |
779 | | add_filter( 'bp_activity_paged_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' ); |
780 | | add_filter( 'bp_activity_total_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' ); |
| 782 | // Comment synced ? |
| 783 | $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = %s", 'bp_blogs_post_comment_id' ) ); |
781 | 784 | |
782 | | // Return the original arguments |
783 | | return $args; |
784 | | } |
785 | | add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); |
| 785 | if ( empty( $activity_ids ) ) { |
| 786 | return $args; |
| 787 | } |
786 | 788 | |
787 | | /** |
788 | | * Filter activity SQL to include new- and old-style 'new_blog_comment' activity items. |
789 | | * |
790 | | * @since BuddyPress (2.1.0) |
791 | | * |
792 | | * @access private |
793 | | * @see bp_blogs_new_blog_comment_query_backpat() |
794 | | * |
795 | | * @param string $query SQL query as assembled in BP_Activity_Activity::get(). |
796 | | * @return string $query Modified SQL query. |
797 | | */ |
798 | | function _bp_blogs_new_blog_comment_query_backpat_filter( $query ) { |
799 | | $bp = buddypress(); |
| 789 | // Init the filter query |
| 790 | $filter_query = array(); |
| 791 | |
| 792 | if ( 'null' === $args['scope'] ) { |
| 793 | $args['scope'] = ''; |
| 794 | } elseif ( 'just-me' === $args['scope'] ) { |
| 795 | $filter_query = array( |
| 796 | 'relation' => 'AND', |
| 797 | array( |
| 798 | 'column' => 'user_id', |
| 799 | 'value' => bp_displayed_user_id(), |
| 800 | ), |
| 801 | ); |
| 802 | $args['scope'] = ''; |
| 803 | } |
| 804 | |
| 805 | $filter_query[] = array( |
| 806 | 'relation' => 'OR', |
| 807 | array( |
| 808 | 'column' => 'type', |
| 809 | 'value' => $args['action'], |
| 810 | ), |
| 811 | array( |
| 812 | 'column' => 'id', |
| 813 | 'value' => $activity_ids, |
| 814 | 'compare' => 'IN' |
| 815 | ), |
| 816 | ); |
800 | 817 | |
801 | | // The query passed to the filter is for old-style 'new_blog_comment' |
802 | | // items. We include new-style 'activity_comment' items by running a |
803 | | // subquery inside of a large OR clause. |
804 | | $activity_comment_subquery = "SELECT a.id FROM {$bp->activity->table_name} a INNER JOIN {$bp->activity->table_name_meta} am ON (a.id = am.activity_id) WHERE am.meta_key = 'bp_blogs_post_comment_id' AND a.type = 'activity_comment'"; |
| 818 | $args['filter_query'] = $filter_query; |
805 | 819 | |
806 | | // WHERE ( [original WHERE clauses] OR a.id IN (activity_comment subquery) ) |
807 | | $query = preg_replace( '|WHERE (.*?) ORDER|', 'WHERE ( ( $1 ) OR ( a.id IN ( ' . $activity_comment_subquery . ' ) ) ) ORDER', $query ); |
| 820 | // Make sure to have comment in stream mode && avoid duplicate content |
| 821 | $args['display_comments'] = 'stream'; |
808 | 822 | |
809 | | // Don't run this on future queries |
810 | | remove_filter( current_filter(), '_bp_blogs_new_blog_comment_query_backpat_filter' ); |
| 823 | // Finally reset the action |
| 824 | $args['action'] = ''; |
811 | 825 | |
812 | | return $query; |
| 826 | // Return the original arguments |
| 827 | return $args; |
813 | 828 | } |
| 829 | add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); |
814 | 830 | |
815 | 831 | /** |
816 | 832 | * Utility function to set up some variables for use in the activity loop. |