Ticket #6937: 6937.activity.patch
File 6937.activity.patch, 9.0 KB (added by , 8 years ago) |
---|
-
src/bp-blogs/bp-blogs-activity.php
606 606 return $open; 607 607 } 608 608 609 /** SITE TRACKING *******************************************************/ 610 611 /** 612 * Add an activity entry for a newly-created site. 613 * 614 * Hooked to the 'bp_blogs_new_blog' action. 615 * 616 * @since 2.6.0 617 * 618 * @param BP_Blogs_Blog $recorded_blog Current site being recorded. Passed by reference. 619 * @param bool $is_private Whether the current site being recorded is private. 620 * @param bool $is_recorded Whether the current site was recorded. 621 */ 622 function bp_blogs_record_activity_on_site_creation( $recorded_blog, $is_private, $is_recorded, $no_activity ) { 623 // Only record this activity if the blog is public. 624 if ( ! $is_private && ! $no_activity && bp_blogs_is_blog_trackable( $recorded_blog->blog_id, $recorded_blog->user_id ) ) { 625 bp_blogs_record_activity( array( 626 'user_id' => $recorded_blog->user_id, 627 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', bp_blogs_get_blogmeta( $recorded_blog->blog_id, 'url' ), $recorded_blog->blog_id ), 628 'type' => 'new_blog', 629 'item_id' => $recorded_blog->blog_id 630 ) ); 631 } 632 } 633 add_action( 'bp_blogs_new_blog', 'bp_blogs_record_activity_on_site_creation', 10, 4 ); 634 635 /** 636 * Deletes the 'new_blog' activity entry when a site is deleted. 637 * 638 * @since 2.6.0 639 * 640 * @param int $blog_id Site ID. 641 */ 642 function bp_blogs_delete_new_blog_activity_for_site( $blog_id ) { 643 bp_blogs_delete_activity( array( 644 'item_id' => $blog_id, 645 'component' => buddypress()->blogs->id, 646 'type' => 'new_blog' 647 ) ); 648 } 649 add_action( 'bp_blogs_remove_blog', 'bp_blogs_delete_new_blog_activity_for_site' ); 650 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_delete_new_blog_activity_for_site' ); 651 652 /** 653 * Delete all 'blogs' activity items for a site when the site is deleted. 654 * 655 * @since 2.6.0 656 * 657 * @param int $blog_id Site ID. 658 */ 659 function bp_blogs_delete_activity_for_site( $blog_id ) { 660 bp_blogs_delete_activity( array( 661 'item_id' => $blog_id, 662 'component' => buddypress()->blogs->id, 663 'type' => false 664 ) ); 665 } 666 add_action( 'bp_blogs_remove_data_for_blog', 'bp_blogs_delete_activity_for_site' ); 667 668 /** 669 * Remove a blog post activity item from the activity stream. 670 * 671 * @since 1.0.0 672 * 673 * @param int $post_id ID of the post to be removed. 674 * @param int $blog_id Optional. Defaults to current blog ID. 675 * @param int $user_id Optional. Defaults to the logged-in user ID. This param 676 * is currently unused in the function (but is passed to hooks). 677 * @return bool 678 */ 679 function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) { 680 global $wpdb; 681 682 if ( empty( $wpdb->blogid ) ) { 683 return false; 684 } 685 686 $post_id = (int) $post_id; 687 688 if ( ! $blog_id ) { 689 $blog_id = (int) $wpdb->blogid; 690 } 691 692 if ( ! $user_id ) { 693 $user_id = bp_loggedin_user_id(); 694 } 695 696 /** 697 * Fires before removal of a blog post activity item from the activity stream. 698 * 699 * @since 1.5.0 700 * 701 * @param int $blog_id ID of the blog associated with the post that was removed. 702 * @param int $post_id ID of the post that was removed. 703 * @param int $user_id ID of the user having the blog removed for. 704 */ 705 do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id ); 706 707 bp_blogs_delete_activity( array( 708 'item_id' => $blog_id, 709 'secondary_item_id' => $post_id, 710 'component' => buddypress()->blogs->id, 711 'type' => 'new_blog_post' 712 ) ); 713 714 /** 715 * Fires after removal of a blog post activity item from the activity stream. 716 * 717 * @since 1.0.0 718 * 719 * @param int $blog_id ID of the blog associated with the post that was removed. 720 * @param int $post_id ID of the post that was removed. 721 * @param int $user_id ID of the user having the blog removed for. 722 */ 723 do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $user_id ); 724 } 725 add_action( 'delete_post', 'bp_blogs_remove_post' ); 726 609 727 /** POST COMMENT SYNCHRONIZATION ****************************************/ 610 728 611 729 /** -
src/bp-blogs/bp-blogs-functions.php
279 279 $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true; 280 280 $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private ); 281 281 282 // Only record this activity if the activity component is active and the blog is public.283 if ( bp_is_active( 'activity' ) && !$is_private && !$no_activity && bp_blogs_is_blog_trackable( $blog_id, $user_id ) ) {284 285 // Record this in activity streams.286 bp_blogs_record_activity( array(287 'user_id' => $recorded_blog->user_id,288 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', $url, $recorded_blog->blog_id ),289 'type' => 'new_blog',290 'item_id' => $recorded_blog->blog_id291 ) );292 }293 294 282 /** 295 283 * Fires after BuddyPress has been made aware of a new site for activity tracking. 296 284 * 297 285 * @since 1.0.0 286 * @since 2.6.0 Added $no_activity as a parameter. 298 287 * 299 288 * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference. 300 289 * @param bool $is_private Whether or not the current blog being recorded is private. 301 290 * @param bool $is_recorded Whether or not the current blog was recorded. 291 * @param bool $no_activity Whether to skip recording an activity item for this blog creation. 302 292 */ 303 do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded ) );293 do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded, $no_activity ) ); 304 294 } 305 295 add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 ); 306 296 … … 816 806 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 817 807 818 808 /** 819 * Delete activity stream item only if the Activity component is active820 *821 * @see https://buddypress.trac.wordpress.org/ticket/6937822 */823 if ( bp_is_active( 'activity' ) ) {824 bp_blogs_delete_activity( array(825 'item_id' => $blog_id,826 'component' => buddypress()->blogs->id,827 'type' => 'new_blog'828 ) );829 }830 831 /**832 809 * Fires after a "blog created" item has been removed from blogs 833 810 * tracker and activity stream. 834 811 * … … 889 866 add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 ); 890 867 891 868 /** 892 * Remove a blog post activity item from the activity stream.893 *894 * @param int $post_id ID of the post to be removed.895 * @param int $blog_id Optional. Defaults to current blog ID.896 * @param int $user_id Optional. Defaults to the logged-in user ID. This param897 * is currently unused in the function (but is passed to hooks).898 * @return bool899 */900 function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {901 global $wpdb;902 903 if ( empty( $wpdb->blogid ) )904 return false;905 906 $post_id = (int) $post_id;907 908 if ( !$blog_id )909 $blog_id = (int) $wpdb->blogid;910 911 if ( !$user_id )912 $user_id = bp_loggedin_user_id();913 914 /**915 * Fires before removal of a blog post activity item from the activity stream.916 *917 * @since 1.5.0918 *919 * @param int $blog_id ID of the blog associated with the post that was removed.920 * @param int $post_id ID of the post that was removed.921 * @param int $user_id ID of the user having the blog removed for.922 */923 do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );924 925 /**926 * Delete activity stream item only if the Activity component is active927 *928 * @see https://buddypress.trac.wordpress.org/ticket/6937929 */930 if ( bp_is_active( 'activity' ) ) {931 bp_blogs_delete_activity( array(932 'item_id' => $blog_id,933 'secondary_item_id' => $post_id,934 'component' => buddypress()->blogs->id,935 'type' => 'new_blog_post'936 ) );937 }938 939 /**940 * Fires after removal of a blog post activity item from the activity stream.941 *942 * @since 1.0.0943 *944 * @param int $blog_id ID of the blog associated with the post that was removed.945 * @param int $post_id ID of the post that was removed.946 * @param int $user_id ID of the user having the blog removed for.947 */948 do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $user_id );949 }950 add_action( 'delete_post', 'bp_blogs_remove_post' );951 952 /**953 869 * Remove a synced activity comment from the activity stream. 954 870 * 955 871 * @since 2.5.0 … … 1127 1043 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 1128 1044 1129 1045 /** 1130 * Delete activity stream item only if the Activity component is active1131 *1132 * @see https://buddypress.trac.wordpress.org/ticket/69371133 */1134 if ( bp_is_active( 'activity' ) ) {1135 bp_blogs_delete_activity( array(1136 'item_id' => $blog_id,1137 'component' => buddypress()->blogs->id,1138 'type' => false1139 ) );1140 }1141 1142 /**1143 1046 * Fires after all data related to a given blog has been removed from blogs tracker 1144 1047 * and activity stream. 1145 1048 *