Skip to:
Content

BuddyPress.org

Ticket #6937: 6937.activity.patch

File 6937.activity.patch, 9.0 KB (added by r-a-y, 6 years ago)
  • src/bp-blogs/bp-blogs-activity.php

     
    606606        return $open;
    607607}
    608608
     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 */
     622function 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}
     633add_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 */
     642function 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}
     649add_action( 'bp_blogs_remove_blog',          'bp_blogs_delete_new_blog_activity_for_site' );
     650add_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 */
     659function 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}
     666add_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 */
     679function 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}
     725add_action( 'delete_post', 'bp_blogs_remove_post' );
     726
    609727/** POST COMMENT SYNCHRONIZATION ****************************************/
    610728
    611729/**
  • src/bp-blogs/bp-blogs-functions.php

     
    279279        $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true;
    280280        $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private );
    281281
    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_id
    291                 ) );
    292         }
    293 
    294282        /**
    295283         * Fires after BuddyPress has been made aware of a new site for activity tracking.
    296284         *
    297285         * @since 1.0.0
     286         * @since 2.6.0 Added $no_activity as a parameter.
    298287         *
    299288         * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference.
    300289         * @param bool          $is_private    Whether or not the current blog being recorded is private.
    301290         * @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.
    302292         */
    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 ) );
    304294}
    305295add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
    306296
     
    816806        BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    817807
    818808        /**
    819          * Delete activity stream item only if the Activity component is active
    820          *
    821          * @see https://buddypress.trac.wordpress.org/ticket/6937
    822          */
    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         /**
    832809         * Fires after a "blog created" item has been removed from blogs
    833810         * tracker and activity stream.
    834811         *
     
    889866add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    890867
    891868/**
    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 param
    897  *                     is currently unused in the function (but is passed to hooks).
    898  * @return bool
    899  */
    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.0
    918          *
    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 active
    927          *
    928          * @see https://buddypress.trac.wordpress.org/ticket/6937
    929          */
    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.0
    943          *
    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 /**
    953869 * Remove a synced activity comment from the activity stream.
    954870 *
    955871 * @since 2.5.0
     
    11271043        BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    11281044
    11291045        /**
    1130          * Delete activity stream item only if the Activity component is active
    1131          *
    1132          * @see https://buddypress.trac.wordpress.org/ticket/6937
    1133          */
    1134         if ( bp_is_active( 'activity' ) ) {
    1135                 bp_blogs_delete_activity( array(
    1136                         'item_id'   => $blog_id,
    1137                         'component' => buddypress()->blogs->id,
    1138                         'type'      => false
    1139                 ) );
    1140         }
    1141 
    1142         /**
    11431046         * Fires after all data related to a given blog has been removed from blogs tracker
    11441047         * and activity stream.
    11451048         *