Ticket #6482: 6482.03.patch
File 6482.03.patch, 120.7 KB (added by , 8 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..a278c70 100644
function bp_activity_catch_transition_post_type_status( $new_status, $old_status 831 831 } 832 832 } 833 833 add_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 */ 844 function 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 action 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 } 954 add_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..d92632a 100644
class BP_Activity_List_Table extends WP_List_Table { 1103 1103 1104 1104 // Option defaults. 1105 1105 $filter = array(); 1106 $filter_query = false; 1106 1107 $include_id = false; 1107 1108 $search_terms = false; 1108 1109 $sort = 'DESC'; … … class BP_Activity_List_Table extends WP_List_Table { 1129 1130 }*/ 1130 1131 1131 1132 // Filter. 1132 if ( ! empty( $_REQUEST['activity_type'] ) )1133 if ( ! empty( $_REQUEST['activity_type'] ) ) { 1133 1134 $filter = array( 'action' => $_REQUEST['activity_type'] ); 1134 1135 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 1135 1154 // Are we doing a search? 1136 1155 if ( !empty( $_REQUEST['s'] ) ) 1137 1156 $search_terms = $_REQUEST['s']; … … class BP_Activity_List_Table extends WP_List_Table { 1158 1177 'page' => $page, 1159 1178 'per_page' => $per_page, 1160 1179 'search_terms' => $search_terms, 1180 'filter_query' => $filter_query, 1161 1181 'show_hidden' => true, 1162 1182 // 'sort' => $sort, 1163 1183 'spam' => $spam, … … class BP_Activity_List_Table extends WP_List_Table { 1757 1777 * functions from working as intended. 1758 1778 * 1759 1779 * @since 2.0.0 1780 * @since 2.5.0 Include Post type activities types 1760 1781 * 1761 1782 * @param array $item An array version of the BP_Activity_Activity object. 1762 1783 * @return bool $can_comment 1763 1784 */ 1764 protected function can_comment( $item 1785 protected function can_comment( $item ) { 1765 1786 $can_comment = true; 1787 $bp = buddypress(); 1766 1788 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 $action => $tracking_args ) { 1806 if ( empty( $tracking_args->activity_comment ) ) { 1807 $maybe_turn_off[ $action ] = $turn_off; 1775 1808 } 1809 } 1776 1810 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'] ] ); 1794 1812 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; 1799 1815 1800 if ( empty( buddypress()->blogs->allow_comments[$item['id']] ) ) { 1801 $can_comment = false; 1802 } 1803 } 1816 if ( bp_activity_action_supports_comments_tracking( $item['type'] ) ) { 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 ); 1804 1827 } 1805 1828 } 1806 1829 -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 2ca8d9f..b67a4d0 100644
function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array 419 419 return false; 420 420 } 421 421 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 422 435 // 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 ) { 424 437 if ( ! empty( $args[ $label_type ] ) ) { 425 438 $wp_post_types[ $post_type ]->labels->{$label_type} = $args[ $label_type ]; 426 439 unset( $args[ $label_type ] ); … … function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array 437 450 * Get tracking arguments for a specific post type. 438 451 * 439 452 * @since 2.2.0 453 * @since 2.5.0 Add post type comments tracking args 440 454 * 441 455 * @param string $post_type Name of the post type. 442 456 * @return object The tracking arguments of the post type. … … function bp_activity_get_post_type_tracking_args( $post_type ) { 446 460 return false; 447 461 } 448 462 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' ); 450 465 451 466 $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', 460 477 ); 461 478 462 479 if ( ! empty( $post_type_object->bp_activity ) ) { … … function bp_activity_get_post_type_tracking_args( $post_type ) { 489 506 $post_type_activity->new_post_type_action_ms = $post_type_object->labels->bp_activity_new_post_ms; 490 507 } 491 508 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 action for comments 512 $post_type_activity->comments_tracking = new stdClass(); 513 514 // Build the activity action 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 492 552 /** 493 553 * Filters tracking arguments for a specific post type. 494 554 * … … function bp_activity_get_post_type_tracking_args( $post_type ) { 504 564 * Get tracking arguments for all post types. 505 565 * 506 566 * @since 2.2.0 567 * @since 2.5.0 Include post type comments tracking args if needed 507 568 * 508 569 * @return array List of post types with their tracking arguments. 509 570 */ … … function bp_activity_get_post_types_tracking_args() { 517 578 $track_post_type = bp_activity_get_post_type_tracking_args( $post_type ); 518 579 519 580 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 action (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 action (new_post_type) 589 $track_post_type->comments_tracking = true; 590 } 591 520 592 $post_types_tracking_args[ $track_post_type->action_id ] = $track_post_type; 521 593 } 522 594 … … function bp_activity_get_post_types_tracking_args() { 534 606 } 535 607 536 608 /** 609 * Helper function to check if the activity action is about a "parent" post type activity 610 * supporting comments tracking 611 * 612 * @since 2.5.0 613 * 614 * @param string $action_id the activity action to check 615 * @return bool true if it's a parent post type activity supporting comments 616 * false otherwise 617 */ 618 function bp_activity_action_is_post_tracking_action( $action_id ) { 619 if ( empty( $action_id ) ) { 620 return false; 621 } 622 623 $bp = buddypress(); 624 625 $retval = bp_activity_action_supports_comments_tracking( $action_id ); 626 627 if ( empty( $retval ) ) { 628 return $retval; 629 } 630 631 return ! empty( $bp->activity->track[ $action_id ]->comment_action_id ); 632 } 633 634 /** 635 * Helper function to check if the activity action is supporting comments tracking 636 * 637 * @since 2.5.0 638 * 639 * @param string $action_id the activity action to check 640 * @return bool true activity action supports comments tracking 641 * false otherwise 642 */ 643 function bp_activity_action_supports_comments_tracking( $action_id ) { 644 if ( empty( $action_id ) ) { 645 return false; 646 } 647 648 $bp = buddypress(); 649 650 // Set the activity track global if not set yet 651 if ( empty( $bp->activity->track ) ) { 652 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 653 } 654 655 return ! empty( $bp->activity->track[ $action_id ]->comments_tracking ); 656 } 657 658 /** 659 * Helper function to get the parent action out of a post type comment action 660 * 661 * eg: new_blog_comment > new_blog_post 662 * 663 * @since 2.5.0 664 * 665 * @param string $action_id the activity action to check 666 * @return array|object $parent_action the parent action post type tracking args 667 * empty array if not found 668 */ 669 function bp_activity_get_parent_post_type_action( $comment_action_id ) { 670 if ( empty( $comment_action_id ) ) { 671 return false; 672 } 673 674 $bp = buddypress(); 675 676 // Set the activity track global if not set yet 677 if ( empty( $bp->activity->track ) ) { 678 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 679 } 680 681 $parent_action = wp_list_filter( $bp->activity->track, array( 'comment_action_id' => $comment_action_id ) ); 682 683 return reset( $parent_action ); 684 } 685 686 /** 537 687 * Get all components' activity actions, sorted by their position attribute. 538 688 * 539 689 * @since 2.2.0 … … function bp_activity_format_activity_action_custom_post_type_post( $action, $act 1394 1544 return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity ); 1395 1545 } 1396 1546 1547 /** 1548 * Format activity action strings for custom post types comments. 1549 * 1550 * @since 2.5.0 1551 * 1552 * @param string $action Static activity action. 1553 * @param object $activity Activity data object. 1554 * 1555 * @return string 1556 */ 1557 function bp_activity_format_activity_action_custom_post_type_comment( $action, $activity ) { 1558 $bp = buddypress(); 1559 1560 // Fetch all the tracked post types once. 1561 if ( empty( $bp->activity->track ) ) { 1562 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1563 } 1564 1565 if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) { 1566 return $action; 1567 } 1568 1569 $user_link = bp_core_get_userlink( $activity->user_id ); 1570 1571 if ( is_multisite() ) { 1572 $blog_link = '<a href="' . esc_url( get_home_url( $activity->item_id ) ) . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>'; 1573 1574 if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_comment_action_ms ) ) { 1575 $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_comment_action_ms, $user_link, $activity->primary_link, $blog_link ); 1576 } else { 1577 $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 ); 1578 } 1579 } else { 1580 if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_comment_action ) ) { 1581 $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_comment_action, $user_link, $activity->primary_link ); 1582 } else { 1583 $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 ); 1584 } 1585 } 1586 1587 /** 1588 * Filters the formatted custom post type activity comment action string. 1589 * 1590 * @since 2.5.0 1591 * 1592 * @param string $action Activity action string value. 1593 * @param BP_Activity_Activity $activity Activity item object. 1594 */ 1595 return apply_filters( 'bp_activity_custom_post_type_comment_action', $action, $activity ); 1596 } 1597 1397 1598 /* 1398 1599 * Business functions are where all the magic happens in BuddyPress. They will 1399 1600 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_post_type_update( $post = null ) { 1982 2183 * Fires after the updating of an activity item for a custom post type entry. 1983 2184 * 1984 2185 * @since 2.2.0 2186 * @since 2.5.0 Add the post type tracking args parameter 1985 2187 * 1986 * @param WP_Post $post Post object. 1987 * @param BP_Activity_Activity $activity Activity object. 2188 * @param WP_Post $post Post object. 2189 * @param BP_Activity_Activity $activity Activity object. 2190 * @param object $activity_post_object The post type tracking args object. 1988 2191 */ 1989 do_action( 'bp_activity_post_type_updated', $post, $activity );2192 do_action( 'bp_activity_post_type_updated', $post, $activity, $activity_post_object ); 1990 2193 1991 2194 return $updated; 1992 2195 } … … function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 2042 2245 } 2043 2246 2044 2247 /** 2248 * Create an activity item for a newly posted post type comment. 2249 * 2250 * @since 2.5.0 2251 * 2252 * @param int $comment_id ID of the comment. 2253 * @param bool $is_approved Whether the comment is approved or not. 2254 * @param object $activity_post_object the post type tracking args object. 2255 * 2256 * @return int|bool The ID of the activity on success. False on error. 2257 */ 2258 function bp_activity_post_type_comment( $comment_id = 0, $is_approved = true, $activity_post_object = null ) { 2259 // Get the users comment 2260 $post_type_comment = get_comment( $comment_id ); 2261 2262 // Don't record activity if the comment hasn't been approved 2263 if ( empty( $is_approved ) ) { 2264 return false; 2265 } 2266 2267 // Don't record activity if no email address has been included 2268 if ( empty( $post_type_comment->comment_author_email ) ) { 2269 return false; 2270 } 2271 2272 // Don't record activity if the comment has already been marked as spam 2273 if ( 'spam' === $is_approved ) { 2274 return false; 2275 } 2276 2277 // Get the user by the comment author email. 2278 $user = get_user_by( 'email', $post_type_comment->comment_author_email ); 2279 2280 // If user isn't registered, don't record activity 2281 if ( empty( $user ) ) { 2282 return false; 2283 } 2284 2285 // Get the user_id 2286 $user_id = (int) $user->ID; 2287 2288 // Get blog and post data 2289 $blog_id = get_current_blog_id(); 2290 2291 // Get the post 2292 $post_type_comment->post = get_post( $post_type_comment->comment_post_ID ); 2293 2294 if ( ! is_a( $post_type_comment->post, 'WP_Post' ) ) { 2295 return false; 2296 } 2297 2298 /** 2299 * Filters whether to publish activities about the comment regarding the post status 2300 * 2301 * @since 2.5.0 2302 * 2303 * @param bool true to bail, false otherwise. 2304 */ 2305 $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 ) ); 2306 2307 // If this is a password protected post, or not a public post don't record the comment 2308 if ( $is_post_status_not_allowed ) { 2309 return false; 2310 } 2311 2312 // Set post type 2313 $post_type = $post_type_comment->post->post_type; 2314 2315 if ( empty( $activity_post_object ) ) { 2316 // Get the post type tracking args. 2317 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 2318 2319 // Bail if the activity action does not exist 2320 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 2321 return false; 2322 } 2323 } 2324 2325 // Set the $activity_comment_object 2326 $activity_comment_object = $activity_post_object->comments_tracking; 2327 2328 /** 2329 * Filters whether or not to post the activity about the comment. 2330 * 2331 * This is a variable filter, dependent on the post type, 2332 * that lets components or plugins bail early if needed. 2333 * 2334 * @since 2.5.0 2335 * 2336 * @param bool $value Whether or not to continue. 2337 * @param int $blog_id ID of the current site. 2338 * @param int $post_id ID of the current post being commented. 2339 * @param int $user_id ID of the current user. 2340 * @param int $comment_id ID of the current comment being posted. 2341 */ 2342 if ( false === apply_filters( "bp_activity_{$post_type}_pre_comment", true, $blog_id, $post_type_comment->post->ID, $user_id, $comment_id ) ) { 2343 return false; 2344 } 2345 2346 // Is this an update ? 2347 $activity_id = bp_activity_get_activity_id( array( 2348 'user_id' => $user_id, 2349 'component' => $activity_comment_object->component_id, 2350 'type' => $activity_comment_object->action_id, 2351 'item_id' => $blog_id, 2352 'secondary_item_id' => $comment_id, 2353 ) ); 2354 2355 // Record this in activity streams. 2356 $comment_link = get_comment_link( $post_type_comment->comment_ID ); 2357 2358 // Backward compatibility filters for the 'blogs' component. 2359 if ( 'blogs' == $activity_comment_object->component_id ) { 2360 $activity_content = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $post_type_comment->comment_content, &$post_type_comment, $comment_link ) ); 2361 $activity_primary_link = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$post_type_comment ) ); 2362 } else { 2363 $activity_content = $post_type_comment->comment_content; 2364 $activity_primary_link = $comment_link; 2365 } 2366 2367 $activity_args = array( 2368 'id' => $activity_id, 2369 'user_id' => $user_id, 2370 'content' => $activity_content, 2371 'primary_link' => $activity_primary_link, 2372 'component' => $activity_comment_object->component_id, 2373 'recorded_time' => $post_type_comment->comment_date_gmt, 2374 ); 2375 2376 if ( bp_disable_blogforum_comments() ) { 2377 $blog_url = get_home_url( $blog_id ); 2378 $post_url = add_query_arg( 2379 'p', 2380 $post_type_comment->post->ID, 2381 trailingslashit( $blog_url ) 2382 ); 2383 2384 $activity_args['type'] = $activity_comment_object->action_id; 2385 $activity_args['item_id'] = $blog_id; 2386 $activity_args['secondary_item_id'] = $post_type_comment->comment_ID; 2387 2388 if ( ! empty( $activity_args['content'] ) ) { 2389 // Create the excerpt. 2390 $activity_summary = bp_activity_create_summary( $activity_args['content'], $activity_args ); 2391 2392 // Backward compatibility filter for blog comments. 2393 if ( 'blogs' == $activity_post_object->component_id ) { 2394 $activity_args['content'] = apply_filters( 'bp_blogs_record_activity_content', $activity_summary, $activity_args['content'], $activity_args, $post_type ); 2395 } else { 2396 $activity_args['content'] = $activity_summary; 2397 } 2398 } 2399 2400 // Set up the action by using the format functions. 2401 $action_args = array_merge( $activity_args, array( 2402 'post_title' => $post_type_comment->post->post_title, 2403 'post_url' => $post_url, 2404 'blog_url' => $blog_url, 2405 'blog_name' => get_blog_option( $blog_id, 'blogname' ), 2406 ) ); 2407 2408 $activity_args['action'] = call_user_func_array( $activity_comment_object->format_callback, array( '', (object) $action_args ) ); 2409 2410 // Make sure the action is set. 2411 if ( empty( $activity_args['action'] ) ) { 2412 return; 2413 } else { 2414 // Backward compatibility filter for the blogs component. 2415 if ( 'blogs' === $activity_post_object->component_id ) { 2416 $activity_args['action'] = apply_filters( 'bp_blogs_record_activity_action', $activity_args['action'] ); 2417 } 2418 } 2419 2420 $activity_id = bp_activity_add( $activity_args ); 2421 } 2422 2423 /** 2424 * Fires after the publishing of an activity item for a newly published post type post. 2425 * 2426 * @since 2.5.0 2427 * 2428 * @param int $activity_id ID of the newly published activity item. 2429 * @param WP_Comment $post_type_comment Comment object. 2430 * @param array $activity_args Array of activity arguments. 2431 * @param object $activity_post_object the post type tracking args object. 2432 */ 2433 do_action_ref_array( 'bp_activity_post_type_comment', array( &$activity_id, $post_type_comment, $activity_args, $activity_post_object ) ); 2434 2435 return $activity_id; 2436 } 2437 add_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 2438 add_action( 'edit_comment', 'bp_activity_post_type_comment', 10 ); 2439 2440 /** 2441 * Remove an activity item when a comment about a post type is deleted. 2442 * 2443 * @since 2.5.0 2444 * 2445 * @param int $comment_id ID of the comment. 2446 * @param object $activity_post_object The post type tracking args object. 2447 * 2448 * @return bool True on success. False on error. 2449 */ 2450 function bp_activity_post_type_remove_comment( $comment_id = 0, $activity_post_object = null ) { 2451 if ( empty( $activity_post_object ) ) { 2452 $comment = get_comment( $comment_id ); 2453 if ( ! $comment ) { 2454 return; 2455 } 2456 2457 $post_type = get_post_type( $comment->comment_post_ID ); 2458 if ( ! $post_type ) { 2459 return; 2460 } 2461 2462 // Get the post type tracking args. 2463 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 2464 2465 // Bail if the activity action does not exist 2466 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 2467 return false; 2468 } 2469 } 2470 2471 // Set the $activity_comment_object 2472 $activity_comment_object = $activity_post_object->comments_tracking; 2473 2474 if ( empty( $activity_comment_object->action_id ) ) { 2475 return false; 2476 } 2477 2478 $deleted = false; 2479 2480 if ( bp_disable_blogforum_comments() ) { 2481 $deleted = bp_activity_delete_by_item_id( array( 2482 'item_id' => get_current_blog_id(), 2483 'secondary_item_id' => $comment_id, 2484 'component' => $activity_comment_object->component_id, 2485 'type' => $activity_comment_object->action_id, 2486 'user_id' => false, 2487 ) ); 2488 } 2489 2490 /** 2491 * Fires after the custom post type comment activity was removed. 2492 * 2493 * @since 2.5.0 2494 * 2495 * @param bool $deleted True if the activity was deleted false otherwise 2496 * @param WP_Comment $comment Comment object. 2497 * @param object $activity_post_object The post type tracking args object. 2498 * @param string $value The post type comment activity type. 2499 */ 2500 do_action( 'bp_activity_post_type_remove_comment', $deleted, $comment_id, $activity_post_object, $activity_comment_object->action_id ); 2501 2502 return $deleted; 2503 } 2504 add_action( 'delete_comment', 'bp_activity_post_type_remove_comment', 10, 1 ); 2505 2506 /** 2507 * Get all activity comments corresponding to Post type synced comments 2508 * and reset the bp_parent_action activity meta. 2509 * 2510 * Used in the 2.5.0 upgrade routine as we need to make sure filtering the activities 2511 * for new_blog_comment is getting activity_comment types having a new_blog_post activity 2512 * type as their parent activity. It can also be used as a repair tool too, if needed. 2513 * 2514 * @since 2.5.0 2515 */ 2516 function bp_activity_post_type_comment_reset_parent_meta() { 2517 /** 2518 * First get all activities associated to a Post type comment ID 2519 * without a bp_parent_action meta set. 2520 */ 2521 $synced_post_comments = bp_activity_get( array( 2522 'type' => 'activity_comment', 2523 'display_comments' => 'stream', 2524 'per_page' => false, 2525 'meta_query' => array( 2526 'relation' => 'AND', 2527 array( 2528 'key' => 'bp_blogs_post_comment_id', 2529 'compare' => 'EXISTS', 2530 ), 2531 array( 2532 'key' => 'bp_parent_action', 2533 'compare' => 'NOT EXISTS', 2534 ), 2535 ) 2536 ) ); 2537 2538 if ( empty( $synced_post_comments['activities'] ) ) { 2539 return; 2540 } 2541 2542 // Prepare the 'in' parameter to get the parent activity types 2543 $parent_activities = array_unique( wp_list_pluck( $synced_post_comments['activities'], 'item_id' ) ); 2544 2545 $parent_activity_types = bp_activity_get( array( 2546 'per_page' => false, 2547 'in' => $parent_activities, 2548 ) ); 2549 2550 if ( empty( $parent_activity_types['activities'] ) ) { 2551 return; 2552 } 2553 2554 // Build the list of parent activity types 2555 $parent_activity_types = wp_list_pluck( $parent_activity_types['activities'], 'type', 'id' ); 2556 2557 // Loop through each activity and set the 'bp_parent_action' if needed 2558 foreach ( $synced_post_comments['activities'] as $synced_post_comment ) { 2559 if ( isset( $parent_activity_types[ $synced_post_comment->item_id ] ) ) { 2560 bp_activity_update_meta( $synced_post_comment->id, 'bp_parent_action', $parent_activity_types[ $synced_post_comment->item_id ] ); 2561 } 2562 } 2563 } 2564 2565 /** 2045 2566 * Add an activity comment. 2046 2567 * 2047 2568 * @since 1.2.0 2569 * @since 2.5.0 Add a new possible parameter $skip_notification for the array of arguments. 2570 * Add the $primary_link parameter for the array of arguments. 2048 2571 * 2049 2572 * @uses wp_parse_args() 2050 2573 * @uses bp_activity_add() … … function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 2054 2577 * @uses do_action() To call the 'bp_activity_comment_posted' hook. 2055 2578 * 2056 2579 * @param array|string $args { 2057 * @type int $id Optional. Pass an ID to update an existing comment. 2058 * @type string $content The content of the comment. 2059 * @type int $user_id Optional. The ID of the user making the comment. 2060 * Defaults to the ID of the logged-in user. 2061 * @type int $activity_id The ID of the "root" activity item, ie the oldest 2062 * ancestor of the comment. 2063 * @type int $parent_id Optional. The ID of the parent activity item, ie the item to 2064 * which the comment is an immediate reply. If not provided, 2065 * this value defaults to the $activity_id. 2580 * @type int $id Optional. Pass an ID to update an existing comment. 2581 * @type string $content The content of the comment. 2582 * @type int $user_id Optional. The ID of the user making the comment. 2583 * Defaults to the ID of the logged-in user. 2584 * @type int $activity_id The ID of the "root" activity item, ie the oldest 2585 * ancestor of the comment. 2586 * @type int $parent_id Optional. The ID of the parent activity item, ie the item to 2587 * which the comment is an immediate reply. If not provided, 2588 * this value defaults to the $activity_id. 2589 * @type string $primary_link Optional. the primary link for the comment. 2590 * Defaults to an empty string. 2591 * @type bool $skip_notification Optional. false to send a comment notification, false otherwise. 2592 * Defaults to false. 2066 2593 * } 2067 2594 * @return int|bool The ID of the comment on success, otherwise false. 2068 2595 */ … … function bp_activity_new_comment( $args = '' ) { 2076 2603 } 2077 2604 2078 2605 $r = wp_parse_args( $args, array( 2079 'id' => false, 2080 'content' => false, 2081 'user_id' => bp_loggedin_user_id(), 2082 'activity_id' => false, // ID of the root activity item. 2083 'parent_id' => false // ID of a parent comment (optional). 2606 'id' => false, 2607 'content' => false, 2608 'user_id' => bp_loggedin_user_id(), 2609 'activity_id' => false, // ID of the root activity item. 2610 'parent_id' => false, // ID of a parent comment (optional). 2611 'primary_link' => '', 2612 'skip_notification' => false, 2084 2613 ) ); 2085 2614 2086 2615 // Bail if missing necessary data. … … function bp_activity_new_comment( $args = '' ) { 2127 2656 'content' => $comment_content, 2128 2657 'component' => buddypress()->activity->id, 2129 2658 'type' => 'activity_comment', 2659 'primary_link' => $r['primary_link'], 2130 2660 'user_id' => $r['user_id'], 2131 2661 'item_id' => $activity_id, 2132 2662 'secondary_item_id' => $r['parent_id'], … … function bp_activity_new_comment( $args = '' ) { 2145 2675 } 2146 2676 wp_cache_delete( $activity_id, 'bp_activity' ); 2147 2677 2148 /** 2149 * Fires near the end of an activity comment posting, before the returning of the comment ID. 2150 * 2151 * @since 1.2.0 2152 * 2153 * @param int $comment_id ID of the newly posted activity comment. 2154 * @param array $r Array of parsed comment arguments. 2155 * @param BP_Activity_Activity $activity Activity item being commented on. 2156 */ 2157 do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity ); 2678 if ( empty( $r[ 'skip_notification' ] ) ) { 2679 /** 2680 * Fires near the end of an activity comment posting, before the returning of the comment ID. 2681 * Sends a notification to the user @see bp_activity_new_comment_notification_helper(). 2682 * 2683 * @since 1.2.0 2684 * 2685 * @param int $comment_id ID of the newly posted activity comment. 2686 * @param array $r Array of parsed comment arguments. 2687 * @param int $activity ID of the activity item being commented on. 2688 */ 2689 do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity ); 2690 } else { 2691 /** 2692 * Fires near the end of an activity comment posting, before the returning of the comment ID. 2693 * without sending a notification to the user 2694 * 2695 * @since 2.5.0 2696 * 2697 * @param int $comment_id ID of the newly posted activity comment. 2698 * @param array $r Array of parsed comment arguments. 2699 * @param int $activity ID of the activity item being commented on. 2700 */ 2701 do_action( 'bp_activity_comment_posted_notification_skipped', $comment_id, $r, $activity ); 2702 } 2158 2703 2159 2704 if ( empty( $comment_id ) ) { 2160 2705 $errors->add( 'comment_failed', $feedback ); … … function bp_activity_delete( $args = '' ) { 2423 2968 * @return bool True on success, false on failure. 2424 2969 */ 2425 2970 function bp_activity_delete_comment( $activity_id, $comment_id ) { 2971 $deleted = false; 2426 2972 2427 2973 /** 2428 2974 * Filters whether BuddyPress should delete an activity comment or not. … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 2431 2977 * handle the deletion of child comments differently. Make sure you return false. 2432 2978 * 2433 2979 * @since 1.2.0 2980 * @since 2.5.0 Add the deleted parameter (passed by reference) 2434 2981 * 2435 2982 * @param bool $value Whether BuddyPress should continue or not. 2436 2983 * @param int $activity_id ID of the root activity item being deleted. 2437 2984 * @param int $comment_id ID of the comment being deleted. 2438 2985 */ 2439 if ( ! apply_filters ( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id) ) {2440 return false;2986 if ( ! apply_filters_ref_array( 'bp_activity_delete_comment_pre', array( true, $activity_id, $comment_id, &$deleted ) ) ) { 2987 return $deleted; 2441 2988 } 2442 2989 2443 2990 // Delete any children of this comment. … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 2446 2993 // Delete the actual comment. 2447 2994 if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) { 2448 2995 return false; 2996 } else { 2997 $deleted = true; 2449 2998 } 2450 2999 2451 3000 // Purge comment cache for the root activity update. … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 2464 3013 */ 2465 3014 do_action( 'bp_activity_delete_comment', $activity_id, $comment_id ); 2466 3015 2467 return true;3016 return $deleted; 2468 3017 } 2469 3018 2470 3019 /** -
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..dab8af8 100644
function bp_blogs_register_activity_actions() { 37 37 ); 38 38 } 39 39 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 1050 );51 }52 53 40 /** 54 41 * Fires after the registry of the default blog component activity actions. 55 42 * … … function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) { 218 205 * @return string Constructed activity action. 219 206 */ 220 207 function 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' ); 208 /** 209 * When the comment is published we are faking an activity object 210 * to which we add 4 properties : 211 * - the post url 212 * - the post title 213 * - the blog url 214 * - the blog name 215 * This is done to build the 'post link' part of the activity 216 * action string. 217 * NB: in this case the activity has not yet been created. 218 */ 219 220 $blog_url = false; 221 222 // Try to get the blog url from the activity object 223 if ( isset( $activity->blog_url ) ) { 224 $blog_url = $activity->blog_url; 225 } else { 226 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 227 } 228 229 $blog_name = false; 230 231 // Try to get the blog name from the activity object 232 if ( isset( $activity->blog_name ) ) { 233 $blog_name = $activity->blog_name; 234 } else { 235 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 236 } 223 237 224 238 if ( empty( $blog_url ) || empty( $blog_name ) ) { 225 239 $blog_url = get_home_url( $activity->item_id ); … … function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) 229 243 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 230 244 } 231 245 232 $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 233 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 246 $post_url = false; 247 248 // Try to get the post url from the activity object 249 if ( isset( $activity->post_url ) ) { 250 $post_url = $activity->post_url; 251 252 /** 253 * The post_url property is not set, we need to build the url 254 * thanks to the post id which is also saved as the secondary 255 * item id property of the activity object. 256 */ 257 } elseif ( ! empty( $activity->id ) ) { 258 $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 259 } 260 261 $post_title = false; 262 263 // Should be the case when the comment has just been published 264 if ( isset( $activity->post_title ) ) { 265 $post_title = $activity->post_title; 266 267 // If activity already exists try to get the post title from activity meta 268 } elseif ( ! empty( $activity->id ) ) { 269 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 270 } 234 271 235 272 // Should only be empty at the time of post creation. 236 273 if ( empty( $post_url ) || empty( $post_title ) ) { … … function bp_blogs_comments_open( $activity ) { 522 559 * 523 560 * Note: This is only a one-way sync - activity comments -> blog comment. 524 561 * 525 * For blog post -> activity comment, see {@link bp_ blogs_record_comment()}.562 * For blog post -> activity comment, see {@link bp_activity_post_type_comment()}. 526 563 * 527 564 * @since 2.0.0 565 * @since 2.5.0 Allow custom post types to sync their comments with activity ones 528 566 * 529 567 * @param int $comment_id The activity ID for the posted activity comment. 530 568 * @param array $params Parameters for the activity comment. 531 569 * @param object $parent_activity Parameters of the parent activity item (in this case, the blog post). 532 570 */ 533 571 function 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') {572 // if parent activity isn't a post type having the buddypress-activity support, stop now! 573 if ( ! bp_activity_action_supports_comments_tracking( $parent_activity->type ) ) { 536 574 return; 537 575 } 538 576 … … function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 565 603 'comment_type' => '', // Could be interesting to add 'buddypress' here... 566 604 'comment_parent' => (int) $comment_parent, 567 605 'user_id' => $params['user_id'], 568 569 // Commenting these out for now570 // 'comment_author_IP' => '127.0.0.1',571 // 'comment_agent' => '', .572 606 'comment_approved' => 1 573 607 ); 574 608 575 609 // Prevent separate activity entry being made. 576 remove_action( 'comment_post', 'bp_ blogs_record_comment', 10, 2 );610 remove_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 577 611 578 612 // Handle multisite. 579 613 switch_to_blog( $parent_activity->item_id ); … … function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 590 624 591 625 // Add meta to activity comment. 592 626 bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); 627 bp_activity_update_meta( $comment_id, 'bp_parent_action', $parent_activity->type ); 593 628 594 629 // Resave activity comment with WP comment permalink. 595 630 // … … function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 616 651 restore_current_blog(); 617 652 618 653 // Add the comment hook back. 619 add_action( 'comment_post', 'bp_ blogs_record_comment', 10, 2 );654 add_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 620 655 621 656 /** 622 657 * 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 640 675 * activity comment children before they are deleted. 641 676 * 642 677 * @since 2.0.0 678 * @since 2.5.0 Add the $delected parameter 643 679 * 644 680 * @param bool $retval Whether BuddyPress should continue or not. 645 681 * @param int $parent_activity_id The parent activity ID for the activity comment. 646 682 * @param int $activity_id The activity ID for the pending deleted activity comment. 683 * @param bool $deleted Whether the comment was deleted or not. 647 684 * @return bool 648 685 */ 649 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {686 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id, &$deleted ) { 650 687 // Check if parent activity is a blog post. 651 688 $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 652 if ( 'new_blog_post' != $parent_activity->type ) { 689 690 // if parent activity isn't a post type having the buddypress-activity support, stop now! 691 if ( ! bp_activity_action_supports_comments_tracking( $parent_activity->type ) ) { 653 692 return $retval; 654 693 } 655 694 … … function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_i 657 696 $activity = bp_activity_get( array( 658 697 'in' => $activity_id, 659 698 'display_comments' => 'stream', 699 'spam' => 'all', 660 700 ) ); 661 701 662 702 // Get all activity comment IDs for the pending deleted item. … … function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_i 677 717 // emulate bp_activity_delete_comment(). 678 718 BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 679 719 720 // Avoid the error message although the comments were successfully deleted 721 $deleted = true; 722 680 723 // We're overriding the default bp_activity_delete_comment() functionality 681 724 // so we need to return false. 682 725 return false; 683 726 } 684 add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 3);727 add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 4 ); 685 728 686 729 /** 687 730 * Updates the blog comment when the associated activity comment is edited. … … add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activit 691 734 * @param BP_Activity_Activity $activity The activity object. 692 735 */ 693 736 function 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 699 737 // This is a new entry, so stop! 700 738 // We only want edits! 701 if ( empty( $activity->id ) ) {739 if ( empty( $activity->id ) || bp_disable_blogforum_comments() ) { 702 740 return; 703 741 } 704 742 705 // Prevent recursion. 706 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 743 // fetch parent activity item 744 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 745 746 // if parent activity isn't a post type having the buddypress-activity support for comments, stop now! 747 if ( ! bp_activity_action_supports_comments_tracking( $parent_activity->type ) ) { 748 return; 749 } 707 750 708 751 // Try to see if a corresponding blog comment exists. 709 752 $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 712 755 return; 713 756 } 714 757 715 // Fetch parent activity item.716 $parent_acti vity = new BP_Activity_Activity( $activity->item_id);758 // Get the parent action 759 $parent_action = bp_activity_get_meta( $activity->id, 'bp_parent_action' ); 717 760 718 761 // Sanity check. 719 if ( 'new_blog_post'!== $parent_activity->type ) {762 if ( $parent_action !== $parent_activity->type ) { 720 763 return; 721 764 } 722 765 723 766 // Handle multisite. 724 767 switch_to_blog( $parent_activity->item_id ); 725 768 726 // Update the blog post comment. 727 wp_update_comment( array( 728 'comment_ID' => $post_comment_id, 729 'comment_content' => $activity->content 730 ) ); 769 // Get the comment status 770 $post_comment_status = wp_get_comment_status( $post_comment_id ); 771 $old_comment_status = $post_comment_status; 772 773 // No need to edit the activity, as it's the activity who's updating the comment 774 remove_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); 775 remove_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4 ); 776 777 if ( 1 === (int) $activity->is_spam && 'spam' !== $post_comment_status ) { 778 wp_spam_comment( $post_comment_id ); 779 } elseif ( ! $activity->is_spam ) { 780 if ( 'spam' === $post_comment_status ) { 781 wp_unspam_comment( $post_comment_id ); 782 } elseif ( 'trash' === $post_comment_status ) { 783 wp_untrash_comment( $post_comment_id ); 784 } else { 785 // Update the blog post comment. 786 wp_update_comment( array( 787 'comment_ID' => $post_comment_id, 788 'comment_content' => $activity->content, 789 ) ); 790 } 791 } 792 793 // Restore actions 794 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); 795 add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4 ); 731 796 732 797 restore_current_blog(); 733 798 } … … add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_ 775 840 * API. 776 841 * 777 842 * @since 2.1.0 843 * @since 2.5.0 Used for any synced Post type comments, in wp-admin or front-end contexts. 778 844 * 779 845 * @param array $args Arguments passed from bp_parse_args() in bp_has_activities(). 780 846 * @return array $args … … function bp_blogs_new_blog_comment_query_backpat( $args ) { 783 849 global $wpdb; 784 850 $bp = buddypress(); 785 851 786 // Bail if this is not a 'new_blog_comment' query. 787 if ( 'new_blog_comment' !== $args['action'] ) { 852 // if activity comments are disabled for blog posts, stop now! 853 if ( bp_disable_blogforum_comments() ) { 854 return $args; 855 } 856 857 // Get the parent action 858 $parent_action = bp_activity_get_parent_post_type_action( $args['action'] ); 859 860 // Bail if this is not a 'new_blog_comment' query 861 if ( empty( $parent_action->action_id ) ) { 788 862 return $args; 789 863 } 790 864 791 865 // 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') );866 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = 'bp_parent_action' AND meta_value = %s", $parent_action->action_id ) ); 793 867 794 868 if ( empty( $activity_ids ) ) { 795 869 return $args; … … function bp_blogs_new_blog_comment_query_backpat( $args ) { 798 872 // Init the filter query. 799 873 $filter_query = array(); 800 874 801 if ( 'null' === $args['scope'] ) {875 if ( ! isset( $args['scope'] ) || 'null' === $args['scope'] ) { 802 876 $args['scope'] = ''; 803 877 } elseif ( 'just-me' === $args['scope'] ) { 804 878 $filter_query = array( … … function bp_blogs_new_blog_comment_query_backpat( $args ) { 831 905 832 906 // Finally reset the action. 833 907 $args['action'] = ''; 908 $args['type'] = ''; 834 909 835 910 // Return the original arguments. 836 911 return $args; 837 912 } 838 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); 913 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); 914 add_filter( 'bp_activity_list_table_filter_activity_type_items', 'bp_blogs_new_blog_comment_query_backpat' ); 839 915 840 916 /** 841 917 * Utility function to set up some variables for use in the activity loop. … … function bp_blogs_setup_activity_loop_globals( $activity ) { 857 933 return; 858 934 } 859 935 860 // Parent not a blog post? stop now!861 if ( 'new_blog_post' !== $activity->type) {936 // parent not a post post type action ? stop now! 937 if ( ! bp_activity_action_is_post_tracking_action( $activity->type ) ) { 862 938 return; 863 939 } 864 940 … … function bp_blogs_disable_activity_commenting( $retval ) { 940 1016 return $retval; 941 1017 } 942 1018 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; 1019 $action = bp_get_activity_action_name(); 952 1020 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' : 1021 // It's a post type action supporting comment tracking 1022 if ( bp_activity_action_supports_comments_tracking( $action ) ) { 1023 // it's a "post" action 1024 if ( bp_activity_action_is_post_tracking_action( $action ) ) { 956 1025 global $activities_template; 957 1026 958 1027 // Setup some globals we'll need to reference later. … … function bp_blogs_disable_activity_commenting( $retval ) { 960 1029 961 1030 // If comments are closed for the WP blog post, we should disable 962 1031 // activity comments for this activity entry. 963 if ( empty( buddypress()->blogs->allow_comments[ bp_get_activity_id()] ) ) {1032 if ( empty( buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) ) { 964 1033 $retval = false; 965 1034 } 966 967 break; 1035 // It's a "comment" action 1036 } else { 1037 $retval = false; 1038 } 968 1039 } 969 1040 970 1041 return $retval; … … function bp_blogs_disable_activity_commenting( $retval ) { 972 1043 add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' ); 973 1044 974 1045 /** 1046 * Limit the display of post type synced comments. 1047 * 1048 * @since 2.5.0 1049 * 1050 * When viewing the synced comments in stream mode, this prevents comments to 1051 * be displayed twice, and avoids a Javascript error as the form to add replies 1052 * is not available. 1053 * 1054 * @param int $retval The comment count for the activity. 1055 * @return int The comment count, or 0 to hide activity comment replies. 1056 */ 1057 function bp_blogs_post_type_comments_avoid_duplicates( $retval ) { 1058 /** 1059 * Only limit the display when Post type comments are synced with 1060 * activity comments. 1061 */ 1062 if ( bp_disable_blogforum_comments() ) { 1063 return $retval; 1064 } 1065 1066 if ( 'activity_comment' !== bp_get_activity_action_name() ) { 1067 return $retval; 1068 } 1069 1070 if ( true === (bool) bp_activity_get_meta( bp_get_activity_id(), 'bp_blogs_post_comment_id' ) ) { 1071 $retval = 0; 1072 } 1073 1074 return $retval; 1075 } 1076 add_filter( 'bp_activity_get_comment_count', 'bp_blogs_post_type_comments_avoid_duplicates' ); 1077 1078 /** 975 1079 * Check if an activity comment associated with a blog post can be replied to. 976 1080 * 977 1081 * By default, disables replying to activity comments if the corresponding WP … … function bp_blogs_activity_comment_single_action( $retval, $activity ) { 1083 1187 return $retval; 1084 1188 } 1085 1189 1190 $bp = buddypress(); 1086 1191 $blog_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); 1087 1192 1088 1193 if ( ! empty( $blog_comment_id ) ) { … … function bp_blogs_activity_comment_single_action( $retval, $activity ) { 1098 1203 // Override 'secondary_item_id' to use comment ID. 1099 1204 $object->secondary_item_id = $blog_comment_id; 1100 1205 1101 // Now format the activity action using the 'new_blog_comment' action callback. 1102 $retval = bp_blogs_format_activity_action_new_blog_comment( '', $object ); 1206 // Set the activity track global if not set yet 1207 if ( empty( $bp->activity->track ) ) { 1208 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1209 } 1210 1211 // Use the fallback of the action 1212 if ( ! empty( $bp->activity->track[ $parent_blog_post_activity->type ]->comment_action_id ) ) { 1213 $object->type = $bp->activity->track[ $parent_blog_post_activity->type ]->comment_action_id; 1214 1215 // now format the activity action using the 'new_blog_comment' action callback 1216 $retval = call_user_func_array( $bp->activity->track[ $object->type ]->format_callback, array( '', $object ) ); 1217 1218 /** 1219 * Reset the activity type to 'activity_comment' 1220 * so that the "View Conversation" button appears 1221 */ 1222 $object->type = 'activity_comment'; 1223 } 1103 1224 } 1104 1225 1105 1226 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 ) { 61 61 } 62 62 63 63 /** 64 * Check whether the current post can be published.64 * Check whether the current activity about a post or a comment can be published. 65 65 * 66 66 * Abstracted from the deprecated `bp_blogs_record_post()`. 67 67 * … … function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, 121 121 return $return; 122 122 } 123 123 add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 ); 124 add_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..c692f9e 100644
add_action( 'bp_activity_post_type_published', 'bp_blogs_publish_post_activity_m 477 477 * Updates a blog post's activity meta entry during a post edit. 478 478 * 479 479 * @since 2.2.0 480 * @since 2.5.0 Add the post type tracking args object parameter 480 481 * 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. 483 485 */ 484 function bp_blogs_update_post_activity_meta( $post, $activity ) {485 if ( empty( $activity->id ) || 'post' != $post->post_type) {486 function bp_blogs_update_post_activity_meta( $post, $activity, $activity_post_object ) { 487 if ( empty( $activity->id ) || empty( $activity_post_object->action_id ) ) { 486 488 return; 487 489 } 488 490 … … function bp_blogs_update_post_activity_meta( $post, $activity ) { 491 493 if ( $post->post_title !== $existing_title ) { 492 494 bp_activity_update_meta( $activity->id, 'post_title', $post->post_title ); 493 495 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 } 531 524 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 } 536 539 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 } 541 545 } 542 }543 546 544 unset( $activities, $activity_ids, $comment_ids, $comments ); 547 unset( $activities, $activity_ids, $comment_ids, $comments ); 548 } 545 549 } 546 550 } 547 551 … … function bp_blogs_update_post_activity_meta( $post, $activity ) { 552 556 bp_activity_delete_meta( $activity->id, 'post_comment_status' ); 553 557 } 554 558 } 555 add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 2);559 add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 3 ); 556 560 557 561 /** 558 * Record a new blog comment in the BuddyPress activity stream.562 * Update Activity and blogs meta and eventually sync comment with activity comment 559 563 * 560 * Only posts the item if blog is public and post is not password-protected.564 * @since 2.5.0 561 565 * 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. 566 571 */ 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 ) ) 572 function 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 ) ) { 578 574 return false; 575 } 579 576 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. 599 578 $blog_id = get_current_blog_id(); 600 579 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 } 643 586 644 // Record the activity entry.645 $activity_id = bp_blogs_record_activity( $args );587 // Sync comment - activity comment 588 if ( ! bp_disable_blogforum_comments() ) { 646 589 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 ); 650 592 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; 662 595 } 596 } 663 597 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 665 604 $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, 668 607 'item_id' => $blog_id, 669 'secondary_item_id' => $ recorded_comment->comment_post_ID608 'secondary_item_id' => $comment->comment_post_ID 670 609 ) ); 671 610 672 611 // Try to create a new activity item for the parent blog post. 673 612 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 ); 675 614 } 615 } 676 616 677 // We found the parent activity entry678 // so let's go ahead and reconfigure some activity args.679 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; 682 622 683 // Now see if the WP parent comment has a BP activity ID.684 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 } 688 628 689 690 // so set to 'new_blog_post' activity ID.691 692 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 } 694 634 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; 698 637 699 // Could not find corresponding parent activity entry700 // so wipe out $args array.701 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 } 704 643 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" action 654 * eg: the "parent" action 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 action 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_action', $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( '/' ) ) ) ); 723 669 } 724 670 } 725 671 } 672 } 726 673 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() ); 729 688 } 730 689 731 return $ recorded_comment;690 return $activity_id; 732 691 } 733 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 734 add_action( 'edit_comment', 'bp_blogs_record_comment', 10 ); 692 add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4 ); 735 693 736 694 /** 737 695 * Record a user's association with a blog. … … function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) { 984 942 add_action( 'delete_post', 'bp_blogs_remove_post' ); 985 943 986 944 /** 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. 988 953 * 989 * @ param int $comment_id ID of the comment to be removed.954 * @return bool True on success. False on error. 990 955 */ 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. 956 function 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 1008 960 $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 1009 961 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 1015 968 $activity = bp_activity_get( array( 1016 969 'in' => $activity_id, 1017 970 'display_comments' => 'stream', 1018 971 'spam' => 'all', 1019 972 ) ); 1020 973 1021 // Get all activity comment IDs for the pending deleted item.974 // get all activity comment IDs for the pending deleted item 1022 975 if ( ! empty( $activity['activities'] ) ) { 1023 976 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 1024 977 $activity_ids[] = $activity_id; 1025 978 1026 // Delete activity items.979 // delete activity items 1027 980 foreach ( $activity_ids as $activity_id ) { 1028 981 bp_activity_delete( array( 1029 982 'id' => $activity_id 1030 983 ) ); 1031 984 } 1032 985 1033 // Remove associated blog comments.986 // remove associated blog comments 1034 987 bp_blogs_remove_associated_blog_comments( $activity_ids ); 1035 988 1036 // Rebuild activity comment tree.989 // rebuild activity comment tree 1037 990 BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 991 992 // Set the result 993 $deleted = true; 1038 994 } 1039 995 } 1040 996 } 1041 997 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; 1052 1013 } 1053 add_action( ' delete_comment', 'bp_blogs_remove_comment');1014 add_action( 'bp_activity_post_type_remove_comment', 'bp_blogs_post_type_remove_comment', 10, 4 ); 1054 1015 1055 1016 /** 1056 1017 * Removes blog comments that are associated with activity comments. 1057 1018 * 1058 1019 * @since 2.0.0 1059 1020 * 1060 * @see bp_blogs_remove_ comment()1021 * @see bp_blogs_remove_synced_comment() 1061 1022 * @see bp_blogs_sync_delete_from_activity_comment() 1062 1023 * 1063 1024 * @param array $activity_ids The activity IDs to check association with blog … … function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $for 1094 1055 } 1095 1056 1096 1057 /** 1097 * When a blog comment status transition occurs, update the relevant activity's status.1098 *1099 * @since 1.6.01100 *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 /**1179 1058 * Get the total number of blogs being tracked by BuddyPress. 1180 1059 * 1181 1060 * @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..6f5604e 100644
class BP_Blogs_Component extends BP_Component { 342 342 $params->contexts = array( 'activity', 'member' ); 343 343 $params->position = 5; 344 344 345 if ( post_type_supports( $post_type, 'comments' ) ) { 346 $params->comment_action_id = 'new_blog_comment'; 347 348 /** 349 * Filters the post types to track for the Blogs component. 350 * 351 * @since 1.5.0 352 * @deprecated 2.5.0 353 * 354 * Make sure plugins still using 'bp_blogs_record_comment_post_types' 355 * to track comment about their post types will generate new_blog_comment activities 356 * See https://buddypress.trac.wordpress.org/ticket/6306 357 * 358 * @param array $value Array of post types to track. 359 */ 360 $comment_post_types = apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ); 361 $comment_post_types_array = array_flip( $comment_post_types ); 362 363 if ( isset( $comment_post_types_array[ $post_type ] ) ) { 364 $params->comments_tracking = new stdClass(); 365 $params->comments_tracking->component_id = $this->id; 366 $params->comments_tracking->action_id = 'new_blog_comment'; 367 $params->comments_tracking->admin_filter = __( 'New post comment posted', 'buddypress' ); 368 $params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment'; 369 $params->comments_tracking->front_filter = __( 'Comments', 'buddypress' ); 370 $params->comments_tracking->contexts = array( 'activity', 'member' ); 371 $params->comments_tracking->position = 10; 372 } 373 } 374 345 375 return $params; 346 376 } 347 377 } -
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..222384a 100644
function bp_version_updater() { 260 260 if ( $raw_db_version < 9615 ) { 261 261 bp_update_to_2_3(); 262 262 } 263 264 // 2.5.0 265 if ( $raw_db_version < 10429 ) { 266 bp_update_to_2_5(); 267 } 263 268 } 264 269 265 270 /** All done! *************************************************************/ … … function bp_update_to_2_3() { 484 489 } 485 490 486 491 /** 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 */ 498 function bp_update_to_2_5() { 499 if ( bp_is_active( 'activity' ) ) { 500 bp_activity_post_type_comment_reset_parent_meta(); 501 } 502 } 503 504 /** 487 505 * Updates the component field for new_members type. 488 506 * 489 507 * @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 ) { 84 84 85 85 /** 86 86 * @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() 88 88 */ 89 89 function bp_blogs_manage_comment( $comment_id, $comment_status ) { 90 90 _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. 9 defined( '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 */ 21 function 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 */ 38 function 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 */ 50 function 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 { 328 328 /** Versions **********************************************************/ 329 329 330 330 $this->version = '2.5.0-alpha'; 331 $this->db_version = 10 071;331 $this->db_version = 10429; 332 332 333 333 /** Loading ***********************************************************/ 334 334 … … class BuddyPress { 501 501 require( $this->plugin_dir . 'bp-core/deprecated/2.2.php' ); 502 502 require( $this->plugin_dir . 'bp-core/deprecated/2.3.php' ); 503 503 require( $this->plugin_dir . 'bp-core/deprecated/2.4.php' ); 504 require( $this->plugin_dir . 'bp-core/deprecated/2.5.php' ); 504 505 } 505 506 } 506 507 -
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 { 49 49 50 50 // Clean up after autocommits. 51 51 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(); 52 58 } 53 59 54 60 public function tearDown() { … … class BP_UnitTestCase extends WP_UnitTestCase { 97 103 parent::clean_up_global_scope(); 98 104 } 99 105 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 100 133 function assertPreConditions() { 101 134 parent::assertPreConditions(); 102 135 -
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 { 9 9 * @group activity_tracking 10 10 */ 11 11 public function test_bp_activity_catch_transition_post_type_status_publish() { 12 $bp = buddypress();13 14 12 register_post_type( 'foo', array( 15 13 'label' => 'foo', 16 14 'public' => true, … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 28 26 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 29 27 30 28 _unregister_post_type( 'foo' ); 31 32 // Reset globals33 unset( $bp->activity->actions->activity->new_foo );34 $bp->activity->track = array();35 29 } 36 30 37 31 /** … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 39 33 * @group activity_tracking 40 34 */ 41 35 public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { 42 $bp = buddypress();43 44 36 register_post_type( 'foo', array( 45 37 'label' => 'foo', 46 38 'public' => true, … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 68 60 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' ); 69 61 70 62 _unregister_post_type( 'foo' ); 71 72 // Reset globals73 unset( $bp->activity->actions->activity->new_foo );74 $bp->activity->track = array();75 63 } 76 64 77 65 /** … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 79 67 * @group activity_tracking 80 68 */ 81 69 public function test_bp_activity_catch_transition_post_type_status_publish_password() { 82 $bp = buddypress();83 84 70 register_post_type( 'foo', array( 85 71 'label' => 'foo', 86 72 'public' => true, … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 106 92 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' ); 107 93 108 94 _unregister_post_type( 'foo' ); 109 110 // Reset globals111 unset( $bp->activity->actions->activity->new_foo );112 $bp->activity->track = array();113 95 } 114 96 115 97 /** … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 117 99 * @group activity_tracking 118 100 */ 119 101 public function test_bp_activity_catch_transition_post_type_status_publish_trash() { 120 $bp = buddypress();121 122 102 register_post_type( 'foo', array( 123 103 'label' => 'foo', 124 104 'public' => true, … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 141 121 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' ); 142 122 143 123 _unregister_post_type( 'foo' ); 144 145 // Reset globals146 unset( $bp->activity->actions->activity->new_foo );147 $bp->activity->track = array();148 124 } 149 125 150 126 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..cf5d92a 100644
Bar!'; 763 763 return; 764 764 } 765 765 766 $bp = buddypress();767 768 766 register_post_type( 'foo', array( 769 767 'label' => 'foo', 770 768 'public' => true, … … Bar!'; 800 798 $this->assertSame( $expected, $a_obj->action ); 801 799 802 800 _unregister_post_type( 'foo' ); 803 804 // Reset globals805 unset( $bp->activity->actions->activity->new_foo );806 $bp->activity->track = array();807 801 } 808 802 809 803 /** … … Bar!'; 816 810 return; 817 811 } 818 812 819 $bp = buddypress();820 821 813 $b = $this->factory->blog->create(); 822 814 $u = $this->factory->user->create(); 823 815 … … Bar!'; 863 855 $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>' ); 864 856 865 857 $this->assertSame( $expected, $a_obj->action ); 866 867 // Reset globals868 unset( $bp->activity->actions->activity->new_foo );869 $bp->activity->track = array();870 858 } 871 859 872 860 /** … … Bar!'; 874 862 * @group bp_activity_get_actions 875 863 */ 876 864 public function test_bp_activity_get_actions_should_sort_by_position() { 877 $old_actions = bp_activity_get_actions();878 865 buddypress()->activity->actions = new stdClass; 879 866 880 867 register_post_type( 'foo5', array( … … Bar!'; 916 903 ); 917 904 $foo_actions = (array) $actions->foo; 918 905 $this->assertEquals( $expected, array_values( wp_list_pluck( $foo_actions, 'key' ) ) ); 919 920 buddypress()->activity->actions = $old_actions;921 906 } 922 907 923 908 /** … … Bar!'; 929 914 return; 930 915 } 931 916 932 $bp = buddypress();933 934 917 $labels = array( 935 918 'name' => 'bars', 936 919 'singular_name' => 'bar', … … Bar!'; 974 957 $this->assertSame( $expected, $a_obj->action ); 975 958 976 959 _unregister_post_type( 'foo' ); 977 978 // Reset globals979 unset( $bp->activity->actions->activity->foo_bar );980 $bp->activity->track = array();981 960 } 982 961 983 962 /** … … Bar!'; 990 969 return; 991 970 } 992 971 993 $bp = buddypress();994 $reset = $bp->activity->actions;995 996 972 $b = $this->factory->blog->create(); 997 973 $u = $this->factory->user->create(); 998 974 … … Bar!'; 1041 1017 $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>' ); 1042 1018 1043 1019 $this->assertSame( $expected, $a_obj->action ); 1044 1045 // Reset globals1046 unset( $bp->activity->actions->activity->new_foo );1047 $bp->activity->track = array();1048 1020 } 1049 1021 1050 1022 /** … … Bar!'; 1081 1053 $this->assertSame( $bp->blogs->id, $a['activities'][0]->component ); 1082 1054 1083 1055 remove_post_type_support( 'page', 'buddypress-activity' ); 1084 1085 // Reset globals1086 unset( $bp->activity->actions->blogs->new_page );1087 $bp->activity->track = array();1088 1056 } 1089 1057 1090 1058 /** … … Bar!'; 1126 1094 } 1127 1095 1128 1096 /** 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 /** 1129 1172 * @group bp_activity_new_comment 1130 1173 * @group cache 1131 1174 */ … … Bar!'; 1432 1475 $this->assertSame( array(), $found['activities'] ); 1433 1476 } 1434 1477 1478 /** 1479 * @group bp_activity_post_type_comment_reset_parent_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_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_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 1435 1540 public function check_activity_caches() { 1436 1541 foreach ( $this->acaches as $k => $v ) { 1437 1542 $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 fc58a21..b940640 100644
class BP_Tests_Activity_Template extends BP_UnitTestCase { 826 826 /** 827 827 * @group filter_query 828 828 * @group BP_Activity_Query 829 * @group post_type_comment_activities 829 830 */ 830 831 function test_bp_has_activities_with_filter_query_compare_regex() { 831 832 $u1 = $this->factory->user->create(); … … class BP_Tests_Activity_Template extends BP_UnitTestCase { 1216 1217 1217 1218 /** 1218 1219 * @group bp_has_activities 1220 * @group post_type_comment_activities 1219 1221 */ 1220 1222 public function test_bp_has_activities_with_type_new_blog_comments() { 1221 1223 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 { 156 156 /** 157 157 * @group activity_action 158 158 * @group bp_blogs_format_activity_action_new_blog_comment 159 * @group post_type_comment_activities 159 160 */ 160 161 public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() { 161 162 if ( ! is_multisite() ) { … … class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 318 319 return; 319 320 } 320 321 321 $bp = buddypress(); 322 $activity_actions = $bp->activity->actions; 323 $bp->activity->actions = new stdClass(); 322 buddypress()->activity->actions = new stdClass(); 324 323 325 324 $u = $this->factory->user->create(); 326 325 $p = wp_insert_post( array( … … class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 346 345 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link ); 347 346 348 347 $this->assertSame( $expected, $a_obj['activities'][0]->action ); 349 350 // Reset activity actions351 $bp->activity->actions = $activity_actions;352 $bp->activity->track = array();353 348 } 354 349 355 350 /** … … class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 361 356 return; 362 357 } 363 358 364 $bp = buddypress(); 365 $activity_actions = $bp->activity->actions; 366 $bp->activity->actions = new stdClass(); 359 buddypress()->activity->actions = new stdClass(); 367 360 368 361 $u = $this->factory->user->create(); 369 362 $p = wp_insert_post( array( … … class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 407 400 ) ); 408 401 409 402 $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' ); 410 672 411 // Reset activity actions 412 $bp->activity->actions = $activity_actions; 413 $bp->activity->track = array(); 673 $this->set_current_user( $old_user ); 414 674 } 415 675 416 676 /** -
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 { 10 10 public function setUp() { 11 11 parent::setUp(); 12 12 13 $bp = buddypress();14 15 $this->activity_actions = $bp->activity->actions;16 $bp->activity->actions = new stdClass();17 18 13 $this->custom_post_types = array( 'using_old_filter' ); 19 14 20 15 register_post_type( 'using_old_filter', array( … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 35 30 _unregister_post_type( 'using_old_filter' ); 36 31 remove_filter( 'bp_blogs_record_post_post_types', array( $this, 'filter_post_types'), 10, 1 ); 37 32 remove_filter( 'bp_blogs_record_comment_post_types', array( $this, 'filter_post_types'), 10, 1 ); 38 39 // Reset activity actions40 $bp->activity->actions = $this->activity_actions;41 $bp->activity->track = array();42 33 } 43 34 44 35 /** … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 64 55 65 56 /** 66 57 * @goup bp_blogs_record_comment 58 * @group post_type_comment_activities 67 59 */ 68 60 public function test_bp_blogs_record_comment() { 69 61 $u = $this->factory->user->create(); … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 89 81 90 82 /** 91 83 * @goup bp_blogs_record_comment_sync_activity_comment 84 * @group post_type_comment_activities 92 85 */ 93 86 public function test_bp_blogs_record_comment_sync_activity_comment() { 94 87 $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 { 513 513 514 514 /** 515 515 * @group bp_blogs_catch_transition_post_status 516 * @group post_type_comment_activities 516 517 */ 517 518 public function test_update_blog_post_and_new_blog_comment_and_activity_comment_meta() { 518 519 // save the current user and override logged-in user … … class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 596 597 597 598 /** 598 599 * @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 600 602 */ 601 603 public function test_bp_blogs_remove_comment_should_remove_spammed_activity_comment() { 602 604 // save the current user and override logged-in user … … class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 658 660 } 659 661 660 662 /** 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 /** 661 705 * @group bp_blogs_catch_transition_post_status 662 706 */ 663 707 public function test_bp_blogs_is_blog_trackable_false_publish_post() { … … class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 714 758 /** 715 759 * @group bp_blogs_record_comment 716 760 * @group unique 761 * @group post_type_comment_activities 717 762 */ 718 763 public function test_bp_blogs_record_comment_no_duplicate_activity_comments() { 719 764 // save the current user and override logged-in user … … class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 777 822 778 823 /** 779 824 * @group bp_blogs_record_comment 825 * @group post_type_comment_activities 780 826 */ 781 827 public function test_bp_blogs_record_comment_should_record_parent_blog_post_activity_if_not_found() { 782 828 // Save the current user and override logged-in user … … class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 826 872 ), 827 873 ) ); 828 874 875 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 876 829 877 // Assert that activity item for blog post was created after adding a comment 830 878 $this->assertNotNull( $a1, 'Activity item was not created for existing blog post when recording post comment.' ); 831 879 832 880 $this->set_current_user( $old_user ); 833 881 } 834 882 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 835 979 public function count_activity_comment_saved() { 836 980 $this->activity_saved_comment_count += 1; 837 981 }