Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/04/2016 05:25:57 PM (8 years ago)
Author:
r-a-y
Message:

Blogs: Move activity-related code from bp-blogs-functions.php to bp-blogs-activity.php.

Instead of hardcoding activity code and needing to check for the Activity
component in bp-blogs-functions.php, this commit moves this activity code
code to bp-blogs-activity.php and also hooks this code to appropriate
blog actions.

This allows developers to easily remove said activity hook if needed.

Fixes #6937.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r10730 r10731  
    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.
     
    819807
    820808    /**
     809     * Fires after a "blog created" item has been removed from blogs
     810     * tracker and activity stream.
     811     *
     812     * @since 1.0.0
     813     *
     814     * @param int $blog_id ID of the blog who had its item removed.
     815     */
     816    do_action( 'bp_blogs_remove_blog', $blog_id );
     817}
     818add_action( 'delete_blog', 'bp_blogs_remove_blog' );
     819
     820/**
     821 * Remove a blog from the tracker for a specific user.
     822 *
     823 * @param int $user_id ID of the user for whom the blog is being removed.
     824 * @param int $blog_id ID of the blog being removed.
     825 */
     826function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
     827
     828    $blog_id = (int) $blog_id;
     829    $user_id = (int) $user_id;
     830
     831    /**
     832     * Fires before a blog is removed from the tracker for a specific user.
     833     *
     834     * @since 1.5.0
     835     *
     836     * @param int $blog_id ID of the blog being removed.
     837     * @param int $user_id ID of the user having the blog removed for.
     838     */
     839    do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
     840
     841    BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
     842
     843    /**
    821844     * Delete activity stream item only if the Activity component is active
    822845     *
     
    832855
    833856    /**
    834      * Fires after a "blog created" item has been removed from blogs
    835      * tracker and activity stream.
    836      *
    837      * @since 1.0.0
    838      *
    839      * @param int $blog_id ID of the blog who had its item removed.
    840      */
    841     do_action( 'bp_blogs_remove_blog', $blog_id );
    842 }
    843 add_action( 'delete_blog', 'bp_blogs_remove_blog' );
    844 
    845 /**
    846  * Remove a blog from the tracker for a specific user.
    847  *
    848  * @param int $user_id ID of the user for whom the blog is being removed.
    849  * @param int $blog_id ID of the blog being removed.
    850  */
    851 function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
    852 
    853     $blog_id = (int) $blog_id;
    854     $user_id = (int) $user_id;
    855 
    856     /**
    857      * Fires before a blog is removed from the tracker for a specific user.
    858      *
    859      * @since 1.5.0
    860      *
    861      * @param int $blog_id ID of the blog being removed.
    862      * @param int $user_id ID of the user having the blog removed for.
    863      */
    864     do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
    865 
    866     BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
    867 
    868     /**
    869      * Delete activity stream item only if the Activity component is active
    870      *
    871      * @see https://buddypress.trac.wordpress.org/ticket/6937
    872      */
    873     if ( bp_is_active( 'activity' ) ) {
    874         bp_blogs_delete_activity( array(
    875             'item_id'   => $blog_id,
    876             'component' => buddypress()->blogs->id,
    877             'type'      => 'new_blog'
    878         ) );
    879     }
    880 
    881     /**
    882857     * Fires after a blog has been removed from the tracker for a specific user.
    883858     *
     
    890865}
    891866add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
    892 
    893 /**
    894  * Remove a blog post activity item from the activity stream.
    895  *
    896  * @param int $post_id ID of the post to be removed.
    897  * @param int $blog_id Optional. Defaults to current blog ID.
    898  * @param int $user_id Optional. Defaults to the logged-in user ID. This param
    899  *                     is currently unused in the function (but is passed to hooks).
    900  * @return bool
    901  */
    902 function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
    903     global $wpdb;
    904 
    905     if ( empty( $wpdb->blogid ) )
    906         return false;
    907 
    908     $post_id = (int) $post_id;
    909 
    910     if ( !$blog_id )
    911         $blog_id = (int) $wpdb->blogid;
    912 
    913     if ( !$user_id )
    914         $user_id = bp_loggedin_user_id();
    915 
    916     /**
    917      * Fires before removal of a blog post activity item from the activity stream.
    918      *
    919      * @since 1.5.0
    920      *
    921      * @param int $blog_id ID of the blog associated with the post that was removed.
    922      * @param int $post_id ID of the post that was removed.
    923      * @param int $user_id ID of the user having the blog removed for.
    924      */
    925     do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
    926 
    927     /**
    928      * Delete activity stream item only if the Activity component is active
    929      *
    930      * @see https://buddypress.trac.wordpress.org/ticket/6937
    931      */
    932     if ( bp_is_active( 'activity' ) ) {
    933         bp_blogs_delete_activity( array(
    934             'item_id'           => $blog_id,
    935             'secondary_item_id' => $post_id,
    936             'component'         => buddypress()->blogs->id,
    937             'type'              => 'new_blog_post'
    938         ) );
    939     }
    940 
    941     /**
    942      * Fires after removal of a blog post activity item from the activity stream.
    943      *
    944      * @since 1.0.0
    945      *
    946      * @param int $blog_id ID of the blog associated with the post that was removed.
    947      * @param int $post_id ID of the post that was removed.
    948      * @param int $user_id ID of the user having the blog removed for.
    949      */
    950     do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $user_id );
    951 }
    952 add_action( 'delete_post', 'bp_blogs_remove_post' );
    953867
    954868/**
     
    11301044
    11311045    /**
    1132      * Delete activity stream item only if the Activity component is active
    1133      *
    1134      * @see https://buddypress.trac.wordpress.org/ticket/6937
    1135      */
    1136     if ( bp_is_active( 'activity' ) ) {
    1137         bp_blogs_delete_activity( array(
    1138             'item_id'   => $blog_id,
    1139             'component' => buddypress()->blogs->id,
    1140             'type'      => false
    1141         ) );
    1142     }
    1143 
    1144     /**
    11451046     * Fires after all data related to a given blog has been removed from blogs tracker
    11461047     * and activity stream.
Note: See TracChangeset for help on using the changeset viewer.