Skip to:
Content

BuddyPress.org

Ticket #6482: 6482.04.patch

File 6482.04.patch, 126.8 KB (added by imath, 9 years ago)
  • src/bp-activity/bp-activity-actions.php

    diff --git src/bp-activity/bp-activity-actions.php src/bp-activity/bp-activity-actions.php
    index 7d17133..8109ae7 100644
    function bp_activity_catch_transition_post_type_status( $new_status, $old_status 
    831831        }
    832832}
    833833add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
     834
     835/**
     836 * When a post type comment status transition occurs, update the relevant activity's status.
     837 *
     838 * @since 2.5.0
     839 *
     840 * @param string     $new_status New comment status.
     841 * @param string     $old_status Previous comment status.
     842 * @param WP_Comment $comment Comment data.
     843 */
     844function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) {
     845        $post_type = get_post_type( $comment->comment_post_ID );
     846        if ( ! $post_type ) {
     847                return;
     848        }
     849
     850        // Get the post type tracking args.
     851        $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
     852
     853        // Bail if the activity type does not exist
     854        if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
     855                return false;
     856
     857        // Set the $activity_comment_object
     858        } else {
     859                $activity_comment_object = $activity_post_object->comments_tracking;
     860        }
     861
     862        // Init an empty activity ID
     863        $activity_id = 0;
     864
     865        /**
     866         * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
     867         *
     868         * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
     869         * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
     870         * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
     871         * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.
     872         * Otherwise, record the comment into the activity stream.
     873         */
     874
     875        // This clause handles delete/hold.
     876        if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {
     877                return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object );
     878
     879        // These clauses handle trash, spam, and un-spams.
     880        } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) {
     881                $action = 'spam_activity';
     882        } elseif ( 'approved' == $new_status ) {
     883                $action = 'ham_activity';
     884        }
     885
     886        // Get the activity
     887        if ( bp_disable_blogforum_comments() ) {
     888                $activity_id = bp_activity_get_activity_id( array(
     889                        'component'         => $activity_comment_object->component_id,
     890                        'item_id'           => get_current_blog_id(),
     891                        'secondary_item_id' => $comment->comment_ID,
     892                        'type'              => $activity_comment_object->action_id,
     893                ) );
     894        } else {
     895                $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
     896        }
     897
     898        /**
     899         * Leave a chance to plugins to manage activity comments differently.
     900         *
     901         * @since  2.5.0
     902         *
     903         * @param bool        $value       True to override BuddyPress management.
     904         * @param string      $post_type   The post type name.
     905         * @param int         $activity_id The post type activity (0 if not found).
     906         * @param string      $new_status  The new status of the post type comment.
     907         * @param string      $old_status  The old status of the post type comment.
     908         * @param WP_Comment  $comment Comment data.
     909         */
     910        if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) {
     911                return false;
     912        }
     913
     914        // Check activity item exists
     915        if ( empty( $activity_id ) ) {
     916                // If no activity exists, but the comment has been approved, record it into the activity table.
     917                if ( 'approved' == $new_status ) {
     918                        return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object );
     919                }
     920
     921                return;
     922        }
     923
     924        // Create an activity object
     925        $activity = new BP_Activity_Activity( $activity_id );
     926        if ( empty( $activity->component ) ) {
     927                return;
     928        }
     929
     930        // Spam/ham the activity if it's not already in that state
     931        if ( 'spam_activity' === $action && ! $activity->is_spam ) {
     932                bp_activity_mark_as_spam( $activity );
     933        } elseif ( 'ham_activity' == $action) {
     934                bp_activity_mark_as_ham( $activity );
     935        }
     936
     937        // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
     938        $post_type_comment_action = $activity_comment_object->action_id;
     939        $comment_akismet_history = create_function( '$t', '$t[] = $post_type_comment_action; return $t;' );
     940        add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
     941
     942        // Make sure the activity change won't edit the comment if sync is on
     943        remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
     944
     945        // Save the updated activity
     946        $activity->save();
     947
     948        // Restore the action
     949        add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
     950
     951        // Remove the "new_blog_comment" activity type whitelist so we don't break anything
     952        remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
     953}
     954add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );
  • src/bp-activity/bp-activity-admin.php

    diff --git src/bp-activity/bp-activity-admin.php src/bp-activity/bp-activity-admin.php
    index 21fda74..765461f 100644
    class BP_Activity_List_Table extends WP_List_Table { 
    11031103
    11041104                // Option defaults.
    11051105                $filter           = array();
     1106                $filter_query     = false;
    11061107                $include_id       = false;
    11071108                $search_terms     = false;
    11081109                $sort             = 'DESC';
    class BP_Activity_List_Table extends WP_List_Table { 
    11291130                }*/
    11301131
    11311132                // Filter.
    1132                 if ( !empty( $_REQUEST['activity_type'] ) )
     1133                if ( ! empty( $_REQUEST['activity_type'] ) ) {
    11331134                        $filter = array( 'action' => $_REQUEST['activity_type'] );
    11341135
     1136                        /**
     1137                         * Filter here to override the filter with a filter query
     1138                         *
     1139                         * @since  2.5.0
     1140                         *
     1141                         * @param array $filter
     1142                         */
     1143                        $has_filter_query = apply_filters( 'bp_activity_list_table_filter_activity_type_items', $filter );
     1144
     1145                        if ( ! empty( $has_filter_query['filter_query'] ) ) {
     1146                                // Reset the filter
     1147                                $filter       = array();
     1148
     1149                                // And use the filter query instead
     1150                                $filter_query = $has_filter_query['filter_query'];
     1151                        }
     1152                }
     1153
    11351154                // Are we doing a search?
    11361155                if ( !empty( $_REQUEST['s'] ) )
    11371156                        $search_terms = $_REQUEST['s'];
    class BP_Activity_List_Table extends WP_List_Table { 
    11581177                        'page'             => $page,
    11591178                        'per_page'         => $per_page,
    11601179                        'search_terms'     => $search_terms,
     1180                        'filter_query'     => $filter_query,
    11611181                        'show_hidden'      => true,
    11621182                        // 'sort'             => $sort,
    11631183                        'spam'             => $spam,
    class BP_Activity_List_Table extends WP_List_Table { 
    17571777         * functions from working as intended.
    17581778         *
    17591779         * @since 2.0.0
     1780         * @since 2.5.0 Include Post type activities types
    17601781         *
    17611782         * @param array $item An array version of the BP_Activity_Activity object.
    17621783         * @return bool $can_comment
    17631784         */
    1764         protected function can_comment( $item  ) {
     1785        protected function can_comment( $item ) {
    17651786                $can_comment = true;
     1787                $bp = buddypress();
    17661788
    1767                 if ( $this->disable_blogforum_comments ) {
    1768                         switch ( $item['type'] ) {
    1769                                 case 'new_blog_post' :
    1770                                 case 'new_blog_comment' :
    1771                                 case 'new_forum_topic' :
    1772                                 case 'new_forum_post' :
    1773                                         $can_comment = false;
    1774                                         break;
     1789                $turn_off = 0;
     1790                if ( ! empty( $this->disable_blogforum_comments ) ) {
     1791                        $turn_off = 1;
     1792                }
     1793
     1794                $maybe_turn_off = array_fill_keys( array(
     1795                        'new_blog_post',
     1796                        'new_blog_comment',
     1797                        'new_forum_topic',
     1798                        'new_forum_post',
     1799                ), $turn_off );
     1800
     1801                if ( ! isset( $bp->activity->track ) ) {
     1802                        $bp->activity->track = bp_activity_get_post_types_tracking_args();
     1803                }
     1804
     1805                foreach ( $bp->activity->track as $type => $tracking_args ) {
     1806                        if ( empty( $tracking_args->activity_comment ) ) {
     1807                                $maybe_turn_off[ $type ] = $turn_off;
    17751808                        }
     1809                }
    17761810
    1777                 // Activity comments supported.
    1778                 } else {
    1779                         // Activity comment.
    1780                         if ( 'activity_comment' == $item['type'] ) {
    1781                                 // Blogs.
    1782                                 if ( bp_is_active( 'blogs' ) ) {
    1783                                         // Grab the parent activity entry.
    1784                                         $parent_activity = new BP_Activity_Activity( $item['item_id'] );
    1785 
    1786                                         // Fetch blog post comment depth and if the blog post's comments are open.
    1787                                         bp_blogs_setup_activity_loop_globals( $parent_activity );
    1788 
    1789                                         // Check if the activity item can be replied to.
    1790                                         if ( false === bp_blogs_can_comment_reply( true, $item ) ) {
    1791                                                 $can_comment = false;
    1792                                         }
    1793                                 }
     1811                $can_comment = empty( $maybe_turn_off[ $item['type'] ] );
    17941812
    1795                         // Blog post.
    1796                         } elseif ( 'new_blog_post' == $item['type'] ) {
    1797                                 if ( bp_is_active( 'blogs' ) ) {
    1798                                         bp_blogs_setup_activity_loop_globals( (object) $item );
     1813                if ( ! $this->disable_blogforum_comments && bp_is_active( 'blogs' ) ) {
     1814                        $parent_activity = false;
    17991815
    1800                                         if ( empty( buddypress()->blogs->allow_comments[$item['id']] ) ) {
    1801                                                 $can_comment = false;
    1802                                         }
    1803                                 }
     1816                        if ( bp_activity_post_type_supports( $item['type'], 'comment-tracking' ) ) {
     1817                                $parent_activity = (object) $item;
     1818                        } elseif ( 'activity_comment' === $item['type'] && bp_activity_get_meta( $item['id'], 'bp_blogs_post_comment_id' ) ) {
     1819                                $parent_activity =  new BP_Activity_Activity( $item['item_id'] );
     1820                        }
     1821
     1822                        if ( ! empty( $parent_activity ) ) {
     1823                                // Fetch blog post comment depth and if the blog post's comments are open.
     1824                                bp_blogs_setup_activity_loop_globals( $parent_activity );
     1825
     1826                                $can_comment = bp_blogs_can_comment_reply( true, $item );
    18041827                        }
    18051828                }
    18061829
  • src/bp-activity/bp-activity-functions.php

    diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
    index 9982733..cc16395 100644
    function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array 
    419419                return false;
    420420        }
    421421
     422        $activity_labels = array(
     423                /* Post labels */
     424                'bp_activity_admin_filter',
     425                'bp_activity_front_filter',
     426                'bp_activity_new_post',
     427                'bp_activity_new_post_ms',
     428                /* Comment labels */
     429                'bp_activity_comments_admin_filter',
     430                'bp_activity_comments_front_filter',
     431                'bp_activity_new_comment',
     432                'bp_activity_new_comment_ms'
     433        );
     434
    422435        // Labels are loaded into the post type object.
    423         foreach ( array( 'bp_activity_admin_filter', 'bp_activity_front_filter', 'bp_activity_new_post', 'bp_activity_new_post_ms' ) as $label_type ) {
     436        foreach ( $activity_labels as $label_type ) {
    424437                if ( ! empty( $args[ $label_type ] ) ) {
    425438                        $wp_post_types[ $post_type ]->labels->{$label_type} = $args[ $label_type ];
    426439                        unset( $args[ $label_type ] );
    function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array 
    437450 * Get tracking arguments for a specific post type.
    438451 *
    439452 * @since 2.2.0
     453 * @since 2.5.0 Add post type comments tracking args
    440454 *
    441455 * @param  string $post_type Name of the post type.
    442456 * @return object The tracking arguments of the post type.
    function bp_activity_get_post_type_tracking_args( $post_type ) { 
    446460                return false;
    447461        }
    448462
    449         $post_type_object = get_post_type_object( $post_type );
     463        $post_type_object           = get_post_type_object( $post_type );
     464        $post_type_support_comments = post_type_supports( $post_type, 'comments' );
    450465
    451466        $post_type_activity = array(
    452                 'component_id'      => buddypress()->activity->id,
    453                 'action_id'         => 'new_' . $post_type,
    454                 'format_callback'   => 'bp_activity_format_activity_action_custom_post_type_post',
    455                 'front_filter'      => $post_type_object->labels->name,
    456                 'contexts'          => array( 'activity' ),
    457                 'position'          => 0,
    458                 'singular'          => strtolower( $post_type_object->labels->singular_name ),
    459                 'activity_comment' => ! post_type_supports( $post_type, 'comments' ),
     467                'component_id'            => buddypress()->activity->id,
     468                'action_id'               => 'new_' . $post_type,
     469                'format_callback'         => 'bp_activity_format_activity_action_custom_post_type_post',
     470                'front_filter'            => $post_type_object->labels->name,
     471                'contexts'                => array( 'activity' ),
     472                'position'                => 0,
     473                'singular'                => strtolower( $post_type_object->labels->singular_name ),
     474                'activity_comment'        => ! $post_type_support_comments,
     475                'comment_action_id'       => false,
     476                'comment_format_callback' => 'bp_activity_format_activity_action_custom_post_type_comment',
    460477        );
    461478
    462479        if ( ! empty( $post_type_object->bp_activity ) ) {
    function bp_activity_get_post_type_tracking_args( $post_type ) { 
    489506                $post_type_activity->new_post_type_action_ms = $post_type_object->labels->bp_activity_new_post_ms;
    490507        }
    491508
     509        // If the post type supports comments and has a comment action id, build the comments tracking args
     510        if ( $post_type_support_comments && ! empty( $post_type_activity->comment_action_id ) ) {
     511                // Init a new container for the activity type for comments
     512                $post_type_activity->comments_tracking = new stdClass();
     513
     514                // Build the activity type for comments
     515                $post_type_activity->comments_tracking->component_id = $post_type_activity->component_id;
     516                $post_type_activity->comments_tracking->action_id    = $post_type_activity->comment_action_id;
     517
     518                // Try to get the comments admin filter from the post type labels.
     519                if ( ! empty( $post_type_object->labels->bp_activity_comments_admin_filter ) ) {
     520                        $post_type_activity->comments_tracking->admin_filter = $post_type_object->labels->bp_activity_comments_admin_filter;
     521
     522                // Fall back to a generic name.
     523                } else {
     524                        $post_type_activity->comments_tracking->admin_filter = _x( 'New item comment posted', 'Post Type generic comments activity admin filter', 'buddypress' );
     525                }
     526
     527                $post_type_activity->comments_tracking->format_callback = $post_type_activity->comment_format_callback;
     528
     529                // Check for the comments front filter in the post type labels.
     530                if ( ! empty( $post_type_object->labels->bp_activity_comments_front_filter ) ) {
     531                        $post_type_activity->comments_tracking->front_filter = $post_type_object->labels->bp_activity_comments_front_filter;
     532
     533                // Fall back to a generic name.
     534                } else {
     535                        $post_type_activity->comments_tracking->front_filter = sprintf( __( '%s comments', 'buddypress' ), $post_type_object->labels->singular_name );
     536                }
     537
     538                $post_type_activity->comments_tracking->contexts = $post_type_activity->contexts;
     539                $post_type_activity->comments_tracking->position = (int) $post_type_activity->position + 1;
     540
     541                // Try to get the action for new post type comment action on non-multisite installations.
     542                if ( ! empty( $post_type_object->labels->bp_activity_new_comment ) ) {
     543                        $post_type_activity->comments_tracking->new_post_type_comment_action = $post_type_object->labels->bp_activity_new_comment;
     544                }
     545
     546                // Try to get the action for new post type comment action on multisite installations.
     547                if ( ! empty( $post_type_object->labels->bp_activity_new_comment_ms ) ) {
     548                        $post_type_activity->comments_tracking->new_post_type_comment_action_ms = $post_type_object->labels->bp_activity_new_comment_ms;
     549                }
     550        }
     551
    492552        /**
    493553         * Filters tracking arguments for a specific post type.
    494554         *
    function bp_activity_get_post_type_tracking_args( $post_type ) { 
    504564 * Get tracking arguments for all post types.
    505565 *
    506566 * @since 2.2.0
     567 * @since 2.5.0 Include post type comments tracking args if needed
    507568 *
    508569 * @return array List of post types with their tracking arguments.
    509570 */
    function bp_activity_get_post_types_tracking_args() { 
    517578                $track_post_type = bp_activity_get_post_type_tracking_args( $post_type );
    518579
    519580                if ( ! empty( $track_post_type ) ) {
     581                        // Set the post type comments tracking args
     582                        if ( ! empty( $track_post_type->comments_tracking->action_id ) ) {
     583                                // Used to check support for comment tracking by activity type (new_post_type_comment)
     584                                $track_post_type->comments_tracking->comments_tracking = true;
     585
     586                                $post_types_tracking_args[ $track_post_type->comments_tracking->action_id ] = $track_post_type->comments_tracking;
     587
     588                                // Used to check support for comment tracking by activity type (new_post_type)
     589                                $track_post_type->comments_tracking = true;
     590                        }
     591
    520592                        $post_types_tracking_args[ $track_post_type->action_id ] = $track_post_type;
    521593                }
    522594
    function bp_activity_get_post_types_tracking_args() { 
    534606}
    535607
    536608/**
     609 * Check if the *Post Type* activity supports a specific feature.
     610 *
     611 * @since 2.5.0
     612 *
     613 * @param  string $activity_type The activity type to check.
     614 * @param  string $supports      The feature to check. Currently supports:
     615 *                               'comment-tracking', 'comment-reply'. See inline doc for more info.
     616 * @return bool
     617 */
     618function bp_activity_post_type_supports( $activity_type = '', $supports = '' ) {
     619        $retval = false;
     620
     621        $bp = buddypress();
     622
     623        switch ( $supports ) {
     624                /**
     625                 * Does this activity type support comment tracking?
     626                 *
     627                 * eg. 'new_blog_post' and 'new_blog_comment' will both return true.
     628                 */
     629                case 'comment-tracking' :
     630                        // Set the activity track global if not set yet
     631                        if ( empty( $bp->activity->track ) ) {
     632                                $bp->activity->track = bp_activity_get_post_types_tracking_args();
     633                        }
     634
     635                        if ( ! empty( $bp->activity->track[ $activity_type ]->comments_tracking ) ) {
     636                                $retval = true;
     637                        }
     638                        break;
     639
     640                /**
     641                 * Is this a parent activity type that support post comments?
     642                 *
     643                 * eg. 'new_blog_post' will return true; 'new_blog_comment' will return false.
     644                 */
     645                case 'comment-reply' :
     646                        // Set the activity track global if not set yet
     647                        if ( empty( $bp->activity->track ) ) {
     648                                $bp->activity->track = bp_activity_get_post_types_tracking_args();
     649                        }
     650
     651                        if ( ! empty( $bp->activity->track[ $activity_type ]->comments_tracking ) && ! empty( $bp->activity->track[ $activity_type ]->comment_action_id ) ) {
     652                                $retval = true;
     653                        }
     654                        break;
     655        }
     656
     657        return $retval;
     658}
     659
     660/**
     661 * Helper function to get the parent type out of an activity comment generated by a post type comment
     662 *
     663 * eg: new_blog_comment > new_blog_post
     664 *
     665 * @since 2.5.0
     666 *
     667 * @param  string       $type the activity type to check
     668 * @return array|object $parent_type the parent type registered into the post type tracking args
     669 *                      empty array if not found
     670 */
     671function bp_activity_post_type_get_parent_type( $type ) {
     672        if ( empty( $type ) ) {
     673                return false;
     674        }
     675
     676        $bp = buddypress();
     677
     678        // Set the activity track global if not set yet
     679        if ( empty( $bp->activity->track ) ) {
     680                $bp->activity->track = bp_activity_get_post_types_tracking_args();
     681        }
     682
     683        $parent_type = wp_list_filter( $bp->activity->track, array( 'comment_action_id' => $type ) );
     684
     685        return reset( $parent_type );
     686}
     687
     688/**
    537689 * Get all components' activity actions, sorted by their position attribute.
    538690 *
    539691 * @since 2.2.0
    function bp_activity_format_activity_action_custom_post_type_post( $action, $act 
    13961548        return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity );
    13971549}
    13981550
     1551/**
     1552 * Format activity action strings for custom post types comments.
     1553 *
     1554 * @since 2.5.0
     1555 *
     1556 * @param string $action   Static activity action.
     1557 * @param object $activity Activity data object.
     1558 *
     1559 * @return string
     1560 */
     1561function bp_activity_format_activity_action_custom_post_type_comment( $action, $activity ) {
     1562        $bp = buddypress();
     1563
     1564        // Fetch all the tracked post types once.
     1565        if ( empty( $bp->activity->track ) ) {
     1566                $bp->activity->track = bp_activity_get_post_types_tracking_args();
     1567        }
     1568
     1569        if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) {
     1570                return $action;
     1571        }
     1572
     1573        $user_link = bp_core_get_userlink( $activity->user_id );
     1574
     1575        if ( is_multisite() ) {
     1576                $blog_link = '<a href="' . esc_url( get_home_url( $activity->item_id ) ) . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>';
     1577
     1578                if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_comment_action_ms ) ) {
     1579                        $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_comment_action_ms, $user_link, $activity->primary_link, $blog_link );
     1580                } else {
     1581                        $action = sprintf( _x( '%1$s commented on the <a href="%2$s">item</a>, on the site %3$s', 'Activity Custom Post Type comment action', 'buddypress' ), $user_link, $activity->primary_link, $blog_link );
     1582                }
     1583        } else {
     1584                if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_comment_action ) ) {
     1585                        $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_comment_action, $user_link, $activity->primary_link );
     1586                } else {
     1587                        $action = sprintf( _x( '%1$s commented on the <a href="%2$s">item</a>', 'Activity Custom Post Type post comment action', 'buddypress' ), $user_link, $activity->primary_link );
     1588                }
     1589        }
     1590
     1591        /**
     1592         * Filters the formatted custom post type activity comment action string.
     1593         *
     1594         * @since 2.5.0
     1595         *
     1596         * @param string               $action   Activity action string value.
     1597         * @param BP_Activity_Activity $activity Activity item object.
     1598         */
     1599        return apply_filters( 'bp_activity_custom_post_type_comment_action', $action, $activity );
     1600}
     1601
    13991602/*
    14001603 * Business functions are where all the magic happens in BuddyPress. They will
    14011604 * handle the actual saving or manipulation of information. Usually they will
    function bp_activity_post_type_update( $post = null ) { 
    19842187         * Fires after the updating of an activity item for a custom post type entry.
    19852188         *
    19862189         * @since 2.2.0
     2190         * @since 2.5.0 Add the post type tracking args parameter
    19872191         *
    1988          * @param WP_Post              $post     Post object.
    1989          * @param BP_Activity_Activity $activity Activity object.
     2192         * @param WP_Post              $post                 Post object.
     2193         * @param BP_Activity_Activity $activity             Activity object.
     2194         * @param object               $activity_post_object The post type tracking args object.
    19902195         */
    1991         do_action( 'bp_activity_post_type_updated', $post, $activity );
     2196        do_action( 'bp_activity_post_type_updated', $post, $activity, $activity_post_object );
    19922197
    19932198        return $updated;
    19942199}
    function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 
    20442249}
    20452250
    20462251/**
     2252 * Create an activity item for a newly posted post type comment.
     2253 *
     2254 * @since 2.5.0
     2255 *
     2256 * @param  int  $comment_id  ID of the comment.
     2257 * @param  bool $is_approved Whether the comment is approved or not.
     2258 * @param  object $activity_post_object the post type tracking args object.
     2259 *
     2260 * @return int|bool The ID of the activity on success. False on error.
     2261 */
     2262function bp_activity_post_type_comment( $comment_id = 0, $is_approved = true, $activity_post_object = null ) {
     2263        // Get the users comment
     2264        $post_type_comment = get_comment( $comment_id );
     2265
     2266        // Don't record activity if the comment hasn't been approved
     2267        if ( empty( $is_approved ) ) {
     2268                return false;
     2269        }
     2270
     2271        // Don't record activity if no email address has been included
     2272        if ( empty( $post_type_comment->comment_author_email ) ) {
     2273                return false;
     2274        }
     2275
     2276        // Don't record activity if the comment has already been marked as spam
     2277        if ( 'spam' === $is_approved ) {
     2278                return false;
     2279        }
     2280
     2281        // Get the user by the comment author email.
     2282        $user = get_user_by( 'email', $post_type_comment->comment_author_email );
     2283
     2284        // If user isn't registered, don't record activity
     2285        if ( empty( $user ) ) {
     2286                return false;
     2287        }
     2288
     2289        // Get the user_id
     2290        $user_id = (int) $user->ID;
     2291
     2292        // Get blog and post data
     2293        $blog_id = get_current_blog_id();
     2294
     2295        // Get the post
     2296        $post_type_comment->post = get_post( $post_type_comment->comment_post_ID );
     2297
     2298        if ( ! is_a( $post_type_comment->post, 'WP_Post' ) ) {
     2299                return false;
     2300        }
     2301
     2302        /**
     2303         * Filters whether to publish activities about the comment regarding the post status
     2304         *
     2305         * @since 2.5.0
     2306         *
     2307         * @param bool true to bail, false otherwise.
     2308         */
     2309        $is_post_status_not_allowed = (bool) apply_filters( 'bp_activity_post_type_is_post_status_allowed', 'publish' !== $post_type_comment->post->post_status || ! empty( $post_type_comment->post->post_password ) );
     2310
     2311        // If this is a password protected post, or not a public post don't record the comment
     2312        if ( $is_post_status_not_allowed ) {
     2313                return false;
     2314        }
     2315
     2316        // Set post type
     2317        $post_type = $post_type_comment->post->post_type;
     2318
     2319        if ( empty( $activity_post_object ) ) {
     2320                // Get the post type tracking args.
     2321                $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
     2322
     2323                // Bail if the activity type does not exist
     2324                if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
     2325                        return false;
     2326                }
     2327        }
     2328
     2329        // Set the $activity_comment_object
     2330        $activity_comment_object = $activity_post_object->comments_tracking;
     2331
     2332        /**
     2333         * Filters whether or not to post the activity about the comment.
     2334         *
     2335         * This is a variable filter, dependent on the post type,
     2336         * that lets components or plugins bail early if needed.
     2337         *
     2338         * @since 2.5.0
     2339         *
     2340         * @param bool $value      Whether or not to continue.
     2341         * @param int  $blog_id    ID of the current site.
     2342         * @param int  $post_id    ID of the current post being commented.
     2343         * @param int  $user_id    ID of the current user.
     2344         * @param int  $comment_id ID of the current comment being posted.
     2345         */
     2346        if ( false === apply_filters( "bp_activity_{$post_type}_pre_comment", true, $blog_id, $post_type_comment->post->ID, $user_id, $comment_id ) ) {
     2347                return false;
     2348        }
     2349
     2350        // Is this an update ?
     2351        $activity_id = bp_activity_get_activity_id( array(
     2352                'user_id'           => $user_id,
     2353                'component'         => $activity_comment_object->component_id,
     2354                'type'              => $activity_comment_object->action_id,
     2355                'item_id'           => $blog_id,
     2356                'secondary_item_id' => $comment_id,
     2357        ) );
     2358
     2359        // Record this in activity streams.
     2360        $comment_link = get_comment_link( $post_type_comment->comment_ID );
     2361
     2362        // Backward compatibility filters for the 'blogs' component.
     2363        if ( 'blogs' == $activity_comment_object->component_id )  {
     2364                $activity_content      = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $post_type_comment->comment_content, &$post_type_comment, $comment_link ) );
     2365                $activity_primary_link = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$post_type_comment ) );
     2366        } else {
     2367                $activity_content      = $post_type_comment->comment_content;
     2368                $activity_primary_link = $comment_link;
     2369        }
     2370
     2371        $activity_args = array(
     2372                'id'            => $activity_id,
     2373                'user_id'       => $user_id,
     2374                'content'       => $activity_content,
     2375                'primary_link'  => $activity_primary_link,
     2376                'component'     => $activity_comment_object->component_id,
     2377                'recorded_time' => $post_type_comment->comment_date_gmt,
     2378        );
     2379
     2380        if ( bp_disable_blogforum_comments() ) {
     2381                $blog_url = get_home_url( $blog_id );
     2382                $post_url = add_query_arg(
     2383                        'p',
     2384                        $post_type_comment->post->ID,
     2385                        trailingslashit( $blog_url )
     2386                );
     2387
     2388                $activity_args['type']              = $activity_comment_object->action_id;
     2389                $activity_args['item_id']           = $blog_id;
     2390                $activity_args['secondary_item_id'] = $post_type_comment->comment_ID;
     2391
     2392                if ( ! empty( $activity_args['content'] ) ) {
     2393                        // Create the excerpt.
     2394                        $activity_summary = bp_activity_create_summary( $activity_args['content'], $activity_args );
     2395
     2396                        // Backward compatibility filter for blog comments.
     2397                        if ( 'blogs' == $activity_post_object->component_id )  {
     2398                                $activity_args['content'] = apply_filters( 'bp_blogs_record_activity_content', $activity_summary, $activity_args['content'], $activity_args, $post_type );
     2399                        } else {
     2400                                $activity_args['content'] = $activity_summary;
     2401                        }
     2402                }
     2403
     2404                // Set up the action by using the format functions.
     2405                $action_args = array_merge( $activity_args, array(
     2406                        'post_title' => $post_type_comment->post->post_title,
     2407                        'post_url'   => $post_url,
     2408                        'blog_url'   => $blog_url,
     2409                        'blog_name'  => get_blog_option( $blog_id, 'blogname' ),
     2410                ) );
     2411
     2412                $activity_args['action'] = call_user_func_array( $activity_comment_object->format_callback, array( '', (object) $action_args ) );
     2413
     2414                // Make sure the action is set.
     2415                if ( empty( $activity_args['action'] ) ) {
     2416                        return;
     2417                } else {
     2418                        // Backward compatibility filter for the blogs component.
     2419                        if ( 'blogs' === $activity_post_object->component_id )  {
     2420                                $activity_args['action'] = apply_filters( 'bp_blogs_record_activity_action', $activity_args['action'] );
     2421                        }
     2422                }
     2423
     2424                $activity_id = bp_activity_add( $activity_args );
     2425        }
     2426
     2427        /**
     2428         * Fires after the publishing of an activity item for a newly published post type post.
     2429         *
     2430         * @since 2.5.0
     2431         *
     2432         * @param int        $activity_id          ID of the newly published activity item.
     2433         * @param WP_Comment $post_type_comment    Comment object.
     2434         * @param array      $activity_args        Array of activity arguments.
     2435         * @param object     $activity_post_object the post type tracking args object.
     2436         */
     2437        do_action_ref_array( 'bp_activity_post_type_comment', array( &$activity_id, $post_type_comment, $activity_args, $activity_post_object ) );
     2438
     2439        return $activity_id;
     2440}
     2441add_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 );
     2442add_action( 'edit_comment', 'bp_activity_post_type_comment', 10    );
     2443
     2444/**
     2445 * Remove an activity item when a comment about a post type is deleted.
     2446 *
     2447 * @since 2.5.0
     2448 *
     2449 * @param  int    $comment_id           ID of the comment.
     2450 * @param  object $activity_post_object The post type tracking args object.
     2451 *
     2452 * @return bool True on success. False on error.
     2453 */
     2454function bp_activity_post_type_remove_comment( $comment_id = 0, $activity_post_object = null ) {
     2455        if ( empty( $activity_post_object ) ) {
     2456                $comment = get_comment( $comment_id );
     2457                if ( ! $comment ) {
     2458                        return;
     2459                }
     2460
     2461                $post_type = get_post_type( $comment->comment_post_ID );
     2462                if ( ! $post_type ) {
     2463                        return;
     2464                }
     2465
     2466                // Get the post type tracking args.
     2467                $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
     2468
     2469                // Bail if the activity type does not exist
     2470                if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
     2471                        return false;
     2472                }
     2473        }
     2474
     2475        // Set the $activity_comment_object
     2476        $activity_comment_object = $activity_post_object->comments_tracking;
     2477
     2478        if ( empty( $activity_comment_object->action_id ) ) {
     2479                return false;
     2480        }
     2481
     2482        $deleted = false;
     2483
     2484        if ( bp_disable_blogforum_comments() ) {
     2485                $deleted = bp_activity_delete_by_item_id( array(
     2486                        'item_id'           => get_current_blog_id(),
     2487                        'secondary_item_id' => $comment_id,
     2488                        'component'         => $activity_comment_object->component_id,
     2489                        'type'              => $activity_comment_object->action_id,
     2490                        'user_id'           => false,
     2491                ) );
     2492        }
     2493
     2494        /**
     2495         * Fires after the custom post type comment activity was removed.
     2496         *
     2497         * @since 2.5.0
     2498         *
     2499         * @param bool       $deleted              True if the activity was deleted false otherwise
     2500         * @param WP_Comment $comment              Comment object.
     2501         * @param object     $activity_post_object The post type tracking args object.
     2502         * @param string     $value                The post type comment activity type.
     2503         */
     2504        do_action( 'bp_activity_post_type_remove_comment', $deleted, $comment_id, $activity_post_object, $activity_comment_object->action_id );
     2505
     2506        return $deleted;
     2507}
     2508add_action( 'delete_comment', 'bp_activity_post_type_remove_comment', 10, 1 );
     2509
     2510/**
     2511 * Get all activity comments corresponding to Post type synced comments
     2512 * and reset the bp_parent_type activity meta.
     2513 *
     2514 * Used in the 2.5.0 upgrade routine as we need to make sure filtering the activities
     2515 * for new_blog_comment is getting activity_comment types having a new_blog_post activity
     2516 * type as their parent activity. It can also be used as a repair tool too, if needed.
     2517 *
     2518 * @since 2.5.0
     2519 */
     2520function bp_activity_post_type_comment_reset_parent_type_meta() {
     2521        /**
     2522         * First get all activities associated to a Post type comment ID
     2523         * without a bp_parent_type meta set.
     2524         */
     2525        $synced_post_comments = bp_activity_get( array(
     2526                'type'              => 'activity_comment',
     2527                'display_comments'  => 'stream',
     2528                'per_page'          => false,
     2529                'meta_query'        => array(
     2530                        'relation' => 'AND',
     2531                        array(
     2532                                'key'       => 'bp_blogs_post_comment_id',
     2533                                'compare'   => 'EXISTS',
     2534                        ),
     2535                        array(
     2536                                'key'       => 'bp_parent_type',
     2537                                'compare'   => 'NOT EXISTS',
     2538                        ),
     2539                )
     2540        ) );
     2541
     2542        if ( empty( $synced_post_comments['activities'] ) ) {
     2543                return;
     2544        }
     2545
     2546        // Prepare the 'in' parameter to get the parent activity types
     2547        $parent_activities = array_unique( wp_list_pluck( $synced_post_comments['activities'], 'item_id' ) );
     2548
     2549        $parent_activity_types = bp_activity_get( array(
     2550                'per_page' => false,
     2551                'in'       => $parent_activities,
     2552        ) );
     2553
     2554        if ( empty( $parent_activity_types['activities'] ) ) {
     2555                return;
     2556        }
     2557
     2558        // Build the list of parent activity types
     2559        $parent_activity_types = wp_list_pluck( $parent_activity_types['activities'], 'type', 'id' );
     2560
     2561        // Loop through each activity and set the 'bp_parent_type' if needed
     2562        foreach ( $synced_post_comments['activities'] as $synced_post_comment ) {
     2563                if ( isset( $parent_activity_types[ $synced_post_comment->item_id ] ) ) {
     2564                        bp_activity_update_meta( $synced_post_comment->id, 'bp_parent_type', $parent_activity_types[ $synced_post_comment->item_id ] );
     2565                }
     2566        }
     2567}
     2568
     2569/**
    20472570 * Add an activity comment.
    20482571 *
    20492572 * @since 1.2.0
     2573 * @since 2.5.0 Add a new possible parameter $skip_notification for the array of arguments.
     2574 *              Add the $primary_link parameter for the array of arguments.
    20502575 *
    20512576 * @uses wp_parse_args()
    20522577 * @uses bp_activity_add()
    function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 
    20562581 * @uses do_action() To call the 'bp_activity_comment_posted' hook.
    20572582 *
    20582583 * @param array|string $args {
    2059  *     @type int    $id          Optional. Pass an ID to update an existing comment.
    2060  *     @type string $content     The content of the comment.
    2061  *     @type int    $user_id     Optional. The ID of the user making the comment.
    2062  *                               Defaults to the ID of the logged-in user.
    2063  *     @type int    $activity_id The ID of the "root" activity item, ie the oldest
    2064  *                               ancestor of the comment.
    2065  *     @type int    $parent_id   Optional. The ID of the parent activity item, ie the item to
    2066  *                               which the comment is an immediate reply. If not provided,
    2067  *                               this value defaults to the $activity_id.
     2584 *     @type int    $id                Optional. Pass an ID to update an existing comment.
     2585 *     @type string $content           The content of the comment.
     2586 *     @type int    $user_id           Optional. The ID of the user making the comment.
     2587 *                                     Defaults to the ID of the logged-in user.
     2588 *     @type int    $activity_id       The ID of the "root" activity item, ie the oldest
     2589 *                                     ancestor of the comment.
     2590 *     @type int    $parent_id         Optional. The ID of the parent activity item, ie the item to
     2591 *                                     which the comment is an immediate reply. If not provided,
     2592 *                                     this value defaults to the $activity_id.
     2593 *     @type string $primary_link      Optional. the primary link for the comment.
     2594 *                                     Defaults to an empty string.
     2595 *     @type bool   $skip_notification Optional. false to send a comment notification, false otherwise.
     2596 *                                     Defaults to false.
    20682597 * }
    20692598 * @return int|bool The ID of the comment on success, otherwise false.
    20702599 */
    function bp_activity_new_comment( $args = '' ) { 
    20782607        }
    20792608
    20802609        $r = wp_parse_args( $args, array(
    2081                 'id'          => false,
    2082                 'content'     => false,
    2083                 'user_id'     => bp_loggedin_user_id(),
    2084                 'activity_id' => false, // ID of the root activity item.
    2085                 'parent_id'   => false  // ID of a parent comment (optional).
     2610                'id'                => false,
     2611                'content'           => false,
     2612                'user_id'           => bp_loggedin_user_id(),
     2613                'activity_id'       => false, // ID of the root activity item.
     2614                'parent_id'         => false, // ID of a parent comment (optional).
     2615                'primary_link'      => '',
     2616                'skip_notification' => false,
    20862617        ) );
    20872618
    20882619        // Bail if missing necessary data.
    function bp_activity_new_comment( $args = '' ) { 
    21292660                'content'           => $comment_content,
    21302661                'component'         => buddypress()->activity->id,
    21312662                'type'              => 'activity_comment',
     2663                'primary_link'      => $r['primary_link'],
    21322664                'user_id'           => $r['user_id'],
    21332665                'item_id'           => $activity_id,
    21342666                'secondary_item_id' => $r['parent_id'],
    function bp_activity_new_comment( $args = '' ) { 
    21472679        }
    21482680        wp_cache_delete( $activity_id, 'bp_activity' );
    21492681
    2150         /**
    2151          * Fires near the end of an activity comment posting, before the returning of the comment ID.
    2152          *
    2153          * @since 1.2.0
    2154          *
    2155          * @param int                  $comment_id ID of the newly posted activity comment.
    2156          * @param array                $r          Array of parsed comment arguments.
    2157          * @param BP_Activity_Activity $activity   Activity item being commented on.
    2158          */
    2159         do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
     2682        if ( empty( $r[ 'skip_notification' ] ) ) {
     2683                /**
     2684                 * Fires near the end of an activity comment posting, before the returning of the comment ID.
     2685                 * Sends a notification to the user @see bp_activity_new_comment_notification_helper().
     2686                 *
     2687                 * @since 1.2.0
     2688                 *
     2689                 * @param int   $comment_id ID of the newly posted activity comment.
     2690                 * @param array $r          Array of parsed comment arguments.
     2691                 * @param int   $activity   ID of the activity item being commented on.
     2692                 */
     2693                do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
     2694        } else {
     2695                /**
     2696                 * Fires near the end of an activity comment posting, before the returning of the comment ID.
     2697                 * without sending a notification to the user
     2698                 *
     2699                 * @since 2.5.0
     2700                 *
     2701                 * @param int   $comment_id ID of the newly posted activity comment.
     2702                 * @param array $r          Array of parsed comment arguments.
     2703                 * @param int   $activity   ID of the activity item being commented on.
     2704                 */
     2705                do_action( 'bp_activity_comment_posted_notification_skipped', $comment_id, $r, $activity );
     2706        }
    21602707
    21612708        if ( empty( $comment_id ) ) {
    21622709                $errors->add( 'comment_failed', $feedback );
    function bp_activity_delete( $args = '' ) { 
    24252972 * @return bool True on success, false on failure.
    24262973 */
    24272974function bp_activity_delete_comment( $activity_id, $comment_id ) {
     2975        $deleted = false;
    24282976
    24292977        /**
    24302978         * Filters whether BuddyPress should delete an activity comment or not.
    function bp_activity_delete_comment( $activity_id, $comment_id ) { 
    24332981         * handle the deletion of child comments differently. Make sure you return false.
    24342982         *
    24352983         * @since 1.2.0
     2984         * @since 2.5.0 Add the deleted parameter (passed by reference)
    24362985         *
    24372986         * @param bool $value       Whether BuddyPress should continue or not.
    24382987         * @param int  $activity_id ID of the root activity item being deleted.
    24392988         * @param int  $comment_id  ID of the comment being deleted.
    24402989         */
    2441         if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) {
    2442                 return false;
     2990        if ( ! apply_filters_ref_array( 'bp_activity_delete_comment_pre', array( true, $activity_id, $comment_id, &$deleted ) ) ) {
     2991                return $deleted;
    24432992        }
    24442993
    24452994        // Delete any children of this comment.
    function bp_activity_delete_comment( $activity_id, $comment_id ) { 
    24482997        // Delete the actual comment.
    24492998        if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) {
    24502999                return false;
     3000        } else {
     3001                $deleted = true;
    24513002        }
    24523003
    24533004        // Purge comment cache for the root activity update.
    function bp_activity_delete_comment( $activity_id, $comment_id ) { 
    24663017         */
    24673018        do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
    24683019
    2469         return true;
     3020        return $deleted;
    24703021}
    24713022
    24723023        /**
  • src/bp-blogs/bp-blogs-activity.php

    diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php
    index af93731..7a39e3e 100644
    defined( 'ABSPATH' ) || exit; 
    1818 * @return bool|null Returns false if activity component is not active.
    1919 */
    2020function bp_blogs_register_activity_actions() {
    21         $bp = buddypress();
    22 
    23         // Bail if activity is not active.
    24         if ( ! bp_is_active( 'activity' ) ) {
    25                 return false;
    26         }
    27 
    2821        if ( is_multisite() ) {
    2922                bp_activity_set_action(
    30                         $bp->blogs->id,
     23                        buddypress()->blogs->id,
    3124                        'new_blog',
    3225                        __( 'New site created', 'buddypress' ),
    3326                        'bp_blogs_format_activity_action_new_blog',
    function bp_blogs_register_activity_actions() { 
    3730                );
    3831        }
    3932
    40         // Only add the comment type if the 'post' post type is trackable.
    41         if ( post_type_supports( 'post', 'buddypress-activity' ) ) {
    42                 bp_activity_set_action(
    43                         $bp->blogs->id,
    44                         'new_blog_comment',
    45                         __( 'New post comment posted', 'buddypress' ),
    46                         'bp_blogs_format_activity_action_new_blog_comment',
    47                         __( 'Comments', 'buddypress' ),
    48                         array( 'activity', 'member' ),
    49                         10
    50                 );
    51         }
    52 
    5333        /**
    5434         * Fires after the registry of the default blog component activity actions.
    5535         *
    function bp_blogs_register_activity_actions() { 
    6040add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
    6141
    6242/**
     43 * Set up the tracking arguments for the 'post' post type.
     44 *
     45 * @since 2.5.0 This was moved out of the BP_Blogs_Component class.
     46 *
     47 * @see bp_activity_get_post_type_tracking_args() for information on parameters.
     48 *
     49 * @param object|null $params    Tracking arguments.
     50 * @param string|int  $post_type Post type to track.
     51 * @return object
     52 */
     53function bp_blogs_register_post_tracking_args( $params = null, $post_type = 0 ) {
     54
     55        /**
     56         * Filters the post types to track for the Blogs component.
     57         *
     58         * @since 1.5.0
     59         * @deprecated 2.3.0
     60         *
     61         * Make sure plugins still using 'bp_blogs_record_post_post_types'
     62         * to track their post types will generate new_blog_post activities
     63         * See https://buddypress.trac.wordpress.org/ticket/6306
     64         *
     65         * @param array $value Array of post types to track.
     66         */
     67        $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
     68        $post_types_array = array_flip( $post_types );
     69
     70        if ( ! isset( $post_types_array[ $post_type ] ) ) {
     71                return $params;
     72        }
     73
     74        // Set specific params for the 'post' post type.
     75        $params->component_id    = buddypress()->blogs->id;
     76        $params->action_id       = 'new_blog_post';
     77        $params->admin_filter    = __( 'New post published', 'buddypress' );
     78        $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
     79        $params->front_filter    = __( 'Posts', 'buddypress' );
     80        $params->contexts        = array( 'activity', 'member' );
     81        $params->position        = 5;
     82
     83        if ( post_type_supports( $post_type, 'comments' ) ) {
     84                $params->comment_action_id = 'new_blog_comment';
     85
     86                /**
     87                 * Filters the post types to track for the Blogs component.
     88                 *
     89                 * @since 1.5.0
     90                 * @deprecated 2.5.0
     91                 *
     92                 * Make sure plugins still using 'bp_blogs_record_comment_post_types'
     93                 * to track comment about their post types will generate new_blog_comment activities
     94                 * See https://buddypress.trac.wordpress.org/ticket/6306
     95                 *
     96                 * @param array $value Array of post types to track.
     97                 */
     98                $comment_post_types = apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) );
     99                $comment_post_types_array = array_flip( $comment_post_types );
     100
     101                if ( isset( $comment_post_types_array[ $post_type ] ) ) {
     102                        $params->comments_tracking = new stdClass();
     103                        $params->comments_tracking->component_id    = buddypress()->blogs->id;
     104                        $params->comments_tracking->action_id       = 'new_blog_comment';
     105                        $params->comments_tracking->admin_filter    = __( 'New post comment posted', 'buddypress' );
     106                        $params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment';
     107                        $params->comments_tracking->front_filter    = __( 'Comments', 'buddypress' );
     108                        $params->comments_tracking->contexts        = array( 'activity', 'member' );
     109                        $params->comments_tracking->position        = 10;
     110                }
     111        }
     112
     113        return $params;
     114}
     115add_filter( 'bp_activity_get_post_type_tracking_args', 'bp_blogs_register_post_tracking_args', 10, 2 );
     116
     117/**
    63118 * Format 'new_blog' activity actions.
    64119 *
    65120 * @since 2.0.0
    function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) { 
    218273 * @return string Constructed activity action.
    219274 */
    220275function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) {
    221         $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
    222         $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     276        /**
     277         * When the comment is published we are faking an activity object
     278         * to which we add 4 properties :
     279         * - the post url
     280         * - the post title
     281         * - the blog url
     282         * - the blog name
     283         * This is done to build the 'post link' part of the activity
     284         * action string.
     285         * NB: in this case the activity has not yet been created.
     286         */
     287
     288        $blog_url = false;
     289
     290        // Try to get the blog url from the activity object
     291        if ( isset( $activity->blog_url ) ) {
     292                $blog_url = $activity->blog_url;
     293        } else {
     294                $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     295        }
     296
     297        $blog_name = false;
     298
     299        // Try to get the blog name from the activity object
     300        if ( isset( $activity->blog_name ) ) {
     301                $blog_name = $activity->blog_name;
     302        } else {
     303                $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     304        }
    223305
    224306        if ( empty( $blog_url ) || empty( $blog_name ) ) {
    225307                $blog_url  = get_home_url( $activity->item_id );
    function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) 
    229311                bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
    230312        }
    231313
    232         $post_url   = bp_activity_get_meta( $activity->id, 'post_url' );
    233         $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     314        $post_url = false;
     315
     316        // Try to get the post url from the activity object
     317        if ( isset( $activity->post_url ) ) {
     318                $post_url = $activity->post_url;
     319
     320        /**
     321         * The post_url property is not set, we need to build the url
     322         * thanks to the post id which is also saved as the secondary
     323         * item id property of the activity object.
     324         */
     325        } elseif ( ! empty( $activity->id ) ) {
     326                $post_url = bp_activity_get_meta( $activity->id, 'post_url' );
     327        }
     328
     329        $post_title = false;
     330
     331        // Should be the case when the comment has just been published
     332        if ( isset( $activity->post_title ) ) {
     333                $post_title = $activity->post_title;
     334
     335        // If activity already exists try to get the post title from activity meta
     336        } elseif ( ! empty( $activity->id ) ) {
     337                $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     338        }
    234339
    235340        // Should only be empty at the time of post creation.
    236341        if ( empty( $post_url ) || empty( $post_title ) ) {
    add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_obje 
    333438 * @return int|bool On success, returns the activity ID. False on failure.
    334439 */
    335440function bp_blogs_record_activity( $args = '' ) {
    336 
    337         // Bail if activity is not active.
    338         if ( ! bp_is_active( 'activity' ) ) {
    339                 return false;
    340         }
    341 
    342         $bp = buddypress();
    343 
    344441        $defaults = array(
    345442                'user_id'           => bp_loggedin_user_id(),
    346443                'action'            => '',
    347444                'content'           => '',
    348445                'primary_link'      => '',
    349                 'component'         => $bp->blogs->id,
     446                'component'         => buddypress()->blogs->id,
    350447                'type'              => false,
    351448                'item_id'           => false,
    352449                'secondary_item_id' => false,
    function bp_blogs_record_activity( $args = '' ) { 
    410507 * @return bool True on success, false on failure.
    411508 */
    412509function bp_blogs_delete_activity( $args = '' ) {
    413 
    414         // Bail if activity is not active.
    415         if ( ! bp_is_active( 'activity' ) ) {
    416                 return false;
    417         }
    418 
    419510        $r = bp_parse_args( $args, array(
    420511                'item_id'           => false,
    421512                'component'         => buddypress()->blogs->id,
    function bp_blogs_comments_open( $activity ) { 
    522613 *
    523614 * Note: This is only a one-way sync - activity comments -> blog comment.
    524615 *
    525  * For blog post -> activity comment, see {@link bp_blogs_record_comment()}.
     616 * For blog post -> activity comment, see {@link bp_activity_post_type_comment()}.
    526617 *
    527618 * @since 2.0.0
     619 * @since 2.5.0 Allow custom post types to sync their comments with activity ones
    528620 *
    529621 * @param int    $comment_id      The activity ID for the posted activity comment.
    530622 * @param array  $params          Parameters for the activity comment.
    531623 * @param object $parent_activity Parameters of the parent activity item (in this case, the blog post).
    532624 */
    533625function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
    534         // If parent activity isn't a blog post, stop now!
    535         if ( $parent_activity->type != 'new_blog_post' ) {
     626        // if parent activity isn't a post type having the buddypress-activity support, stop now!
     627        if ( ! bp_activity_post_type_supports( $parent_activity->type, 'comment-tracking' ) ) {
    536628                return;
    537629        }
    538630
    function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 
    565657                'comment_type'         => '', // Could be interesting to add 'buddypress' here...
    566658                'comment_parent'       => (int) $comment_parent,
    567659                'user_id'              => $params['user_id'],
    568 
    569                 // Commenting these out for now
    570                 // 'comment_author_IP'    => '127.0.0.1',
    571                 // 'comment_agent'        => '', .
    572660                'comment_approved'     => 1
    573661        );
    574662
    575663        // Prevent separate activity entry being made.
    576         remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     664        remove_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 );
    577665
    578666        // Handle multisite.
    579667        switch_to_blog( $parent_activity->item_id );
    function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 
    590678
    591679        // Add meta to activity comment.
    592680        bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id );
     681        bp_activity_update_meta( $comment_id, 'bp_parent_type', $parent_activity->type );
    593682
    594683        // Resave activity comment with WP comment permalink.
    595684        //
    function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 
    616705        restore_current_blog();
    617706
    618707        // Add the comment hook back.
    619         add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     708        add_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 );
    620709
    621710        /**
    622711         * Fires after activity comments have been synced and posted as blog comments.
    add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comme 
    640729 * activity comment children before they are deleted.
    641730 *
    642731 * @since 2.0.0
     732 * @since 2.5.0 Add the $delected parameter
    643733 *
    644734 * @param bool $retval             Whether BuddyPress should continue or not.
    645735 * @param int  $parent_activity_id The parent activity ID for the activity comment.
    646736 * @param int  $activity_id        The activity ID for the pending deleted activity comment.
     737 * @param bool $deleted            Whether the comment was deleted or not.
    647738 * @return bool
    648739 */
    649 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
     740function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id, &$deleted ) {
    650741        // Check if parent activity is a blog post.
    651742        $parent_activity = new BP_Activity_Activity( $parent_activity_id );
    652         if ( 'new_blog_post' != $parent_activity->type ) {
     743
     744        // if parent activity isn't a post type having the buddypress-activity support, stop now!
     745        if ( ! bp_activity_post_type_supports( $parent_activity->type, 'comment-tracking' ) ) {
    653746                return $retval;
    654747        }
    655748
    function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_i 
    657750        $activity = bp_activity_get( array(
    658751                'in'               => $activity_id,
    659752                'display_comments' => 'stream',
     753                'spam'             => 'all',
    660754        ) );
    661755
    662756        // Get all activity comment IDs for the pending deleted item.
    function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_i 
    677771        // emulate bp_activity_delete_comment().
    678772        BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id );
    679773
     774        // Avoid the error message although the comments were successfully deleted
     775        $deleted = true;
     776
    680777        // We're overriding the default bp_activity_delete_comment() functionality
    681778        // so we need to return false.
    682779        return false;
    683780}
    684 add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 3 );
     781add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 4 );
    685782
    686783/**
    687784 * Updates the blog comment when the associated activity comment is edited.
    add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activit 
    691788 * @param BP_Activity_Activity $activity The activity object.
    692789 */
    693790function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) {
    694         // Not an activity comment? stop now!
    695         if ( 'activity_comment' !== $activity->type ) {
    696                 return;
    697         }
    698 
    699791        // This is a new entry, so stop!
    700792        // We only want edits!
    701         if ( empty( $activity->id ) ) {
     793        if ( empty( $activity->id ) || bp_disable_blogforum_comments() ) {
    702794                return;
    703795        }
    704796
    705         // Prevent recursion.
    706         remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
     797        // fetch parent activity item
     798        $parent_activity = new BP_Activity_Activity( $activity->item_id );
     799
     800        // if parent activity isn't a post type having the buddypress-activity support for comments, stop now!
     801        if ( ! bp_activity_post_type_supports( $parent_activity->type, 'comment-tracking' ) ) {
     802                return;
     803        }
    707804
    708805        // Try to see if a corresponding blog comment exists.
    709806        $post_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' );
    function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $acti 
    712809                return;
    713810        }
    714811
    715         // Fetch parent activity item.
    716         $parent_activity = new BP_Activity_Activity( $activity->item_id );
     812        // Get the parent type
     813        $parent_type = bp_activity_get_meta( $activity->id, 'bp_parent_type' );
    717814
    718815        // Sanity check.
    719         if ( 'new_blog_post' !== $parent_activity->type ) {
     816        if ( $parent_type !== $parent_activity->type ) {
    720817                return;
    721818        }
    722819
    723820        // Handle multisite.
    724821        switch_to_blog( $parent_activity->item_id );
    725822
    726         // Update the blog post comment.
    727         wp_update_comment( array(
    728                 'comment_ID'      => $post_comment_id,
    729                 'comment_content' => $activity->content
    730         ) );
     823        // Get the comment status
     824        $post_comment_status = wp_get_comment_status( $post_comment_id );
     825        $old_comment_status  = $post_comment_status;
     826
     827        // No need to edit the activity, as it's the activity who's updating the comment
     828        remove_action( 'transition_comment_status',     'bp_activity_transition_post_type_comment_status', 10, 3 );
     829        remove_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment',          10, 4 );
     830
     831        if ( 1 === (int) $activity->is_spam && 'spam' !== $post_comment_status ) {
     832                wp_spam_comment( $post_comment_id );
     833        } elseif ( ! $activity->is_spam ) {
     834                if ( 'spam' === $post_comment_status  ) {
     835                        wp_unspam_comment( $post_comment_id );
     836                } elseif ( 'trash' === $post_comment_status ) {
     837                        wp_untrash_comment( $post_comment_id );
     838                } else {
     839                        // Update the blog post comment.
     840                        wp_update_comment( array(
     841                                'comment_ID'       => $post_comment_id,
     842                                'comment_content'  => $activity->content,
     843                        ) );
     844                }
     845        }
     846
     847        // Restore actions
     848        add_action( 'transition_comment_status',     'bp_activity_transition_post_type_comment_status', 10, 3 );
     849        add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment',          10, 4 );
    731850
    732851        restore_current_blog();
    733852}
    add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_ 
    769888 * powers the 'Comments' filter in the activity directory dropdown) includes
    770889 * both old-style and new-style activity comments.
    771890 *
    772  * This implementation involves filtering the activity queries directly, and
    773  * should be considered a stopgap. The proper solution would involve enabling
    774  * multiple query condition clauses, connected by an OR, in the bp_has_activities()
    775  * API.
    776  *
    777891 * @since 2.1.0
     892 * @since 2.5.0 Used for any synced Post type comments, in wp-admin or front-end contexts.
    778893 *
    779894 * @param array $args Arguments passed from bp_parse_args() in bp_has_activities().
    780895 * @return array $args
    function bp_blogs_new_blog_comment_query_backpat( $args ) { 
    783898        global $wpdb;
    784899        $bp = buddypress();
    785900
    786         // Bail if this is not a 'new_blog_comment' query.
    787         if ( 'new_blog_comment' !== $args['action'] ) {
     901        // If activity comments are disabled for blog posts, stop now!
     902        if ( bp_disable_blogforum_comments() ) {
     903                return $args;
     904        }
     905
     906        // Get the parent type
     907        $parent_type = bp_activity_post_type_get_parent_type( $args['action'] );
     908
     909        // Bail if this is not a 'new_blog_comment' query
     910        if ( empty( $parent_type->action_id ) ) {
    788911                return $args;
    789912        }
    790913
    791914        // Comment synced ?
    792         $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' ) );
     915        $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = 'bp_parent_type' AND meta_value = %s", $parent_type->action_id ) );
    793916
    794917        if ( empty( $activity_ids ) ) {
    795918                return $args;
    function bp_blogs_new_blog_comment_query_backpat( $args ) { 
    798921        // Init the filter query.
    799922        $filter_query = array();
    800923
    801         if ( 'null' === $args['scope'] ) {
     924        if ( ! isset( $args['scope'] ) || 'null' === $args['scope'] ) {
    802925                $args['scope'] = '';
    803926        } elseif ( 'just-me' === $args['scope'] ) {
    804927                $filter_query = array(
    function bp_blogs_new_blog_comment_query_backpat( $args ) { 
    831954
    832955        // Finally reset the action.
    833956        $args['action'] = '';
     957        $args['type']   = '';
    834958
    835959        // Return the original arguments.
    836960        return $args;
    837961}
    838 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' );
     962add_filter( 'bp_after_has_activities_parse_args',                'bp_blogs_new_blog_comment_query_backpat' );
     963add_filter( 'bp_activity_list_table_filter_activity_type_items', 'bp_blogs_new_blog_comment_query_backpat' );
    839964
    840965/**
    841966 * Utility function to set up some variables for use in the activity loop.
    function bp_blogs_setup_activity_loop_globals( $activity ) { 
    857982                return;
    858983        }
    859984
    860         // Parent not a blog post? stop now!
    861         if ( 'new_blog_post' !== $activity->type ) {
     985        // The activity type does not support comments or replies ? stop now!
     986        if ( ! bp_activity_post_type_supports( $activity->type, 'comment-reply' ) ) {
    862987                return;
    863988        }
    864989
    function bp_blogs_disable_activity_commenting( $retval ) { 
    9401065                return $retval;
    9411066        }
    9421067
    943         // Activity commenting is enabled for blog posts.
    944         switch ( bp_get_activity_action_name() ) {
    945 
    946                 // We still have to disable activity commenting for 'new_blog_comment' items
    947                 // commenting should only be done on the parent 'new_blog_post' item.
    948                 case 'new_blog_comment' :
    949                         $retval = false;
    950 
    951                         break;
     1068        $type = bp_get_activity_type();
    9521069
    953                 // Check if commenting is disabled for the WP blog post
    954                 // we should extrapolate this and automate this for plugins... or not.
    955                 case 'new_blog_post' :
     1070        // It's a post type supporting comment tracking.
     1071        if ( bp_activity_post_type_supports( $type, 'comment-tracking' ) ) {
     1072                // The activity type is supporting comments or replies
     1073                if ( bp_activity_post_type_supports( $type, 'comment-reply' ) ) {
    9561074                        global $activities_template;
    9571075
    9581076                        // Setup some globals we'll need to reference later.
    function bp_blogs_disable_activity_commenting( $retval ) { 
    9601078
    9611079                        // If comments are closed for the WP blog post, we should disable
    9621080                        // activity comments for this activity entry.
    963                         if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) {
     1081                        if ( empty( buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) ) {
    9641082                                $retval = false;
    9651083                        }
    966 
    967                         break;
     1084                // The activity type does not support comments or replies
     1085                } else {
     1086                        $retval = false;
     1087                }
    9681088        }
    9691089
    9701090        return $retval;
    function bp_blogs_disable_activity_commenting( $retval ) { 
    9721092add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' );
    9731093
    9741094/**
     1095 * Limit the display of post type synced comments.
     1096 *
     1097 * @since  2.5.0
     1098 *
     1099 * When viewing the synced comments in stream mode, this prevents comments to
     1100 * be displayed twice, and avoids a Javascript error as the form to add replies
     1101 * is not available.
     1102 *
     1103 * @param  int $retval  The comment count for the activity.
     1104 * @return int          The comment count, or 0 to hide activity comment replies.
     1105 */
     1106function bp_blogs_post_type_comments_avoid_duplicates( $retval ) {
     1107        /**
     1108         * Only limit the display when Post type comments are synced with
     1109         * activity comments.
     1110         */
     1111        if ( bp_disable_blogforum_comments() ) {
     1112                return $retval;
     1113        }
     1114
     1115        if ( 'activity_comment' !== bp_get_activity_type() ) {
     1116                return $retval;
     1117        }
     1118
     1119        if ( true === (bool) bp_activity_get_meta( bp_get_activity_id(), 'bp_blogs_post_comment_id' ) ) {
     1120                $retval = 0;
     1121        }
     1122
     1123        return $retval;
     1124}
     1125add_filter( 'bp_activity_get_comment_count', 'bp_blogs_post_type_comments_avoid_duplicates' );
     1126
     1127/**
    9751128 * Check if an activity comment associated with a blog post can be replied to.
    9761129 *
    9771130 * By default, disables replying to activity comments if the corresponding WP
    function bp_blogs_activity_comment_single_action( $retval, $activity ) { 
    10861239        $blog_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' );
    10871240
    10881241        if ( ! empty( $blog_comment_id ) ) {
     1242                $bp = buddypress();
     1243
    10891244                // Fetch the parent blog post activity item.
    10901245                $parent_blog_post_activity = new BP_Activity_Activity( $activity->item_id );
    10911246
    function bp_blogs_activity_comment_single_action( $retval, $activity ) { 
    10981253                // Override 'secondary_item_id' to use comment ID.
    10991254                $object->secondary_item_id = $blog_comment_id;
    11001255
    1101                 // Now format the activity action using the 'new_blog_comment' action callback.
    1102                 $retval = bp_blogs_format_activity_action_new_blog_comment( '', $object );
     1256                // Set the activity track global if not set yet
     1257                if ( empty( $bp->activity->track ) ) {
     1258                        $bp->activity->track = bp_activity_get_post_types_tracking_args();
     1259                }
     1260
     1261                // Use the action string callback for the activity type
     1262                if ( ! empty( $bp->activity->track[ $parent_blog_post_activity->type ]->comment_action_id ) ) {
     1263                        $object->type = $bp->activity->track[ $parent_blog_post_activity->type ]->comment_action_id;
     1264
     1265                        // now format the activity action using the 'new_blog_comment' action callback
     1266                        $retval = call_user_func_array( $bp->activity->track[ $object->type ]->format_callback, array( '', $object ) );
     1267
     1268                        /**
     1269                         * Reset the activity type to 'activity_comment'
     1270                         * so that the "View Conversation" button appears
     1271                         */
     1272                        $object->type = 'activity_comment';
     1273                }
    11031274        }
    11041275
    11051276        return $retval;
  • src/bp-blogs/bp-blogs-filters.php

    diff --git src/bp-blogs/bp-blogs-filters.php src/bp-blogs/bp-blogs-filters.php
    index 5cb6a2f..bfd96f0 100644
    function bp_blogs_comments_clauses_select_by_id( $retval ) { 
    6161}
    6262
    6363/**
    64  * Check whether the current post can be published.
     64 * Check whether the current activity about a post or a comment can be published.
    6565 *
    6666 * Abstracted from the deprecated `bp_blogs_record_post()`.
    6767 *
    function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, 
    121121        return $return;
    122122}
    123123add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 );
     124add_filter( 'bp_activity_post_pre_comment', 'bp_blogs_post_pre_publish', 10, 4 );
  • src/bp-blogs/bp-blogs-functions.php

    diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php
    index 02e3477..cdfbf03 100644
    add_action( 'bp_activity_post_type_published', 'bp_blogs_publish_post_activity_m 
    477477 * Updates a blog post's activity meta entry during a post edit.
    478478 *
    479479 * @since 2.2.0
     480 * @since 2.5.0 Add the post type tracking args object parameter
    480481 *
    481  * @param WP_Post              $post     Post object.
    482  * @param BP_Activity_Activity $activity Activity object.
     482 * @param WP_Post              $post                 Post object.
     483 * @param BP_Activity_Activity $activity             Activity object.
     484 * @param object               $activity_post_object The post type tracking args object.
    483485 */
    484 function bp_blogs_update_post_activity_meta( $post, $activity ) {
    485         if ( empty( $activity->id ) || 'post' != $post->post_type ) {
     486function bp_blogs_update_post_activity_meta( $post, $activity, $activity_post_object ) {
     487        if ( empty( $activity->id ) || empty( $activity_post_object->action_id ) ) {
    486488                return;
    487489        }
    488490
    function bp_blogs_update_post_activity_meta( $post, $activity ) { 
    491493        if ( $post->post_title !== $existing_title ) {
    492494                bp_activity_update_meta( $activity->id, 'post_title', $post->post_title );
    493495
    494                 // Now update activity meta for post comments... sigh.
    495                 add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
    496                 $comments = get_comments( array( 'post_id' => $post->ID ) );
    497                 remove_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
    498 
    499                 if ( ! empty( $comments ) ) {
    500                         $activity_ids = array();
    501                         $comment_ids  = wp_list_pluck( $comments, 'comment_ID' );
    502 
    503                         // Set up activity args.
    504                         $args = array(
    505                                 'update_meta_cache' => false,
    506                                 'show_hidden'       => true,
    507                                 'per_page'          => 99999,
    508                         );
    509 
    510                         // Query for old-style "new_blog_comment" activity items.
    511                         $args['filter'] = array(
    512                                 'object'       => buddypress()->blogs->id,
    513                                 'action'       => 'new_blog_comment',
    514                                 'secondary_id' => implode( ',', $comment_ids ),
    515                         );
    516 
    517                         $activities = bp_activity_get( $args );
    518                         if ( ! empty( $activities['activities'] ) ) {
    519                                 $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' );
    520                         }
    521 
    522                         // Query for activity comments connected to a blog post.
    523                         unset( $args['filter'] );
    524                         $args['meta_query'] = array( array(
    525                                 'key'     => 'bp_blogs_post_comment_id',
    526                                 'value'   => $comment_ids,
    527                                 'compare' => 'IN',
    528                         ) );
    529                         $args['type'] = 'activity_comment';
    530                         $args['display_comments'] = 'stream';
     496                if ( ! empty( $activity_post_object->comments_tracking->action_id ) ) {
     497                        // Now update activity meta for post comments... sigh.
     498                        add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
     499                        $comments = get_comments( array( 'post_id' => $post->ID ) );
     500                        remove_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
     501
     502                        if ( ! empty( $comments ) ) {
     503                                $activity_ids = array();
     504                                $comment_ids  = wp_list_pluck( $comments, 'comment_ID' );
     505
     506                                // Set up activity args.
     507                                $args = array(
     508                                        'update_meta_cache' => false,
     509                                        'show_hidden'       => true,
     510                                        'per_page'          => 99999,
     511                                );
     512
     513                                // Query for old-style "new_blog_comment" activity items.
     514                                $args['filter'] = array(
     515                                        'object'       => $activity_post_object->comments_tracking->component_id,
     516                                        'action'       => $activity_post_object->comments_tracking->action_id,
     517                                        'secondary_id' => implode( ',', $comment_ids ),
     518                                );
     519
     520                                $activities = bp_activity_get( $args );
     521                                if ( ! empty( $activities['activities'] ) ) {
     522                                        $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' );
     523                                }
    531524
    532                         $activities = bp_activity_get( $args );
    533                         if ( ! empty( $activities['activities'] ) ) {
    534                                 $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) );
    535                         }
     525                                // Query for activity comments connected to a blog post.
     526                                unset( $args['filter'] );
     527                                $args['meta_query'] = array( array(
     528                                        'key'     => 'bp_blogs_post_comment_id',
     529                                        'value'   => $comment_ids,
     530                                        'compare' => 'IN',
     531                                ) );
     532                                $args['type'] = 'activity_comment';
     533                                $args['display_comments'] = 'stream';
     534
     535                                $activities = bp_activity_get( $args );
     536                                if ( ! empty( $activities['activities'] ) ) {
     537                                        $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) );
     538                                }
    536539
    537                         // Update activity meta for all found activity items.
    538                         if ( ! empty( $activity_ids ) ) {
    539                                 foreach ( $activity_ids as $aid ) {
    540                                         bp_activity_update_meta( $aid, 'post_title', $post->post_title );
     540                                // Update activity meta for all found activity items.
     541                                if ( ! empty( $activity_ids ) ) {
     542                                        foreach ( $activity_ids as $aid ) {
     543                                                bp_activity_update_meta( $aid, 'post_title', $post->post_title );
     544                                        }
    541545                                }
    542                         }
    543546
    544                         unset( $activities, $activity_ids, $comment_ids, $comments );
     547                                unset( $activities, $activity_ids, $comment_ids, $comments );
     548                        }
    545549                }
    546550        }
    547551
    function bp_blogs_update_post_activity_meta( $post, $activity ) { 
    552556                bp_activity_delete_meta( $activity->id, 'post_comment_status' );
    553557        }
    554558}
    555 add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 2 );
     559add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 3 );
    556560
    557561/**
    558  * Record a new blog comment in the BuddyPress activity stream.
     562 * Update Activity and blogs meta and eventually sync comment with activity comment
    559563 *
    560  * Only posts the item if blog is public and post is not password-protected.
     564 * @since  2.5.0
    561565 *
    562  * @param int         $comment_id  ID of the comment being recorded.
    563  * @param bool|string $is_approved Optional. The $is_approved value passed to
    564  *                                 the 'comment_post' action. Default: true.
    565  * @return bool|object Returns false on failure, the comment object on success.
     566 * @param  int|bool   $activity_id          ID of recorded activity, or false if sync is active.
     567 * @param  WP_Comment $comment              The comment object.
     568 * @param  array      $activity_args        Array of activity arguments.
     569 * @param  object     $activity_post_object The post type tracking args object.
     570 * @return int|bool   Returns false if no activity, the activity id otherwise.
    566571 */
    567 function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    568         // Bail if activity component is not active.
    569         if ( ! bp_is_active( 'activity' ) ) {
    570                 return;
    571         }
    572 
    573         // Get the users comment.
    574         $recorded_comment = get_comment( $comment_id );
    575 
    576         // Don't record activity if the comment hasn't been approved.
    577         if ( empty( $is_approved ) )
     572function bp_blogs_comment_sync_activity_comment( &$activity_id, $comment = null, $activity_args = array(), $activity_post_object = null ) {
     573        if ( empty( $activity_args ) || empty( $comment->post->ID ) || empty( $activity_post_object->comment_action_id ) ) {
    578574                return false;
     575        }
    579576
    580         // Don't record activity if no email address has been included.
    581         if ( empty( $recorded_comment->comment_author_email ) )
    582                 return false;
    583 
    584         // Don't record activity if the comment has already been marked as spam.
    585         if ( 'spam' === $is_approved )
    586                 return false;
    587 
    588         // Get the user by the comment author email.
    589         $user = get_user_by( 'email', $recorded_comment->comment_author_email );
    590 
    591         // If user isn't registered, don't record activity.
    592         if ( empty( $user ) )
    593                 return false;
    594 
    595         // Get the user_id.
    596         $user_id = (int) $user->ID;
    597 
    598         // Get blog and post data.
     577        // Set the current blog id.
    599578        $blog_id = get_current_blog_id();
    600579
    601         // If blog is not trackable, do not record the activity.
    602         if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) )
    603                 return false;
    604 
    605         $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
    606 
    607         if ( empty( $recorded_comment->post ) || is_wp_error( $recorded_comment->post ) )
    608                 return false;
    609 
    610         // If this is a password protected post, don't record the comment.
    611         if ( !empty( $recorded_comment->post->post_password ) )
    612                 return false;
    613 
    614         // Don't record activity if the comment's associated post isn't a WordPress Post.
    615         if ( !in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ) ) )
    616                 return false;
    617 
    618         $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
    619 
    620         // If blog is public allow activity to be posted.
    621         if ( $is_blog_public ) {
    622 
    623                 // Get activity related links.
    624                 $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
    625                 $comment_link   = get_comment_link( $recorded_comment->comment_ID );
    626 
    627                 // Setup activity args.
    628                 $args = array();
    629 
    630                 $args['user_id']       = $user_id;
    631                 $args['content']       = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $recorded_comment->comment_content, &$recorded_comment, $comment_link ) );
    632                 $args['primary_link']  = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment ) );
    633                 $args['recorded_time'] = $recorded_comment->comment_date_gmt;
    634 
    635                 // Setup some different activity args depending if activity commenting is
    636                 // enabled or not.
    637                 // if cannot comment, record separate activity entry
    638                 // this is the old way of doing things.
    639                 if ( bp_disable_blogforum_comments() ) {
    640                         $args['type']              = 'new_blog_comment';
    641                         $args['item_id']           = $blog_id;
    642                         $args['secondary_item_id'] = $comment_id;
     580        // These activity metadatas are used to build the new_blog_comment action string
     581        if ( ! empty( $activity_id ) && ! empty( $activity_args['item_id'] ) && 'new_blog_comment' === $activity_post_object->comment_action_id ) {
     582                // add some post info in activity meta
     583                bp_activity_update_meta( $activity_id, 'post_title', $comment->post->post_title );
     584                bp_activity_update_meta( $activity_id, 'post_url',   esc_url_raw( add_query_arg( 'p', $comment->post->ID, home_url( '/' ) ) ) );
     585        }
    643586
    644                         // Record the activity entry.
    645                         $activity_id = bp_blogs_record_activity( $args );
     587        // Sync comment - activity comment
     588        if ( ! bp_disable_blogforum_comments() ) {
    646589
    647                         // Add some post info in activity meta.
    648                         bp_activity_update_meta( $activity_id, 'post_title', $recorded_comment->post->post_title );
    649                         bp_activity_update_meta( $activity_id, 'post_url',   add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) );
     590                if ( ! empty( $_REQUEST['action'] ) ) {
     591                        $existing_activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
    650592
    651                 // Record comment as BP activity comment under the parent 'new_blog_post'
    652                 // activity item.
    653                 } else {
    654                         // This is a comment edit
    655                         // check to see if corresponding activity entry already exists.
    656                         if ( ! empty( $_REQUEST['action'] ) ) {
    657                                 $existing_activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true );
    658 
    659                                 if ( ! empty( $existing_activity_id ) ) {
    660                                         $args['id'] = $existing_activity_id;
    661                                 }
     593                        if ( ! empty( $existing_activity_id ) ) {
     594                                $activity_args['id'] = $existing_activity_id;
    662595                        }
     596                }
    663597
    664                         // Find the parent 'new_blog_post' activity entry.
     598                if ( empty( $activity_post_object ) ) {
     599                        $activity_post_object = bp_activity_get_post_type_tracking_args( $comment->post->post_type );
     600                }
     601
     602                if ( isset( $activity_post_object->action_id ) && isset( $activity_post_object->component_id ) ) {
     603                        // find the parent 'new_post_type' activity entry
    665604                        $parent_activity_id = bp_activity_get_activity_id( array(
    666                                 'component'         => 'blogs',
    667                                 'type'              => 'new_blog_post',
     605                                'component'         => $activity_post_object->component_id,
     606                                'type'              => $activity_post_object->action_id,
    668607                                'item_id'           => $blog_id,
    669                                 'secondary_item_id' => $recorded_comment->comment_post_ID
     608                                'secondary_item_id' => $comment->comment_post_ID
    670609                        ) );
    671610
    672611                        // Try to create a new activity item for the parent blog post.
    673612                        if ( empty( $parent_activity_id ) ) {
    674                                 $parent_activity_id = bp_activity_post_type_publish( $recorded_comment->comment_post_ID, $recorded_comment->post );
     613                                $parent_activity_id = bp_activity_post_type_publish( $comment->post->ID, $comment->post );
    675614                        }
     615                }
    676616
    677                         // We found the parent activity entry
    678                         // so let's go ahead and reconfigure some activity args.
    679                         if ( ! empty( $parent_activity_id ) ) {
    680                                 // Set the 'item_id' with the parent activity entry ID.
    681                                 $args['item_id'] = $parent_activity_id;
     617                // we found the parent activity entry
     618                // so let's go ahead and reconfigure some activity args
     619                if ( ! empty( $parent_activity_id ) ) {
     620                        // set the parent activity entry ID
     621                        $activity_args['activity_id'] = $parent_activity_id;
    682622
    683                                 // Now see if the WP parent comment has a BP activity ID.
    684                                 $comment_parent = 0;
    685                                 if ( ! empty( $recorded_comment->comment_parent ) ) {
    686                                         $comment_parent = get_comment_meta( $recorded_comment->comment_parent, 'bp_activity_comment_id', true );
    687                                 }
     623                        // now see if the WP parent comment has a BP activity ID
     624                        $comment_parent = 0;
     625                        if ( ! empty( $comment->comment_parent ) ) {
     626                                $comment_parent = get_comment_meta( $comment->comment_parent, 'bp_activity_comment_id', true );
     627                        }
    688628
    689                                 // WP parent comment does not have a BP activity ID
    690                                 // so set to 'new_blog_post' activity ID.
    691                                 if ( empty( $comment_parent ) ) {
    692                                         $comment_parent = $parent_activity_id;
    693                                 }
     629                        // WP parent comment does not have a BP activity ID
     630                        // so set to 'new_' . post_type activity ID
     631                        if ( empty( $comment_parent ) ) {
     632                                $comment_parent = $parent_activity_id;
     633                        }
    694634
    695                                 $args['secondary_item_id'] = $comment_parent;
    696                                 $args['component']         = 'activity';
    697                                 $args['type']              = 'activity_comment';
     635                        $activity_args['parent_id']         = $comment_parent;
     636                        $activity_args['skip_notification'] = true;
    698637
    699                         // Could not find corresponding parent activity entry
    700                         // so wipe out $args array.
    701                         } else {
    702                                 $args = array();
    703                         }
     638                // could not find corresponding parent activity entry
     639                // so wipe out $args array
     640                } else {
     641                        $activity_args = array();
     642                }
    704643
    705                         // Record in activity streams.
    706                         if ( ! empty( $args ) ) {
    707                                 // @todo should we use bp_activity_new_comment()? that function will also send
    708                                 // an email to people in the activity comment thread.
    709                                 //
    710                                 // What if a site already has some comment email notification plugin setup?
    711                                 // this is why I decided to go with bp_activity_add() to avoid any conflict
    712                                 // with existing comment email notification plugins.
    713                                 $comment_activity_id = bp_activity_add( $args );
    714 
    715                                 if ( empty( $args['id'] ) ) {
    716                                         // Add meta to activity comment.
    717                                         bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id );
    718                                         bp_activity_update_meta( $comment_activity_id, 'post_title', $recorded_comment->post->post_title );
    719                                         bp_activity_update_meta( $comment_activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) );
    720 
    721                                         // Add meta to comment.
    722                                         add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id );
     644                // Record in activity streams
     645                if ( ! empty( $activity_args ) ) {
     646                        $activity_id = bp_activity_new_comment( $activity_args );
     647
     648                        if ( empty( $activity_args['id'] ) ) {
     649                                // The activity metadata to inform about the corresponding comment ID
     650                                bp_activity_update_meta( $activity_id, 'bp_blogs_post_comment_id', $comment->comment_ID );
     651
     652                                /**
     653                                 * The activity metadata to inform about the "parent" type
     654                                 * eg: the "parent" type for new_blog_comment is new_blog_post
     655                                 *
     656                                 * This is used to make sure filtering the activities using the new_{post_type}_comment type
     657                                 * will fetch all new_{post_type}_comment activities & activity_comment activities belonging to
     658                                 * the new_{post_type} parent activity
     659                                 */
     660                                bp_activity_update_meta( $activity_id, 'bp_parent_type', $activity_post_object->action_id );
     661
     662                                // The comment metadata to inform about the corresponding activity ID
     663                                add_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', $activity_id );
     664
     665                                // These activity metadatas are used to build the new_blog_comment action string
     666                                if ( 'new_blog_comment' === $activity_post_object->comment_action_id ) {
     667                                        bp_activity_update_meta( $activity_id, 'post_title', $comment->post->post_title );
     668                                        bp_activity_update_meta( $activity_id, 'post_url', esc_url_raw( add_query_arg( 'p', $comment->post->ID, home_url( '/' ) ) ) );
    723669                                }
    724670                        }
    725671                }
     672        }
    726673
    727                 // Update the blogs last active date.
    728                 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     674        // Update the blogs last active date
     675        bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     676
     677        if ( 'new_blog_comment' === $activity_post_object->comment_action_id ) {
     678                /**
     679                 * Fires after BuddyPress has recorded metadata about a published blog post comment.
     680                 *
     681                 * @since 2.5.0
     682                 *
     683                 * @param int     $value    Comment ID of the blog post comment being recorded.
     684                 * @param WP_Post $post  WP_Comment object for the current blog post.
     685                 * @param string  $value ID of the user associated with the current blog post comment.
     686                 */
     687                do_action( 'bp_blogs_new_blog_comment', $comment->comment_ID, $comment, bp_loggedin_user_id() );
    729688        }
    730689
    731         return $recorded_comment;
     690        return $activity_id;
    732691}
    733 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
    734 add_action( 'edit_comment', 'bp_blogs_record_comment', 10    );
     692add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4 );
    735693
    736694/**
    737695 * Record a user's association with a blog.
    function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) { 
    984942add_action( 'delete_post', 'bp_blogs_remove_post' );
    985943
    986944/**
    987  * Remove a blog comment activity item from the activity stream.
     945 * Remove a synced activity comment from the activity stream.
     946 *
     947 * @since 2.5.0
     948 *
     949 * @param bool   $deleted              True when a comment post type activity was successfully removed.
     950 * @param int    $comment_id           ID of the comment to be removed.
     951 * @param object $activity_post_object The post type tracking args object.
     952 * @param string $activity_type        The post type comment activity type.
    988953 *
    989  * @param int $comment_id ID of the comment to be removed.
     954 * @return bool True on success. False on error.
    990955 */
    991 function bp_blogs_remove_comment( $comment_id ) {
    992         global $wpdb;
    993 
    994         // Activity comments are disabled for blog posts
    995         // which means that individual activity items exist for blog comments.
    996         if ( bp_disable_blogforum_comments() ) {
    997                 // Delete the individual activity stream item.
    998                 bp_blogs_delete_activity( array(
    999                         'item_id'           => $wpdb->blogid,
    1000                         'secondary_item_id' => $comment_id,
    1001                         'type'              => 'new_blog_comment'
    1002                 ) );
    1003 
    1004         // Activity comments are enabled for blog posts
    1005         // remove the associated activity item.
    1006         } else {
    1007                 // Get associated activity ID from comment meta.
     956function bp_blogs_post_type_remove_comment( $deleted, $comment_id, $activity_post_object, $activity_type = '' ) {
     957        // Remove synced activity comments, if needed.
     958        if ( ! bp_disable_blogforum_comments() ) {
     959                // Get associated activity ID from comment meta
    1008960                $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true );
    1009961
    1010                 // Delete the associated activity comment.
    1011                 //
    1012                 // Also removes child post comments and associated activity comments.
    1013                 if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) {
    1014                         // Fetch the activity comments for the activity item.
     962                /**
     963                 * Delete the associated activity comment & also remove
     964                 * child post comments and associated activity comments.
     965                 */
     966                if ( ! empty( $activity_id ) ) {
     967                        // fetch the activity comments for the activity item
    1015968                        $activity = bp_activity_get( array(
    1016969                                'in'               => $activity_id,
    1017970                                'display_comments' => 'stream',
    1018971                                'spam'             => 'all',
    1019972                        ) );
    1020973
    1021                         // Get all activity comment IDs for the pending deleted item.
     974                        // get all activity comment IDs for the pending deleted item
    1022975                        if ( ! empty( $activity['activities'] ) ) {
    1023976                                $activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
    1024977                                $activity_ids[] = $activity_id;
    1025978
    1026                                 // Delete activity items.
     979                                // delete activity items
    1027980                                foreach ( $activity_ids as $activity_id ) {
    1028981                                        bp_activity_delete( array(
    1029982                                                'id' => $activity_id
    1030983                                        ) );
    1031984                                }
    1032985
    1033                                 // Remove associated blog comments.
     986                                // remove associated blog comments
    1034987                                bp_blogs_remove_associated_blog_comments( $activity_ids );
    1035988
    1036                                 // Rebuild activity comment tree.
     989                                // rebuild activity comment tree
    1037990                                BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id );
     991
     992                                // Set the result
     993                                $deleted = true;
    1038994                        }
    1039995                }
    1040996        }
    1041997
    1042         /**
    1043          * Fires after a blog comment activity item was removed from activity stream.
    1044          *
    1045          * @since 1.0.0
    1046          *
    1047          * @param int $blogid     Item ID for the blog associated with the removed comment.
    1048          * @param int $comment_id ID of the comment being removed.
    1049          * @param int $value      ID of the current logged in user.
    1050          */
    1051         do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() );
     998        // Backcompat for comments about the 'post' post type.
     999        if ( 'new_blog_comment' === $activity_type ) {
     1000                /**
     1001                 * Fires after a blog comment activity item was removed from activity stream.
     1002                 *
     1003                 * @since 1.0.0
     1004                 *
     1005                 * @param int $value      ID for the blog associated with the removed comment.
     1006                 * @param int $comment_id ID of the comment being removed.
     1007                 * @param int $value      ID of the current logged in user.
     1008                 */
     1009                do_action( 'bp_blogs_remove_comment', get_current_blog_id(), $comment_id, bp_loggedin_user_id() );
     1010        }
     1011
     1012        return $deleted;
    10521013}
    1053 add_action( 'delete_comment', 'bp_blogs_remove_comment' );
     1014add_action( 'bp_activity_post_type_remove_comment', 'bp_blogs_post_type_remove_comment', 10, 4 );
    10541015
    10551016/**
    10561017 * Removes blog comments that are associated with activity comments.
    10571018 *
    10581019 * @since 2.0.0
    10591020 *
    1060  * @see bp_blogs_remove_comment()
     1021 * @see bp_blogs_remove_synced_comment()
    10611022 * @see bp_blogs_sync_delete_from_activity_comment()
    10621023 *
    10631024 * @param array $activity_ids The activity IDs to check association with blog
    function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $for 
    10941055}
    10951056
    10961057/**
    1097  * When a blog comment status transition occurs, update the relevant activity's status.
    1098  *
    1099  * @since 1.6.0
    1100  *
    1101  * @param string $new_status New comment status.
    1102  * @param string $old_status Previous comment status.
    1103  * @param object $comment    Comment data.
    1104  */
    1105 function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
    1106 
    1107         // Check the Activity component is active.
    1108         if ( ! bp_is_active( 'activity' ) )
    1109                 return;
    1110 
    1111         /**
    1112          * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
    1113          *
    1114          * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
    1115          * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
    1116          * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
    1117          * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.
    1118          * Otherwise, record the comment into the activity stream.
    1119          */
    1120 
    1121         // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.
    1122         if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {
    1123                 return bp_blogs_remove_comment( $comment->comment_ID );
    1124 
    1125         // These clauses handle trash, spam, and un-spams.
    1126         } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) {
    1127                 $action = 'spam_activity';
    1128         } elseif ( 'approved' == $new_status ) {
    1129                 $action = 'ham_activity';
    1130         }
    1131 
    1132         // Get the activity.
    1133         if ( bp_disable_blogforum_comments() ) {
    1134                 $activity_id = bp_activity_get_activity_id( array(
    1135                         'component'         => buddypress()->blogs->id,
    1136                         'item_id'           => get_current_blog_id(),
    1137                         'secondary_item_id' => $comment->comment_ID,
    1138                         'type'              => 'new_blog_comment'
    1139                 ) );
    1140         } else {
    1141                 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
    1142         }
    1143 
    1144         // Check activity item exists.
    1145         if ( empty( $activity_id ) ) {
    1146                 // If no activity exists, but the comment has been approved, record it into the activity table.
    1147                 if ( 'approved' == $new_status ) {
    1148                         return bp_blogs_record_comment( $comment->comment_ID, true );
    1149                 }
    1150 
    1151                 return;
    1152         }
    1153 
    1154         // Create an activity object.
    1155         $activity = new BP_Activity_Activity( $activity_id );
    1156         if ( empty( $activity->component ) )
    1157                 return;
    1158 
    1159         // Spam/ham the activity if it's not already in that state.
    1160         if ( 'spam_activity' == $action && ! $activity->is_spam ) {
    1161                 bp_activity_mark_as_spam( $activity );
    1162         } elseif ( 'ham_activity' == $action) {
    1163                 bp_activity_mark_as_ham( $activity );
    1164         }
    1165 
    1166         // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated.
    1167         $comment_akismet_history = create_function( '$t', '$t[] = "new_blog_comment"; return $t;' );
    1168         add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
    1169 
    1170         // Save the updated activity.
    1171         $activity->save();
    1172 
    1173         // Remove the "new_blog_comment" activity type whitelist so we don't break anything.
    1174         remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
    1175 }
    1176 add_action( 'transition_comment_status', 'bp_blogs_transition_activity_status', 10, 3 );
    1177 
    1178 /**
    11791058 * Get the total number of blogs being tracked by BuddyPress.
    11801059 *
    11811060 * @return int $count Total blog count.
  • src/bp-blogs/bp-blogs-loader.php

    diff --git src/bp-blogs/bp-blogs-loader.php src/bp-blogs/bp-blogs-loader.php
    index 67d84db..274bc5f 100644
    class BP_Blogs_Component extends BP_Component { 
    106106                                add_post_type_support( $post_type, 'buddypress-activity' );
    107107                        }
    108108                }
    109 
    110                 // Filter the generic track parameters for the 'post' post type.
    111                 add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 );
    112109        }
    113110
    114111        /**
    class BP_Blogs_Component extends BP_Component { 
    128125                        'classes',
    129126                        'template',
    130127                        'filters',
    131                         'activity',
    132128                        'functions',
    133129                );
    134130
     131                if ( bp_is_active( 'activity' ) ) {
     132                        $includes[] = 'activity';
     133                }
     134
    135135                if ( is_multisite() ) {
    136136                        $includes[] = 'widgets';
    137137                }
    class BP_Blogs_Component extends BP_Component { 
    300300
    301301                parent::setup_cache_groups();
    302302        }
    303 
    304         /**
    305          * Set up the tracking arguments for the 'post' post type.
    306          *
    307          * @since 2.2.0
    308          *
    309          * @see bp_activity_get_post_type_tracking_args() for information on parameters.
    310          *
    311          * @param object|null $params    Tracking arguments.
    312          * @param string|int  $post_type Post type to track.
    313          * @return object
    314          */
    315         public function post_tracking_args( $params = null, $post_type = 0 ) {
    316 
    317                 /**
    318                  * Filters the post types to track for the Blogs component.
    319                  *
    320                  * @since 1.5.0
    321                  * @deprecated 2.3.0
    322                  *
    323                  * Make sure plugins still using 'bp_blogs_record_post_post_types'
    324                  * to track their post types will generate new_blog_post activities
    325                  * See https://buddypress.trac.wordpress.org/ticket/6306
    326                  *
    327                  * @param array $value Array of post types to track.
    328                  */
    329                 $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
    330                 $post_types_array = array_flip( $post_types );
    331 
    332                 if ( ! isset( $post_types_array[ $post_type ] ) ) {
    333                         return $params;
    334                 }
    335 
    336                 // Set specific params for the 'post' post type.
    337                 $params->component_id    = $this->id;
    338                 $params->action_id       = 'new_blog_post';
    339                 $params->admin_filter    = __( 'New post published', 'buddypress' );
    340                 $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
    341                 $params->front_filter    = __( 'Posts', 'buddypress' );
    342                 $params->contexts        = array( 'activity', 'member' );
    343                 $params->position        = 5;
    344 
    345                 return $params;
    346         }
    347303}
    348304
    349305/**
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index a85c41e..28e5278 100644
    function bp_version_updater() { 
    260260                if ( $raw_db_version < 9615 ) {
    261261                        bp_update_to_2_3();
    262262                }
     263
     264                // 2.5.0
     265                if ( $raw_db_version < 10429 ) {
     266                        bp_update_to_2_5();
     267                }
    263268        }
    264269
    265270        /** All done! *************************************************************/
    function bp_update_to_2_3() { 
    484489}
    485490
    486491/**
     492 * 2.5.0 update routine.
     493 *
     494 * - Add a new activity meta for Post comments synced with activity comments
     495 *
     496 * @since 2.5.0
     497 */
     498function bp_update_to_2_5() {
     499        if ( bp_is_active( 'activity' ) ) {
     500                bp_activity_post_type_comment_reset_parent_type_meta();
     501        }
     502}
     503
     504/**
    487505 * Updates the component field for new_members type.
    488506 *
    489507 * @since 2.2.0
  • src/bp-core/deprecated/1.6.php

    diff --git src/bp-core/deprecated/1.6.php src/bp-core/deprecated/1.6.php
    index 626d31b..c5550b6 100644
    function bp_core_is_user_spammer( $user_id = 0 ) { 
    8484
    8585/**
    8686 * @deprecated 1.6.0
    87  * @deprecated No longer used; see bp_blogs_transition_activity_status()
     87 * @deprecated No longer used; see bp_activity_transition_post_type_comment_status()
    8888 */
    8989function bp_blogs_manage_comment( $comment_id, $comment_status ) {
    9090        _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
  • src/bp-core/deprecated/2.5.php

    diff --git src/bp-core/deprecated/2.5.php src/bp-core/deprecated/2.5.php
    index e69de29..de1a8ba 100644
     
     1<?php
     2/**
     3 * Deprecated functions.
     4 *
     5 * @deprecated 2.5.0
     6 */
     7
     8// Exit if accessed directly.
     9defined( 'ABSPATH' ) || exit;
     10
     11/**
     12 * When a blog comment status transition occurs, update the relevant activity's status.
     13 *
     14 * @since 1.6.0
     15 * @deprecated 2.5.0
     16 *
     17 * @param string $new_status New comment status.
     18 * @param string $old_status Previous comment status.
     19 * @param object $comment Comment data.
     20 */
     21function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
     22        _deprecated_function( __FUNCTION__, '2.5.0', 'bp_activity_transition_post_type_comment_status()' );
     23        bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment );
     24}
     25
     26/**
     27 * Record a new blog comment in the BuddyPress activity stream.
     28 *
     29 * Only posts the item if blog is public and post is not password-protected.
     30 *
     31 * @deprecated 2.5.0
     32 *
     33 * @param int $comment_id ID of the comment being recorded.
     34 * @param bool|string $is_approved Optional. The $is_approved value passed to
     35 *        the 'comment_post' action. Default: true.
     36 * @return bool|object Returns false on failure, the comment object on success.
     37 */
     38function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
     39        _deprecated_function( __FUNCTION__, '2.5.0', 'bp_activity_post_type_comment()' );
     40        bp_activity_post_type_comment( $comment_id, $is_approved );
     41}
     42
     43/**
     44 * Remove a blog comment activity item from the activity stream.
     45 *
     46 * @deprecated 2.5.0
     47 *
     48 * @param int $comment_id ID of the comment to be removed.
     49 */
     50function bp_blogs_remove_comment( $comment_id ) {
     51        _deprecated_function( __FUNCTION__, '2.5.0', 'bp_activity_post_type_remove_comment()' );
     52        bp_activity_post_type_remove_comment( $comment_id );
     53}
  • src/bp-loader.php

    diff --git src/bp-loader.php src/bp-loader.php
    index 77d5408..40d6da0 100644
    class BuddyPress { 
    328328                /** Versions **********************************************************/
    329329
    330330                $this->version    = '2.5.0-alpha';
    331                 $this->db_version = 10071;
     331                $this->db_version = 10429;
    332332
    333333                /** Loading ***********************************************************/
    334334
    class BuddyPress { 
    501501                        require( $this->plugin_dir . 'bp-core/deprecated/2.2.php' );
    502502                        require( $this->plugin_dir . 'bp-core/deprecated/2.3.php' );
    503503                        require( $this->plugin_dir . 'bp-core/deprecated/2.4.php' );
     504                        require( $this->plugin_dir . 'bp-core/deprecated/2.5.php' );
    504505                }
    505506        }
    506507
  • tests/phpunit/includes/testcase.php

    diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
    index a75009a..1e8bcb4 100644
    class BP_UnitTestCase extends WP_UnitTestCase { 
    4949
    5050                // Clean up after autocommits.
    5151                add_action( 'bp_blogs_recorded_existing_blogs', array( $this, 'set_autocommit_flag' ) );
     52
     53                // Make sure Activity actions are reset before each test
     54                $this->reset_bp_activity_actions();
     55
     56                // Make sure all Post types activities globals are reset before each test
     57                $this->reset_bp_activity_post_types_globals();
    5258        }
    5359
    5460        public function tearDown() {
    class BP_UnitTestCase extends WP_UnitTestCase { 
    97103                parent::clean_up_global_scope();
    98104        }
    99105
     106        protected function reset_bp_activity_actions() {
     107                buddypress()->activity->actions = new stdClass();
     108
     109                /**
     110                 * Populate the global with default activity actions only
     111                 * before each test.
     112                 */
     113                do_action( 'bp_register_activity_actions' );
     114        }
     115
     116        protected function reset_bp_activity_post_types_globals() {
     117                global $wp_post_types;
     118
     119                // Remove all remaining tracking arguments to each post type
     120                foreach ( $wp_post_types as $post_type => $post_type_arg ) {
     121                        if ( post_type_supports( $post_type, 'buddypress-activity' ) ) {
     122                                remove_post_type_support( $post_type, 'buddypress-activity' );
     123                        }
     124
     125                        if ( isset( $post_type_arg->bp_activity ) ) {
     126                                unset( $post_type_arg->bp_activity );
     127                        }
     128                }
     129
     130                buddypress()->activity->track = array();
     131        }
     132
    100133        function assertPreConditions() {
    101134                parent::assertPreConditions();
    102135
  • tests/phpunit/testcases/activity/actions.php

    diff --git tests/phpunit/testcases/activity/actions.php tests/phpunit/testcases/activity/actions.php
    index d1ae6df..5549607 100644
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    99         * @group activity_tracking
    1010         */
    1111        public function test_bp_activity_catch_transition_post_type_status_publish() {
    12                 $bp = buddypress();
    13 
    1412                register_post_type( 'foo', array(
    1513                        'label'   => 'foo',
    1614                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    2826                $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' );
    2927
    3028                _unregister_post_type( 'foo' );
    31 
    32                 // Reset globals
    33                 unset( $bp->activity->actions->activity->new_foo );
    34                 $bp->activity->track = array();
    3529        }
    3630
    3731        /**
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    3933         * @group activity_tracking
    4034         */
    4135        public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() {
    42                 $bp = buddypress();
    43 
    4436                register_post_type( 'foo', array(
    4537                        'label'   => 'foo',
    4638                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    6860                $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' );
    6961
    7062                _unregister_post_type( 'foo' );
    71 
    72                 // Reset globals
    73                 unset( $bp->activity->actions->activity->new_foo );
    74                 $bp->activity->track = array();
    7563        }
    7664
    7765        /**
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    7967         * @group activity_tracking
    8068         */
    8169        public function test_bp_activity_catch_transition_post_type_status_publish_password() {
    82                 $bp = buddypress();
    83 
    8470                register_post_type( 'foo', array(
    8571                        'label'   => 'foo',
    8672                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    10692                $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' );
    10793
    10894                _unregister_post_type( 'foo' );
    109 
    110                 // Reset globals
    111                 unset( $bp->activity->actions->activity->new_foo );
    112                 $bp->activity->track = array();
    11395        }
    11496
    11597        /**
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    11799         * @group activity_tracking
    118100         */
    119101        public function test_bp_activity_catch_transition_post_type_status_publish_trash() {
    120                 $bp = buddypress();
    121 
    122102                register_post_type( 'foo', array(
    123103                        'label'   => 'foo',
    124104                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    141121                $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' );
    142122
    143123                _unregister_post_type( 'foo' );
    144 
    145                 // Reset globals
    146                 unset( $bp->activity->actions->activity->new_foo );
    147                 $bp->activity->track = array();
    148124        }
    149125
    150126        protected function activity_exists_for_post( $post_id, $action ) {
  • tests/phpunit/testcases/activity/functions.php

    diff --git tests/phpunit/testcases/activity/functions.php tests/phpunit/testcases/activity/functions.php
    index 8a3304f..3398afa 100644
    Bar!'; 
    763763                        return;
    764764                }
    765765
    766                 $bp = buddypress();
    767 
    768766                register_post_type( 'foo', array(
    769767                        'label'   => 'foo',
    770768                        'public'   => true,
    Bar!'; 
    800798                $this->assertSame( $expected, $a_obj->action );
    801799
    802800                _unregister_post_type( 'foo' );
    803 
    804                 // Reset globals
    805                 unset( $bp->activity->actions->activity->new_foo );
    806                 $bp->activity->track = array();
    807801        }
    808802
    809803        /**
    Bar!'; 
    816810                        return;
    817811                }
    818812
    819                 $bp = buddypress();
    820 
    821813                $b = $this->factory->blog->create();
    822814                $u = $this->factory->user->create();
    823815
    Bar!'; 
    863855                $expected = sprintf( '%s wrote a new %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
    864856
    865857                $this->assertSame( $expected, $a_obj->action );
    866 
    867                 // Reset globals
    868                 unset( $bp->activity->actions->activity->new_foo );
    869                 $bp->activity->track = array();
    870858        }
    871859
    872860        /**
    Bar!'; 
    874862         * @group bp_activity_get_actions
    875863         */
    876864        public function test_bp_activity_get_actions_should_sort_by_position() {
    877                 $old_actions = bp_activity_get_actions();
    878865                buddypress()->activity->actions = new stdClass;
    879866
    880867                register_post_type( 'foo5', array(
    Bar!'; 
    916903                );
    917904                $foo_actions = (array) $actions->foo;
    918905                $this->assertEquals( $expected, array_values( wp_list_pluck( $foo_actions, 'key' ) ) );
    919 
    920                 buddypress()->activity->actions = $old_actions;
    921906        }
    922907
    923908        /**
    Bar!'; 
    929914                        return;
    930915                }
    931916
    932                 $bp = buddypress();
    933 
    934917                $labels = array(
    935918                        'name'                 => 'bars',
    936919                        'singular_name'        => 'bar',
    Bar!'; 
    974957                $this->assertSame( $expected, $a_obj->action );
    975958
    976959                _unregister_post_type( 'foo' );
    977 
    978                 // Reset globals
    979                 unset( $bp->activity->actions->activity->foo_bar );
    980                 $bp->activity->track = array();
    981960        }
    982961
    983962        /**
    Bar!'; 
    990969                        return;
    991970                }
    992971
    993                 $bp = buddypress();
    994                 $reset = $bp->activity->actions;
    995 
    996972                $b = $this->factory->blog->create();
    997973                $u = $this->factory->user->create();
    998974
    Bar!'; 
    10411017                $expected = sprintf( '%1$s shared a new <a href="%2$s">bar</a>, on the site %3$s', $user_link, $post_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
    10421018
    10431019                $this->assertSame( $expected, $a_obj->action );
    1044 
    1045                 // Reset globals
    1046                 unset( $bp->activity->actions->activity->new_foo );
    1047                 $bp->activity->track = array();
    10481020        }
    10491021
    10501022        /**
    Bar!'; 
    10811053                $this->assertSame( $bp->blogs->id, $a['activities'][0]->component );
    10821054
    10831055                remove_post_type_support( 'page', 'buddypress-activity' );
    1084 
    1085                 // Reset globals
    1086                 unset( $bp->activity->actions->blogs->new_page );
    1087                 $bp->activity->track = array();
    10881056        }
    10891057
    10901058        /**
    Bar!'; 
    11261094        }
    11271095
    11281096        /**
     1097         * @group activity_action
     1098         * @group bp_activity_format_activity_action_custom_post_type_post_ms
     1099         * @group post_type_comment_activities
     1100         */
     1101        public function test_bp_activity_format_activity_action_custom_post_type_comment() {
     1102                if ( is_multisite() ) {
     1103                        $b = $this->factory->blog->create();
     1104                        switch_to_blog( $b );
     1105                        add_filter( 'comment_flood_filter', '__return_false' );
     1106                } else {
     1107                        $b = get_current_blog_id();
     1108                }
     1109
     1110                $u = $this->factory->user->create();
     1111                $userdata = get_userdata( $u );
     1112
     1113                $labels = array(
     1114                        'name'                       => 'bars',
     1115                        'singular_name'              => 'bar',
     1116                        'bp_activity_new_comment'    => __( '%1$s commented on the <a href="%2$s">bar</a>', 'buddypress' ),
     1117                        'bp_activity_new_comment_ms' => __( '%1$s commented on the <a href="%2$s">bar</a>, on the site %3$s', 'buddypress' ),
     1118                );
     1119
     1120                register_post_type( 'foo', array(
     1121                        'labels'   => $labels,
     1122                        'public'   => true,
     1123                        'supports' => array( 'buddypress-activity', 'comments' ),
     1124                        'bp_activity' => array(
     1125                                'action_id'         => 'new_bar',
     1126                                'comment_action_id' => 'new_bar_comment',
     1127                        ),
     1128                ) );
     1129
     1130                // Build the actions to fetch the tracking args
     1131                bp_activity_get_actions();
     1132
     1133                $p = $this->factory->post->create( array(
     1134                        'post_author' => $u,
     1135                        'post_type'   => 'foo',
     1136                ) );
     1137
     1138                $c = wp_new_comment( array(
     1139                        'comment_post_ID'      => $p,
     1140                        'comment_author'       => $userdata->user_nicename,
     1141                        'comment_author_url'   => 'http://buddypress.org',
     1142                        'comment_author_email' => $userdata->user_email,
     1143                        'comment_content'      => 'this is a blog comment',
     1144                        'comment_type'         => '',
     1145                        'comment_parent'       => 0,
     1146                        'user_id'              => $u,
     1147                ) );
     1148
     1149                $a = bp_activity_get_activity_id( array( 'type' => 'new_bar_comment' ) );
     1150
     1151                $a_obj = new BP_Activity_Activity( $a );
     1152
     1153                $user_link    = bp_core_get_userlink( $u );
     1154                $comment_url  = get_comment_link( $c );
     1155
     1156                _unregister_post_type( 'foo' );
     1157
     1158                if ( is_multisite() ) {
     1159                        $blog_url  = get_blog_option( $a_obj->item_id, 'home' );
     1160                        restore_current_blog();
     1161                        remove_filter( 'comment_flood_filter', '__return_false' );
     1162
     1163                        $expected = sprintf( $labels['bp_activity_new_comment_ms'], $user_link, $comment_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     1164                } else {
     1165                        $expected = sprintf( $labels['bp_activity_new_comment'], $user_link, $comment_url );
     1166                }
     1167
     1168                $this->assertSame( $expected, $a_obj->action );
     1169        }
     1170
     1171        /**
    11291172         * @group bp_activity_new_comment
    11301173         * @group cache
    11311174         */
    Bar!'; 
    14321475                $this->assertSame( array(), $found['activities'] );
    14331476        }
    14341477
     1478        /**
     1479         * @group bp_activity_post_type_comment_reset_parent_type_meta
     1480         * @group bp_blogs_new_blog_comment_query_backpat
     1481         * @group post_type_comment_activities
     1482         */
     1483        public function test_bp_activity_post_type_comment_reset_parent_type_meta() {
     1484                $blogs = array();
     1485                if ( is_multisite() ) {
     1486                        $blogs = array(
     1487                                $this->factory->blog->create(),
     1488                                $this->factory->blog->create(),
     1489                        );
     1490                }
     1491
     1492                $blogs = array_merge( array( get_current_blog_id() ), $blogs );
     1493                $synced_activity_comments = array();
     1494
     1495                $u = $this->factory->user->create();
     1496                $i = 1;
     1497
     1498                foreach ( $blogs as $blog ) {
     1499
     1500                        $a = $this->factory->activity->create( array(
     1501                                'type'    => 'new_blog_post',
     1502                                'user_id' => $u,
     1503                                'item_id' => $blog,
     1504                        ) );
     1505
     1506                        $ac = $this->factory->activity->create( array(
     1507                                'type'    => 'activity_comment',
     1508                                'user_id' => $u,
     1509                                'item_id' => $a,
     1510                        ) );
     1511
     1512                        bp_activity_update_meta( $ac, 'bp_blogs_post_comment_id', $i );
     1513
     1514                        $synced_activity_comments[ $ac ] = $i;
     1515
     1516                        $i += 1;
     1517                }
     1518
     1519                bp_activity_post_type_comment_reset_parent_type_meta();
     1520
     1521                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     1522
     1523                global $activities_template;
     1524                $reset_activities_template = $activities_template;
     1525                bp_has_activities( array( 'action' => 'new_blog_comment' ) );
     1526
     1527                $check_activities = wp_list_pluck( $activities_template->activities, 'id' );
     1528
     1529                foreach ( $check_activities as $cid ) {
     1530                        $this->assertTrue( (int) $synced_activity_comments[ $cid ] === (int) bp_activity_get_meta( $cid, 'bp_blogs_post_comment_id' ) );
     1531                        unset( $synced_activity_comments[ $cid ] );
     1532                }
     1533
     1534                $this->assertEmpty( $synced_activity_comments );
     1535
     1536                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     1537                $activities_template = $reset_activities_template;
     1538        }
     1539
    14351540        public function check_activity_caches() {
    14361541                foreach ( $this->acaches as $k => $v ) {
    14371542                        $this->acaches[ $k ] = wp_cache_get( $k, 'bp_activity' );
  • tests/phpunit/testcases/activity/template.php

    diff --git tests/phpunit/testcases/activity/template.php tests/phpunit/testcases/activity/template.php
    index db33cda..c5b1e20 100644
    class BP_Tests_Activity_Template extends BP_UnitTestCase { 
    909909        /**
    910910         * @group filter_query
    911911         * @group BP_Activity_Query
     912         * @group post_type_comment_activities
    912913         */
    913914        function test_bp_has_activities_with_filter_query_compare_regex() {
    914915                $u1 = $this->factory->user->create();
    class BP_Tests_Activity_Template extends BP_UnitTestCase { 
    12991300
    13001301        /**
    13011302         * @group bp_has_activities
     1303         * @group post_type_comment_activities
    13021304         */
    13031305        public function test_bp_has_activities_with_type_new_blog_comments() {
    13041306                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
  • tests/phpunit/testcases/blogs/activity.php

    diff --git tests/phpunit/testcases/blogs/activity.php tests/phpunit/testcases/blogs/activity.php
    index 08941e2..d7595ef 100644
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    156156        /**
    157157         * @group activity_action
    158158         * @group bp_blogs_format_activity_action_new_blog_comment
     159         * @group post_type_comment_activities
    159160         */
    160161        public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() {
    161162                if ( ! is_multisite() ) {
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    318319                        return;
    319320                }
    320321
    321                 $bp = buddypress();
    322                 $activity_actions = $bp->activity->actions;
    323                 $bp->activity->actions = new stdClass();
     322                buddypress()->activity->actions = new stdClass();
    324323
    325324                $u = $this->factory->user->create();
    326325                $p = wp_insert_post( array(
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    346345                $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link );
    347346
    348347                $this->assertSame( $expected, $a_obj['activities'][0]->action );
    349 
    350                 // Reset activity actions
    351                 $bp->activity->actions = $activity_actions;
    352                 $bp->activity->track = array();
    353348        }
    354349
    355350        /**
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    361356                        return;
    362357                }
    363358
    364                 $bp = buddypress();
    365                 $activity_actions = $bp->activity->actions;
    366                 $bp->activity->actions = new stdClass();
     359                buddypress()->activity->actions = new stdClass();
    367360
    368361                $u = $this->factory->user->create();
    369362                $p = wp_insert_post( array(
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    407400                ) );
    408401
    409402                $this->assertSame( $expected, $a_obj['activities'][0]->action );
     403        }
     404
     405        /**
     406         * @group bp_blogs_sync_add_from_activity_comment
     407         * @group post_type_comment_activities
     408         */
     409        public function test_bp_blogs_sync_add_from_activity_comment() {
     410                $old_user = get_current_user_id();
     411                $u = $this->factory->user->create();
     412                $this->set_current_user( $u );
     413                $userdata = get_userdata( $u );
     414
     415                // let's use activity comments instead of single "new_blog_comment" activity items
     416                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     417
     418                // create the blog post
     419                $post_id = $this->factory->post->create( array(
     420                        'post_status' => 'publish',
     421                        'post_type'   => 'post',
     422                        'post_title'  => 'Test activity comment to post comment',
     423                ) );
     424
     425                // grab the activity ID for the activity comment
     426                $a1 = bp_activity_get_activity_id( array(
     427                        'type'      => 'new_blog_post',
     428                        'component' => buddypress()->blogs->id,
     429                        'filter'    => array(
     430                                'item_id' => get_current_blog_id(),
     431                                'secondary_item_id' => $post_id
     432                        ),
     433                ) );
     434
     435                $a2 = bp_activity_new_comment( array(
     436                        'content'     => 'this content shoud be in a new post comment',
     437                        'user_id'     => $u,
     438                        'activity_id' => $a1,
     439                ) );
     440
     441                $approved_comments = get_approved_comments( $post_id );
     442                $comment = reset( $approved_comments );
     443
     444                $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' );
     445                $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' );
     446
     447                // reset
     448                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     449
     450                $this->set_current_user( $old_user );
     451        }
     452
     453        /**
     454         * @group bp_blogs_sync_delete_from_activity_comment
     455         * @group post_type_comment_activities
     456         */
     457        public function test_bp_blogs_sync_delete_from_activity_comment() {
     458                $old_user = get_current_user_id();
     459                $u = $this->factory->user->create();
     460                $this->set_current_user( $u );
     461                $userdata = get_userdata( $u );
     462
     463                // let's use activity comments instead of single "new_blog_comment" activity items
     464                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     465
     466                // create the blog post
     467                $post_id = $this->factory->post->create( array(
     468                        'post_status' => 'publish',
     469                        'post_type'   => 'post',
     470                        'post_title'  => 'Test activity comment to post comment',
     471                ) );
     472
     473                // grab the activity ID for the activity comment
     474                $a1 = bp_activity_get_activity_id( array(
     475                        'type'      => 'new_blog_post',
     476                        'component' => buddypress()->blogs->id,
     477                        'filter'    => array(
     478                                'item_id' => get_current_blog_id(),
     479                                'secondary_item_id' => $post_id
     480                        ),
     481                ) );
     482
     483                $a2 = bp_activity_new_comment( array(
     484                        'content'     => 'the generated comment should be deleted once the activity comment is removed',
     485                        'user_id'     => $u,
     486                        'activity_id' => $a1,
     487                ) );
     488
     489                bp_activity_delete_comment( $a1, $a2 );
     490
     491                $post_comments = get_comments( array( 'post_id' => $post_id ) );
     492
     493                $this->assertEmpty( $post_comments, 'A post comment should be deleted when the corresponding activity is' );
     494
     495                // reset
     496                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     497
     498                $this->set_current_user( $old_user );
     499        }
     500
     501        /**
     502         * @group bp_blogs_sync_activity_edit_to_post_comment
     503         * @group post_type_comment_activities
     504         */
     505        public function test_bp_blogs_sync_activity_edit_to_post_comment_spam_unspam_activity_comment() {
     506                $old_user = get_current_user_id();
     507                $u = $this->factory->user->create();
     508                $this->set_current_user( $u );
     509                $userdata = get_userdata( $u );
     510
     511                // let's use activity comments instead of single "new_blog_comment" activity items
     512                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     513
     514                // create the blog post
     515                $post_id = $this->factory->post->create( array(
     516                        'post_status' => 'publish',
     517                        'post_type'   => 'post',
     518                        'post_title'  => 'Test activity comment to post comment',
     519                ) );
     520
     521                // grab the activity ID for the activity comment
     522                $a1 = bp_activity_get_activity_id( array(
     523                        'type'      => 'new_blog_post',
     524                        'component' => buddypress()->blogs->id,
     525                        'filter'    => array(
     526                                'item_id' => get_current_blog_id(),
     527                                'secondary_item_id' => $post_id
     528                        ),
     529                ) );
     530
     531                $a2 = bp_activity_new_comment( array(
     532                        'content'     => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed',
     533                        'user_id'     => $u,
     534                        'activity_id' => $a1,
     535                ) );
     536
     537                $activity = new BP_Activity_Activity( $a2 );
     538
     539                bp_activity_mark_as_spam( $activity );
     540                $activity->save();
     541
     542                $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     543
     544                $this->assertEmpty( $post_comments, 'A post comment should be spammed when the corresponding activity is spammed' );
     545
     546                bp_activity_mark_as_ham( $activity );
     547                $activity->save();
     548
     549                $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     550                $comment = reset( $post_comments );
     551
     552                $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' );
     553                $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' );
     554
     555                // reset
     556                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     557
     558                $this->set_current_user( $old_user );
     559        }
     560
     561        /**
     562         * @group bp_blogs_sync_activity_edit_to_post_comment
     563         * @group post_type_comment_activities
     564         */
     565        public function test_bp_blogs_sync_activity_edit_to_post_comment_spam_activity_comment_unspam_post_comment() {
     566                $old_user = get_current_user_id();
     567                $u = $this->factory->user->create();
     568                $this->set_current_user( $u );
     569                $userdata = get_userdata( $u );
     570
     571                // let's use activity comments instead of single "new_blog_comment" activity items
     572                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     573
     574                // create the blog post
     575                $post_id = $this->factory->post->create( array(
     576                        'post_status' => 'publish',
     577                        'post_type'   => 'post',
     578                        'post_title'  => 'Test activity comment to post comment',
     579                ) );
     580
     581                // grab the activity ID for the activity comment
     582                $a1 = bp_activity_get_activity_id( array(
     583                        'type'      => 'new_blog_post',
     584                        'component' => buddypress()->blogs->id,
     585                        'filter'    => array(
     586                                'item_id' => get_current_blog_id(),
     587                                'secondary_item_id' => $post_id
     588                        ),
     589                ) );
     590
     591                $a2 = bp_activity_new_comment( array(
     592                        'content'     => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed',
     593                        'user_id'     => $u,
     594                        'activity_id' => $a1,
     595                ) );
     596
     597                $c = bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' );
     598
     599                $activity = new BP_Activity_Activity( $a2 );
     600
     601                bp_activity_mark_as_spam( $activity );
     602                $activity->save();
     603
     604                wp_unspam_comment( $c );
     605
     606                $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     607                $comment = reset( $post_comments );
     608
     609                $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' );
     610                $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' );
     611
     612                // reset
     613                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     614
     615                $this->set_current_user( $old_user );
     616        }
     617
     618        /**
     619         * @group bp_blogs_sync_activity_edit_to_post_comment
     620         * @group post_type_comment_activities
     621         * @group imath
     622         */
     623        public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity() {
     624                $old_user = get_current_user_id();
     625                $u = $this->factory->user->create();
     626                $this->set_current_user( $u );
     627                $userdata = get_userdata( $u );
     628
     629                // let's use activity comments instead of single "new_blog_comment" activity items
     630                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     631
     632                // create the blog post
     633                $post_id = $this->factory->post->create( array(
     634                        'post_status' => 'publish',
     635                        'post_type'   => 'post',
     636                        'post_title'  => 'Test activity comment to post comment',
     637                ) );
     638
     639                // grab the activity ID for the activity comment
     640                $a1 = bp_activity_get_activity_id( array(
     641                        'type'      => 'new_blog_post',
     642                        'component' => buddypress()->blogs->id,
     643                        'filter'    => array(
     644                                'item_id' => get_current_blog_id(),
     645                                'secondary_item_id' => $post_id
     646                        ),
     647                ) );
     648
     649                $a2 = bp_activity_new_comment( array(
     650                        'content'     => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed',
     651                        'user_id'     => $u,
     652                        'activity_id' => $a1,
     653                ) );
     654
     655                $c = bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' );
     656
     657                wp_trash_comment( $c );
     658
     659                $activity = new BP_Activity_Activity( $a2 );
     660
     661                bp_activity_mark_as_ham( $activity );
     662                $activity->save();
     663
     664                $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     665                $comment = reset( $post_comments );
     666
     667                $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' );
     668                $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' );
     669
     670                // reset
     671                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
    410672
    411                 // Reset activity actions
    412                 $bp->activity->actions = $activity_actions;
    413                 $bp->activity->track = array();
     673                $this->set_current_user( $old_user );
    414674        }
    415675
    416676        /**
  • tests/phpunit/testcases/blogs/filters.php

    diff --git tests/phpunit/testcases/blogs/filters.php tests/phpunit/testcases/blogs/filters.php
    index a0fc961..3d2af7f 100644
    class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 
    1010        public function setUp() {
    1111                parent::setUp();
    1212
    13                 $bp = buddypress();
    14 
    15                 $this->activity_actions = $bp->activity->actions;
    16                 $bp->activity->actions = new stdClass();
    17 
    1813                $this->custom_post_types = array( 'using_old_filter' );
    1914
    2015                register_post_type( 'using_old_filter', array(
    class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 
    3530                _unregister_post_type( 'using_old_filter' );
    3631                remove_filter( 'bp_blogs_record_post_post_types',    array( $this, 'filter_post_types'), 10, 1 );
    3732                remove_filter( 'bp_blogs_record_comment_post_types', array( $this, 'filter_post_types'), 10, 1 );
    38 
    39                 // Reset activity actions
    40                 $bp->activity->actions = $this->activity_actions;
    41                 $bp->activity->track = array();
    4233        }
    4334
    4435        /**
    class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 
    6455
    6556        /**
    6657         * @goup bp_blogs_record_comment
     58         * @group post_type_comment_activities
    6759         */
    6860        public function test_bp_blogs_record_comment() {
    6961                $u = $this->factory->user->create();
    class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 
    8981
    9082        /**
    9183         * @goup bp_blogs_record_comment_sync_activity_comment
     84         * @group post_type_comment_activities
    9285         */
    9386        public function test_bp_blogs_record_comment_sync_activity_comment() {
    9487                $u = $this->factory->user->create();
  • tests/phpunit/testcases/blogs/functions.php

    diff --git tests/phpunit/testcases/blogs/functions.php tests/phpunit/testcases/blogs/functions.php
    index a058db2..9d957d4 100644
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    513513
    514514        /**
    515515         * @group bp_blogs_catch_transition_post_status
     516         * @group post_type_comment_activities
    516517         */
    517518        public function test_update_blog_post_and_new_blog_comment_and_activity_comment_meta() {
    518519                // save the current user and override logged-in user
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    596597
    597598        /**
    598599         * @group bp_blogs_transition_activity_status
    599          * @group bp_blogs_remove_comment
     600         * @group bp_blogs_post_type_remove_comment
     601         * @group post_type_comment_activities
    600602         */
    601603        public function test_bp_blogs_remove_comment_should_remove_spammed_activity_comment() {
    602604                // save the current user and override logged-in user
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    658660        }
    659661
    660662        /**
     663         * @group bp_blogs_post_type_remove_comment
     664         * @group post_type_comment_activities
     665         */
     666        public function test_bp_blogs_post_type_remove_comment() {
     667                $old_user = get_current_user_id();
     668                $u = $this->factory->user->create();
     669                $this->set_current_user( $u );
     670                $userdata = get_userdata( $u );
     671
     672                // create the blog post
     673                $p = $this->factory->post->create( array(
     674                        'post_status' => 'publish',
     675                        'post_type' => 'post',
     676                        'post_title' => 'First title',
     677                ) );
     678
     679                $c = wp_new_comment( array(
     680                        'comment_post_ID'      => $p,
     681                        'comment_author'       => $userdata->user_nicename,
     682                        'comment_author_url'   => 'http://buddypress.org',
     683                        'comment_author_email' => $userdata->user_email,
     684                        'comment_content'      => 'this comment will be removed',
     685                        'comment_type'         => '',
     686                        'comment_parent'       => 0,
     687                        'user_id'              => $u,
     688                ) );
     689
     690                // An activity should exist
     691                $a = bp_activity_get_activity_id( array(
     692                        'user_id' => $u,
     693                        'type'    => 'new_blog_comment'
     694                ) );
     695
     696                // now permanently delete the comment
     697                wp_delete_comment( $c, true );
     698
     699                // The activity comment should no longer exist
     700                $ac = bp_activity_get( array( 'in' => $a ) );
     701                $this->assertTrue( empty( $ac['activities'] ) );
     702        }
     703
     704        /**
    661705         * @group bp_blogs_catch_transition_post_status
    662706         */
    663707        public function test_bp_blogs_is_blog_trackable_false_publish_post() {
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    714758        /**
    715759         * @group bp_blogs_record_comment
    716760         * @group unique
     761         * @group post_type_comment_activities
    717762         */
    718763        public function test_bp_blogs_record_comment_no_duplicate_activity_comments() {
    719764                // save the current user and override logged-in user
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    777822
    778823        /**
    779824         * @group bp_blogs_record_comment
     825         * @group post_type_comment_activities
    780826         */
    781827        public function test_bp_blogs_record_comment_should_record_parent_blog_post_activity_if_not_found() {
    782828                // Save the current user and override logged-in user
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    826872                        ),
    827873                ) );
    828874
     875                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     876
    829877                // Assert that activity item for blog post was created after adding a comment
    830878                $this->assertNotNull( $a1, 'Activity item was not created for existing blog post when recording post comment.' );
    831879
    832880                $this->set_current_user( $old_user );
    833881        }
    834882
     883        /**
     884         * @group bp_blogs_comment_sync_activity_comment
     885         * @group post_type_comment_activities
     886         */
     887        public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type() {
     888                if ( is_multisite() ) {
     889                        $b = $this->factory->blog->create();
     890                        switch_to_blog( $b );
     891                        add_filter( 'comment_flood_filter', '__return_false' );
     892                } else {
     893                        $b = get_current_blog_id();
     894                }
     895
     896                $u = $this->factory->user->create();
     897                $userdata = get_userdata( $u );
     898
     899                $labels = array(
     900                        'name'                       => 'bars',
     901                        'singular_name'              => 'bar',
     902                );
     903
     904                register_post_type( 'foo', array(
     905                        'labels'   => $labels,
     906                        'public'   => true,
     907                        'supports' => array( 'comments' ),
     908                ) );
     909
     910                add_post_type_support( 'foo', 'buddypress-activity' );
     911
     912                bp_activity_set_post_type_tracking_args( 'foo', array(
     913                        'comment_action_id' => 'new_foo_comment',
     914                ) );
     915
     916                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     917
     918                $p = $this->factory->post->create( array(
     919                        'post_author' => $u,
     920                        'post_type'   => 'foo',
     921                ) );
     922
     923                $a1 = bp_activity_get_activity_id( array(
     924                        'type'      => 'new_foo',
     925                        'filter'    => array(
     926                                'item_id' => $b,
     927                                'secondary_item_id' => $p
     928                        ),
     929                ) );
     930
     931                $c = wp_new_comment( array(
     932                        'comment_post_ID'      => $p,
     933                        'comment_author'       => $userdata->user_nicename,
     934                        'comment_author_url'   => 'http://buddypress.org',
     935                        'comment_author_email' => $userdata->user_email,
     936                        'comment_content'      => 'this is a foo comment',
     937                        'comment_type'         => '',
     938                        'comment_parent'       => 0,
     939                        'user_id'              => $u,
     940                ) );
     941
     942                $a2 = bp_activity_new_comment( array(
     943                        'content'     => 'this should generate a new foo comment',
     944                        'user_id'     => $u,
     945                        'activity_id' => $a1,
     946                ) );
     947
     948                $activity_args = array(
     949                        'type'              => 'activity_comment',
     950                        'display_comments'  => 'stream',
     951                        'meta_query'        => array( array(
     952                                'key'       => 'bp_blogs_post_comment_id',
     953                                'compare'   => 'exists',
     954                        ) )
     955                );
     956
     957                $a = bp_activity_get( $activity_args );
     958                $aids = wp_list_pluck( $a['activities'], 'id' );
     959                $cids = wp_list_pluck( get_approved_comments( $p ), 'comment_ID' );
     960
     961                foreach ( $aids as $aid ) {
     962                        $this->assertTrue( in_array( bp_activity_get_meta( $aid, 'bp_blogs_post_comment_id' ), $cids ), 'The comment ID should be in the activity meta' );
     963                }
     964
     965                foreach ( $cids as $cid ) {
     966                        $this->assertTrue( in_array( get_comment_meta( $cid, 'bp_activity_comment_id', true ), $aids ), 'The activity ID should be in the comment meta' );
     967                }
     968
     969                _unregister_post_type( 'foo' );
     970
     971                if ( is_multisite() ) {
     972                        restore_current_blog();
     973                        remove_filter( 'comment_flood_filter', '__return_false' );
     974                }
     975
     976                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     977        }
     978
    835979        public function count_activity_comment_saved() {
    836980                $this->activity_saved_comment_count += 1;
    837981        }