Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/04/2016 05:25:57 PM (9 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-activity.php

    r10544 r10731  
    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
Note: See TracChangeset for help on using the changeset viewer.